Skip to content

Latest commit

 

History

History
87 lines (67 loc) · 4.37 KB

environments.md

File metadata and controls

87 lines (67 loc) · 4.37 KB

Environments

The suite runs against one environment per run. The environment is chosen with TEST_ENV. Each environment has a settings file in config/environments/.

Environment TEST_ENV Settings file Read-only
Development dev (default) config/environments/dev.json no
QA qa config/environments/qa.json no
Staging staging config/environments/staging.json no
Production production config/environments/production.json yes

Current state: all four files point at the OrangeHRM demo as placeholders. Replace each baseUrl with the real URL when it is available.

Settings file

{
  "name": "qa",
  "description": "QA environment. Placeholder: points at the OrangeHRM demo until a real QA URL is provided.",
  "baseUrl": "https://opensource-demo.orangehrmlive.com",
  "readOnly": false
}
Key Type Meaning
name string must match the file name and an entry in SUPPORTED_ENVIRONMENTS
description string shown to humans only
baseUrl string (absolute URL) the base for every page.goto and env.url(...) call
readOnly boolean true limits the run to @prod tests and makes the guard enforce it

Settings files hold no secrets. Credentials come from environment variables.

Precedence

  1. BASE_URL (environment variable) overrides baseUrl in the settings file.
  2. TEST_ENV selects the file. Unset means dev.
  3. An unknown TEST_ENV fails before any test starts, with the list of valid names.
TEST_ENV=qa bun run test:smoke
TEST_ENV=staging BASE_URL=https://staging.example.test bun run test:integration

Production safety

Production is protected in three layers. Each one works without the others.

flowchart TD
    START["TEST_ENV=production"] --> CFG{"readOnly is true?"}
    CFG -- "yes" --> GREP["playwright.config.js: grep /@prod/"]
    GREP --> SEL["Only @prod tests are selected"]
    SEL --> GUARD{"Fixture guard: test tagged @prod or setup project?"}
    GUARD -- "yes" --> RUN["Test runs"]
    GUARD -- "no" --> FAIL["Test fails before it starts, with a clear message"]
    CHG["Config filter removed or changed"] --> GUARD
Loading

Text alternative: in production, the config selects only @prod tests. The fixture guard checks every test that starts, and fails any test that is not tagged @prod and is not in the setup project. The guard is a backup for the config filter: it applies if that filter is removed or changed.

  1. Config filter: playwright.config.js sets grep: /@prod/ when readOnly is true. A --grep on the command line is combined with this filter, so it can only narrow the selection. It cannot select a non-@prod test.
  2. Fixture guard: src/fixtures/index.js runs for every test. It refuses any test in a read-only environment unless the test is tagged @prod (or belongs to the setup project). It is a backup for the config filter.
  3. Test rules: @prod tests must be read-only. See tagging.

Adding an environment

  1. Create config/environments/<name>.json with the four keys above.
  2. Add the name to SUPPORTED_ENVIRONMENTS in src/config/environment.js.
  3. Optionally add a script to package.json, for example "test:<name>": "cross-env TEST_ENV=<name> playwright test".
  4. Add a GitHub Environment and its secrets, then reference it from a workflow. See CI/CD.
  5. Update the environment table in this file and in the project README.

Secrets

Where Used for
.env on your machine (git-ignored) local runs
GitHub Environment secrets CI runs (E2E_USERNAME, E2E_PASSWORD)

Never put a password in a settings file, a test, or the .env.example template.