test-standards
Skill222 starsChanged 4 months agoMITView on GitHub
Spec file conventions for the Playwright scaffold — imports from test-options.ts, test file structure (describe / beforeEach / test / test.step), single-tag rule, functional vs E2E vs API vs setup test types, data-driven test loops against TS static data, web-first assertions, destructive-test cleanup, and test independence. Use when creating a new spec file, adding tests to an existing spec, deciding which test type or tag to use, writing data-driven loops, wiring destructive cleanup, or reviewing a test for compliance. For the deep API test-coverage matrix and negative-testing patterns see the api-testing skill; for factories and static data see the data-strategy skill; for prompt templates see the common-tasks skill; for page object usage from tests see the fixtures and page-objects skills.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- BackToCimaCoppi/Praxistheir own version, first seen Sep 23, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- BackToCimaCoppi/Praxis★ 6same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository37 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/rules.mdcCursor rule
- ai-native-workflowSkill
- api-testingSkill
- common-tasksSkill
- configSkill
- data-strategySkill
- debuggingSkill
- enumsSkill
- fixturesSkill
- helpersSkill
- page-objectsSkill
- playwright-cliSkill
- pr-reviewerSkill
- refactor-valuesSkill
- selectorsSkill
- skill-creatorSkill
- test-standardsSkill
- type-safetySkill
- ai-native-workflowSkill
- api-testingSkill
- common-tasksSkill
- configSkill
- data-strategySkill
- debuggingSkill
- enumsSkill
- fixturesSkill
- helpersSkill
- page-objectsSkill
- playwright-cliSkill
- pr-reviewerSkill
- refactor-valuesSkill
- selectorsSkill
- skill-creatorSkill
- type-safetySkill
- skill-creatorSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 4 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 11
Imports: Import test and expect from fixtures/pom/test-options.ts.
- Very specific: line 14
Every state-mutating test: must have test.afterEach() or test.afterAll() cleanup that reverts the change — both @destructive shared-state …
- Very specific: line 16
Use
test.step()for Given/When/Then structure: when a test has more than one distinct phase (setup, action, assertion). - Distinctive: line 17
Tests must be independent: No ordering dependencies, no shared mutable state across tests.
- Very specific: line 18
NEVER: commit explore-only or debug test files (.spec.ts containing console.log(await page.content()), temporary probes, etc.).
- Distinctive: line 48
Every spec file starts with:
- Very specific: line 128
Use test.step() to split the test into Given / When / Then blocks.
- Very specific: line 170
If a response must be awaited, use page.waitForResponse(...) inside a page-object action method, not inside the spec.
- Very specific: line 174
Use test.beforeEach() for per-test navigation and setup.
- Very specific: line 175
Use test.afterEach() for per-test cleanup when fixtures don't handle it.
- Very specific: line 176
Use the resetStorageState fixture when testing login/logout flows so each test starts unauthenticated:
- Distinctive: line 255
After adding or modifying a test file:
- Distinctive: line 268
Do not finish until the added/modified tests pass consistently.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Test Standards
Critical
- Imports: Import
testandexpectfromfixtures/pom/test-options.ts. NEVER from@playwright/testin spec files. - Single-tag rule: Each test has exactly one tag chosen from
@smoke|@sanity|@regression|@e2e|@api|@destructive. NEVER combine tags. NEVER use@functional. NEVER put tags ontest.describe()blocks. @destructiveis the heaviest tag and always wins — but only for shared/global state. A test that mutates state other tests or users depend on (locale, permissions, roles, guest access, feature flags, global settings) is tagged only@destructive. A test that creates and deletes only its own data is isolated, not destructive — tag it by importance (@smoke/@sanity/@regression/@e2e/@api).- Every state-mutating test must have
test.afterEach()ortest.afterAll()cleanup that reverts the change — both@destructiveshared-state tests and isolated tests that write their own data. - Web-first assertions only (
await expect(locator).toBeVisible(),.toHaveText(),.toBeEnabled(),.toHaveCount(...), etc.). NEVERpage.waitForTimeout(...). - Use
test.step()for Given/When/Then structure when a test has more than one distinct phase (setup, action, assertion). - Tests must be independent. No ordering dependencies, no shared mutable state across tests.
- NEVER commit explore-only or debug test files (
.spec.tscontainingconsole.log(await page.content()), temporary probes, etc.). - Static test data is imported from
.tsmodules (test-data/static/**/*.ts) via namedas constexports. NEVER.json. - Dynamic happy-path data comes from Faker factories (
test-data/factories/{area}/); universal type-mismatch arrays fromtest-data/static/util/invalid-values.ts; domain-specific curated sets fromtest-data/static/{area}/*.ts. See thedata-strategyskill. - Page objects are consumed via the fixture (
async ({ appPage }) => ...). NEVERnew PageObject(page)inside a test. - After adding or modifying a test file, run the affected tests and confirm zero failures before finishing the task.
Test File Location and Type
{area}is a placeholder. Before creating or referencing any path below, runls tests/to discover the real subdirectory names in this repo (e.g.,front-office,back-office) and use those instead.
| Test Type | Directory | What it covers |
| Functional | tests/{area}/functional/ | One feature or behaviour in isolation |
| API | tests/{area}/api/ | API contracts and response validation |
| E2E | tests/{area}/e2e/ | A complete multi-feature user journey in a single test |
| Setup | tests/{area}/ | Auth or precondition setup (.setup.ts) |
Functional vs E2E distinction:
- A functional test isolates and verifies a single behaviour (e.g., "adding a todo updates the count"). Each test covers one thing.
- An E2E test chains multiple features together in one test that mirrors a real user journey from start to finish (e.g., add items → complete → filter → clear → verify final state). An E2E file typically contains one or a few high-level scenario tests.
Instructions
Phase 1: Classify the test type and pick the location
Determine whether the work is a functional, E2E, API, or setup test, then run ls tests/ to resolve {area} and place the file in tests/{area}/<type>/[name].spec.ts (or tests/{area}/[name].setup.ts for setup). Never guess the area.
Phase 2: Write the imports and file skeleton
Every spec file starts with:
import { expect, test } from '../../../fixtures/pom/test-options';
test.describe('Feature Name', () => {
test.beforeEach(async ({ appPage }) => {
await appPage.openHomePage();
});
test(
'should do expected behavior',
{ tag: '@smoke' },
async ({ appPage }) => {
// ...
}
);
});- Imports come from
fixtures/pom/test-options.ts, not@playwright/test. test.describe(...)groups related tests; the describe name has no tag.test.beforeEach(...)handles navigation and per-test setup (see Phase 7 for destructive cleanup and Phase 6 forresetStorageState).
Phase 3: Tag the test (single-tag rule)
Each test gets exactly one tag. Pick the right one:
| Tag | Used for |
@smoke | Critical path functional tests, run first and frequently |
@sanity | Key functionality verification |
@regression | Full regression coverage of a single behaviour |
@e2e | End-to-end multi-feature user journey tests |
@api | API contract and schema validation tests |
@destructive | Mutates shared/global state (locale, permissions, roles, guest access, feature flags, global settings) — excluded from npm test, run via npm run test:destructive |
@destructive overrides any other importance tag — for shared/global state mutation only. If a test would otherwise be @smoke but changes global settings, it is tagged only @destructive. A test that creates and cleans up only its own data is isolated, not destructive — keep its importance tag (@smoke/@regression/@api/…).
// CORRECT
test('should login successfully', { tag: '@smoke' }, async ({ appPage }) => {
/* ... */
});
test('should validate cart flow', { tag: '@e2e' }, async ({ checkoutPage }) => {
/* ... */
});
test('should return user profile', { tag: '@api' }, async ({ apiRequest }) => {
/* ... */
});
test(
'should delete all users',
{ tag: '@destructive' },
async ({ apiRequest }) => {
/* ... */
}
);
// WRONG -- @functional is not a valid tag
test('should login', { tag: '@functional' }, async ({ appPage }) => {
/* ... */
});
// WRONG -- combining tags is forbidden
test(
'should delete all users',
{ tag: ['@regression', '@destructive'] },
async () => {
/* ... */
}
);
// WRONG -- tag belongs on the test, not the describe
test.describe('Feature @smoke', () => {
/* ... */
});Phase 4: Structure the test body with test.step
Use test.step() to split the test into Given / When / Then blocks. This produces readable HTML reports and makes debugging faster.
test(
'should show error for invalid login',
{ tag: '@regression' },
async ({ appPage }) => {
await test.step('GIVEN user is on the login page', async () => {
await expect(appPage.loginButton).toBeVisible();
});
await test.step('WHEN user enters invalid credentials', async () => {
// generateLoginCredentials() is illustrative -- build the factory
// via the data-strategy skill or use process.env.* + a known-bad password.
const { email, password } = generateLoginCredentials();
await appPage.login(email, password);
});
await test.step('THEN error message is displayed', async () => {
await expect(appPage.errorMessage).toBeVisible();
});
}
);For API tests with multiple calls, test.step is mandatory — see the api-testing skill (Phase 4).
Phase 5: Use web-first assertions
Web-first assertions auto-wait and retry until the condition is met or a timeout elapses. Never use hard waits.
// CORRECT -- web-first assertions
await expect(locator).toBeVisible();
await expect(locator).toHaveText('Expected text');
await expect(locator).toBeEnabled();
await expect(locator).toHaveCount(3);
// FORBIDDEN -- hard waits mask real timing issues
await page.waitForTimeout(1000);If a response must be awaited, use page.waitForResponse(...) inside a page-object action method, not inside the spec.
Phase 6: Handle setup / teardown and storage state
- Use
test.beforeEach()for per-test navigation and setup. - Use
test.afterEach()for per-test cleanup when fixtures don't handle it. - Use the
resetStorageStatefixture when testing login/logout flows so each test starts unauthenticated:
test.beforeEach(async ({ resetStorageState, appPage }) => {
await resetStorageState();
await appPage.openHomePage();
});For API-driven setup/teardown reused across many files, see the api-testing skill (Phase 8, helper-fixture rule of thumb).
Phase 7: Handle destructive tests
@destructive is reserved for shared/global state. A test is destructive only when it mutates state that lives outside the test and that other tests, users, or sessions depend on. Concretely:
- changing the locale / language / region
- granting or removing permissions, roles, or guest access
- toggling feature flags or global settings / configuration
- mutating shared seed data every test reads (e.g. "delete all users", resetting a global catalog)
Counter-example — NOT destructive. A test that creates its own record, asserts on it, then deletes only that record in cleanup is isolated, not destructive. It touches no state another test depends on. Tag it by importance (@smoke / @regression / @api / …) — never @destructive. It still needs a cleanup hook (see below), but it runs in the parallel suite.
Cleanup hook is required for any state-mutating test. Both @destructive shared-state tests and isolated own-data tests MUST use test.afterEach() or test.afterAll() to revert what they wrote:
test.describe('admin data management', () => {
test.afterEach(async ({ apiRequest }) => {
// REQUIRED: Revert state changes made by the test.
// ApiEndpoints.RESET_DATA is illustrative -- use whatever reset
// endpoint your app provides, defined in enums/{area}/*.ts.
await apiRequest({
method: 'POST',
url: ApiEndpoints.RESET_DATA,
baseUrl: process.env.API_URL,
headers: process.env.ACCESS_TOKEN,
});
});
test(
'should delete all inactive users',
{ tag: '@destructive' },
async ({ apiRequest }) => {
// Test that modifies shared state
}
);
});Execution rules:
- Excluded from
npm test— the base command uses--grep-invert @destructiveto keep destructive tests out of the parallel suite. - Tag-specific commands (
test:smoke,test:regression,test:api, etc.) use--grepto match their own tag. Because each test has exactly one tag, a@destructivetest only runs undernpm run test:destructive— not undertest:smoke,test:regression, etc. - Dedicated command —
npm run test:destructiveruns only destructive tests with--workers=1for sequential execution.
Phase 8: Data-driven tests
Loop outside test blocks to generate individual test cases. Static data is imported from .ts modules via named as const exports.
import { INVALID_LOGIN_ATTEMPTS } from '../../../test-data/static/app/invalidCredentials';
for (const { description, email, password } of INVALID_LOGIN_ATTEMPTS) {
test(
`should show error for ${description}`,
{ tag: '@regression' },
async ({ appPage }) => {
await appPage.login(email, password);
await expect(appPage.errorMessage).toBeVisible();
}
);
}For universal invalid-value loops (wrong type for any string/number/etc. field) import from test-data/static/util/invalid-values.ts (INVALID_STRING_VALUES, INVALID_NUMBER_VALUES, etc.). Full three-tier rule in the data-strategy skill.
Phase 9: Verify test independence and run
Tests must be independent — no test may depend on the outcome or side-effects of another test. Use fixtures and beforeEach for shared setup.
After adding or modifying a test file:
# Run the specific spec file
npx playwright test tests/app/functional/login.spec.ts
# Run by tag (exactly one tag match since tags never combine)
npx playwright test --grep @smoke
# Run the destructive suite
npm run test:destructiveDo not finish until the added/modified tests pass consistently. Do not suppress failures.
See Also
api-testingskill — full API test coverage matrix,test.steprequirements for multi-call tests, per-field negative-testing patterns, helper-fixture promotion rule (Phase 8).data-strategyskill — Faker + Zod factories, three-tier static data rule, universal invalid-value arrays, TS-only policy.fixturesskill — DI pattern,test-options.tsmerge layer, page-object fixture registration.page-objectsskill — POM class structure, action methods, component composition, fixture registration.selectorsskill — exploration-first workflow, locator priority, feedback / validation message selectors.common-tasksskill — copy-paste prompt templates for creating spec files of each type.refactor-valuesskill — safe workflow for changing enum values or static data used in assertions.debuggingskill — failure-mode taxonomy and the right Playwright tool (UI Mode, Trace Viewer, Inspector) when a test fails or behaves unexpectedly during Phase 9 verification.references/examples.md— four worked spec patterns (functional smoke, data-driven regression, destructive with cleanup, E2E multi-feature journey).references/troubleshooting.md— common test-standards pitfalls (@functional, tag arrays, wrong imports, hard waits, JSON data, manual instantiation, parallel collisions, destructive leaks, committed explore files).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

