agentleFS
ychampionychampion/ystack/skills/bun-playwright-runner-selection/SKILL.md

bun-playwright-runner-selection

Skill4 starsChanged 2 days agoMITView on GitHub

Fix the error "Playwright Test did not expect test() to be called here" when a Playwright spec file is run with Bun's unit-test runner instead of the Playwright CLI. Use when: (1) a `*.spec.ts` file contains `import { test, expect } from '@playwright/test'`, (2) `bun test` was run on that file, and (3) the suite fails before any test runs. Run the suite with `bunx playwright test` instead.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test. The suite fails before any test runs, with an error that points somewhere else.

    line 16
  2. Distinctive:

    All of these hold:

    line 20
  3. Very specific:

    Don't run it with bun test.

    line 42
  4. Distinctive:

    Run the Playwright CLI through Bun's package runner:

    line 43
  5. Very specific:

    Keep using Bun for installs and scripts.

    line 55
  6. Very specific:

    If the error persists under bunx playwright test, then look at the usual Playwright causes: two versions of @playwright/test, or test() …

    line 86

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Bun: run Playwright specs with the Playwright runner

Problem

In Bun-based repos it is easy to run a Playwright spec with the wrong runner. Passed to bun test, a file that defines Playwright tests is treated as a Bun unit-test file instead of going to Playwright Test. The suite fails before any test runs, with an error that points somewhere else.

Trigger conditions

All of these hold:

  • The repo uses Bun for package management and scripts.
  • The test file imports from @playwright/test.
  • It was run with something like bun test path/to/file.spec.ts.
  • The failure looks like:
Playwright Test did not expect test() to be called here.
Most common reasons include:
- You are calling test() in a configuration file.
- You are calling test() in a file that is imported by the configuration file.
- You have two different versions of @playwright/test.

The message invites you to chase duplicate dependencies or bad imports when the only problem is the runner.

Solution

  1. Confirm the file is a Playwright spec, not a Bun unit test: it imports from @playwright/test and uses fixtures such as page or request.
  2. Don't run it with bun test.
  3. Run the Playwright CLI through Bun's package runner:
bunx playwright test path/to/file.spec.ts
  1. To pick specific tests, use Playwright's flags, not Bun's (-t is a Bun flag):
bunx playwright test "path/to/file.spec.ts" --grep "test name"
  1. Keep using Bun for installs and scripts; use the Playwright CLI for Playwright suites. A package.json script such as "e2e": "playwright test" (run with bun run e2e) stops the mistake from recurring.

Verification

  • The test() error is gone.
  • Playwright reports the expected number of tests (Running N tests using M workers).
  • The run ends with Playwright's normal summary (N passed).

Example

Wrong:

bun test tests/checkout.e2e.spec.ts -t "applies discount"
# error: Playwright Test did not expect test() to be called here.

Right:

bunx playwright test tests/checkout.e2e.spec.ts --grep "applies discount"
# 1 passed

Notes

  • This is about runner choice, not a broken Playwright install.
  • bunx is Bun's equivalent of npx or pnpm exec for package CLIs, and it honours Node shebangs, so bunx playwright ... runs the Playwright CLI as intended.
  • If the error persists under bunx playwright test, then look at the usual Playwright causes: two versions of @playwright/test, or test() called from a file the config imports.
  • To keep bun test from picking up e2e specs at all, keep them in a folder Bun's runner doesn't scan, or point bun test at your unit-test paths explicitly.

References

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.