Skip to content

E2E Tests You Can Re-run by Module Name

Adityo Guni Waluyo

Forgetting spec filenames whenever one page needs testing? A thin resolver plus an honest coverage ledger.

TL;DR

A 73-line bash script maps module names to Playwright specs so you can rerun one page instead of the whole suite. It checks folders, matches spec files, forwards flags like headed mode, and lists modules from describe blocks. A companion ledger tracks coverage per feature and requires new code to update its row, keeping gaps visible.

# E2E Tests You Can Re-run by Module Name

I was about to ship a small fix to the /peta page. What I actually needed was the test for that one page. The problem: memory is a bad place to store "which file is the map test in, and which flags does it need".

The old habit: open the E2E specs folder, scroll one by one, guess filenames. When in doubt, run the whole suite. Not forever, just wasteful when a single file would do. Tests you once wrote are fragile on an invisible axis: the file never disappears from the repo, but it disappears from the list of who-tests-what.

This commit ships two artifacts for that problem: run_page.sh for calling tests, INDEX.md for recording them.

A thin resolver on top of Playwright

Playwright already accepts a spec file name or a folder directly as arguments [7]. So the resolver does not need to be clever. run_page.sh is 73 lines, and its core is translating a module name into a target: is there a / folder? Run it. Are there files matching *.spec.ts? Run all of them. Nothing found? Fail with a message that points somewhere: "see: run_page.sh --list".

File discovery leans on Playwright's default patterns, so spec files under the E2E folder become module candidates automatically [6]. Meanwhile the list option prints modules plus a description pulled from the first describe block in each file. Arguments after the module name pass straight through to Playwright, so headed mode keeps working [7]:

bash scripts/unit_testing/run_page.sh --list
bash scripts/unit_testing/run_page.sh peta --headed

No JSON parser, no hand-maintained mapping. When I wondered "how fancy does this script need to be", the answer turned out to be: as plain as possible. The selective-invocation ability was already in Playwright; only the naming layer was missing.

INDEX.md, a ledger allowed to be honest

The resolver only answers "how do I call it". The question that slips away more often: "what is actually covered by tests?". Hence INDEX.md: a table per page or feature across four tiers, from per-page E2E down to frontend unit and smoke, complete with a re-run command column.

What keeps this ledger from rotting is its rule: a slice that ships tests must add its row in the same commit. And rows are allowed to be honest. The admin module has no specs yet, and the table says exactly that: no specs, a specific slice must create them and update this row. The "not tested yet" state stays visible instead of quietly vanishing among files nobody opens.

One small trap I noted: there are two --list flags. Playwright's collects and reports all tests without running them [8]. run_page.sh's only lists modules from filenames. The difference is thin, but at the terminal you can ping-pong between them.

One door in

The repo's testing rules now ban typing go or npm test commands directly: everything goes through one runner folder. The reason is not aesthetics. Decisive flags slip away when typing by hand, like the single-process number in the backend runner that protects the shared test database across packages.

My habit now: after touching a page, just run_page.sh . If the spec turns out not to exist, the one talking is not my guess but INDEX.md — complete with the rule for who has to fill it in.

Sources

[6] https://github.com/microsoft/playwright/blob/main/docs/src/test-configuration-js.md

[7] https://github.com/microsoft/playwright/blob/main/docs/src/running-tests-js.md

[8] https://github.com/microsoft/playwright/blob/main/docs/src/test-cli-js.md

Related articles