Keeping test code clean: linting, formatting, hooks and review
Use a linter, a formatter, a type check, a git hook and a short review list so Playwright test code stays tidy and mistakes such as a missing await are caught before they run.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a workshop where each tool has a hook. You see at once which hook is empty. In a messy workshop you lose ten minutes, and you may grab the wrong tool because it looks the same.
Tom and Leo both write tests for Daily List, a to-do list app. After a few weeks the files look different. One test sleeps for five seconds. Another forgot a small word, await, so it moves on too early.
What it is: Playwright is a free program, made by Microsoft, that drives real browsers from test code. This topic is about keeping that test code tidy. A linter reads code and warns about risky habits. A rewrites spaces and line breaks into one style. A reads TypeScript without running it and reports values used the wrong way. A git hook is a script git runs by itself, for example just before a commit. A code review is a teammate reading the change. Continuous integration (CI) is the shared run that starts when code is pushed. The machines catch the same small slips. People judge whether the test is worth having.
Why it matters: a missing await can pass on a fast laptop and fail on a slow build. A fixed pause makes every run slow and still fails on a bad day. If the linter flags both before the commit, Mei reviews the idea, not the noise.
A tidy file can still test the wrong thing. Someone must still ask what the test proves.
Kept simple: other tools can do these jobs. This lesson uses the ones Playwright's own docs name, plus a formatter.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are invented.)
PLAIN WORDS · 2 in this section
- playwright
- a free Microsoft tool that drives a browser for tests
- typescript
- JavaScript with added labels for the kinds of data
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Keeping test code tidy and catching small slips automatically, so people can spend their review on the ideas.
- Format
- Lint and type check
- Hook on commit
- Review
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The hook on the wall for each tool | The agreed style the formatter enforces |
| Seeing a missing tool at a glance | The linter and type check marking a slip |
| The door lock that stops you leaving with a mess | The git hook that blocks a bad commit |
| The foreman walking round | The code review |
WHERE THIS PICTURE STOPS
- A tidy workshop does not make a good chair. Clean test code can still test the wrong thing.
- A wall hook is always there. A git hook can be skipped on one computer.
- A foreman can see the whole job. A rule only sees what it was told to look for.
HOOK
Tidy by machine, judged by people.
REMEMBER IT THIS WAY
A rule of thumb: if you see this, think that.
If a slip is small and a rule can spot it, let the formatter, linter or catch it. Keep the review for the ideas.
| In the trick | What it stands for |
|---|---|
| Formatter | tidies the layout |
| Linter | warns about risky habits |
| Git hook | stops a messy commit |
A rule only sees what it was told to look for, so clean test code can still test the wrong thing.
TELL A FRIEND
It is like a workshop where each tool has a hook on the wall, so a missing one shows at once.
OFTEN MIXED UP WITH Best practices and anti-patterns. The best-practices lesson says what good tests look like. This lesson shows the tools that help keep them that way.
Sources & standards — 6 sources
- Market practice
eslint-plugin-playwright (npm package page) ↗ — npm registry page for a community package · The package adds Playwright rules to ESLint; the no-wait-for-timeout rule flags page.waitForTimeout and is in the recommended set (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number; read at the time of writing. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Husky and lint-staged guide (Better Stack Community) ↗ — Better Stack · A pre-commit hook runs lint-staged on staged files only; if a task fails the commit is blocked (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number; read at the time of writing. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Test what the user sees, keep tests isolated, prefer role and text locators, use web-first assertions that retry, use TypeScript and ESLint to catch errors early, and run tsc --noEmit in the pipeline (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).
- Market practice
Auto-waiting (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
eslint-playwright ↗ — raw.githubusercontent.com · Reviewed 6 November 2026: Installation/usage and selected await/assertion/wait rules only. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Installation/usage and selected await/assertion/wait rules only. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
no-floating-promises | typescript-eslint ↗ — typescript-eslint.io · Reviewed 6 November 2026: no-floating-promises introduction, prerequisites, handled forms and examples only. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: no-floating-promises introduction, prerequisites, handled forms and examples only. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
PRACTISE AND KEEP
Sources for this topic — 6 sources
- Market practice
eslint-plugin-playwright (npm package page) ↗ — npm registry page for a community package · The package adds Playwright rules to ESLint; the no-wait-for-timeout rule flags page.waitForTimeout and is in the recommended set (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number; read at the time of writing. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Husky and lint-staged guide (Better Stack Community) ↗ — Better Stack · A pre-commit hook runs lint-staged on staged files only; if a task fails the commit is blocked (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number; read at the time of writing. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Test what the user sees, keep tests isolated, prefer role and text locators, use web-first assertions that retry, use TypeScript and ESLint to catch errors early, and run tsc --noEmit in the pipeline (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).
- Market practice
Auto-waiting (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
eslint-playwright ↗ — raw.githubusercontent.com · Reviewed 6 November 2026: Installation/usage and selected await/assertion/wait rules only. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Installation/usage and selected await/assertion/wait rules only. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
no-floating-promises | typescript-eslint ↗ — typescript-eslint.io · Reviewed 6 November 2026: no-floating-promises introduction, prerequisites, handled forms and examples only. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: no-floating-promises introduction, prerequisites, handled forms and examples only. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.