Skip to content

Commit da09cd3

Browse files
committed
Make focused WPT runs register only matching cases
1 parent aff2e8f commit da09cd3

21 files changed

Lines changed: 517 additions & 39 deletions

‎.changeset/wpt-focused-runs.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@bomb.sh/web-platform-tests': patch
3+
---
4+
5+
Allow runners to filter configured WPT cases before test registration. Provide a Vitest integration and a Router-based `wpt` command that accepts literal search text, so focused runs omit unrelated cases instead of reporting them as skipped.

‎.github/workflows/benchmark.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
persist-credentials: false
2323
- uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0
2424
- run: pnpm install --frozen-lockfile
25+
- run: pnpm --filter @bomb.sh/web-platform-tests build
2526
- name: Run benchmarks with CodSpeed
2627
uses: CodSpeedHQ/action@78102a468f96d8e0ccb92d0ec49425753fc42062 # v5
2728
with:

‎.github/workflows/check.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
persist-credentials: false
4141
- uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0
4242
- run: pnpm install --frozen-lockfile
43+
- run: pnpm --filter @bomb.sh/web-platform-tests build
4344
- run: pnpm test
4445

4546
dom-wpt:

‎CONTRIBUTING.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ You need the exact Node and pnpm versions listed under `devEngines` in the root
1515

1616
Any version manager works. If you use [mise](https://mise.jdx.dev), which is what our lint, format, and test checks use, export `MISE_IDIOMATIC_VERSION_FILE_ENABLE_TOOLS=node,pnpm` and run `mise install` so it reads those versions from `package.json`.
1717

18-
Then install the dependencies:
18+
Then install the dependencies and build the packages:
1919

2020
```sh
2121
pnpm install
22+
pnpm build
2223
```
2324

2425
## Commands you'll use
2526

26-
Run these from the repo root. You don't need to build before you run the tests.
27+
Run these from the repo root. Tests and benchmarks reuse the built WPT package.
28+
Rebuild it after changing its sources with `pnpm --filter @bomb.sh/web-platform-tests build`;
29+
you can run tests repeatedly without rebuilding otherwise.
2730

2831
| Command | What it does |
2932
| ------------------------------------------ | ----------------------------------------- |
@@ -63,12 +66,13 @@ Use `expect.poll` here, because the screen doesn't update the moment you change
6366
Before you push, make sure these pass:
6467

6568
```sh
69+
pnpm build
6670
pnpm lint
6771
pnpm format:check
6872
pnpm test
6973
```
7074

71-
CI runs the same three on every pull request, along with the benchmarks and a workflow that publishes a preview build. In your PR, tell us why the change is needed and link the issue if there is one.
75+
CI runs these checks on every pull request, building the WPT package once before tests or benchmarks. A separate workflow publishes a preview build. In your PR, tell us why the change is needed and link the issue if there is one.
7276

7377
## Be kind
7478

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
"format": "bsh format",
3434
"format:check": "bsh format --check",
3535
"lint": "bsh lint .",
36-
"test": "pnpm --filter @bomb.sh/web-platform-tests build && bsh test"
36+
"test": "vitest run --config vitest.config.mts --experimental.viteModuleRunner",
37+
"wpt": "wpt --file packages/ui/src/dom.compatibility.test.ts"
3738
},
3839
"devDependencies": {
3940
"@bomb.sh/tools": "^0.8.0",
41+
"@bomb.sh/web-platform-tests": "workspace:*",
4042
"@codspeed/vitest-plugin": "^6.1.0",
4143
"@termless/core": "^0.10.2",
4244
"@termless/test": "^0.10.2",

‎packages/ui/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"build": "bsh build --dts",
3434
"format": "bsh format",
3535
"lint": "bsh lint",
36-
"test": "pnpm --filter @bomb.sh/web-platform-tests build && bsh test"
36+
"test": "vitest run --config ../../vitest.config.mts --experimental.viteModuleRunner"
3737
},
3838
"dependencies": {
3939
"@bomb.sh/tty": "catalog:"
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { describe, it, expect } from 'vitest';
2-
import { testDOMCompatibility } from '@bomb.sh/web-platform-tests';
1+
import { testDOMCompatibility } from '@bomb.sh/web-platform-tests/vitest/runner';
32
import { Document } from './dom.ts';
43
import config from '../test/wpt.config.ts';
54

65
testDOMCompatibility({
7-
runner: { describe, it, expect },
86
config,
97
create: () => new Document(() => {}),
108
});

‎packages/ui/test/README.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# UI tests
22

3-
Tests live alongside the implementation in `src/`; this directory contains their shared fixtures and WPT configuration. Run the UI tests from the workspace root:
3+
Tests live in `src/` and this directory, alongside shared fixtures and WPT configuration. Run the UI tests from the workspace root:
44

55
```sh
66
pnpm --filter @clack/ui test
77
```
88

9-
The test script builds the private `@bomb.sh/web-platform-tests` package before running Vitest. Use `pnpm test` from the workspace root to run the workspace tests.
9+
Run `pnpm build` once before testing, and rebuild the private `@bomb.sh/web-platform-tests` package after changing its sources. Test commands reuse that build. Use `pnpm test` from the workspace root to run the workspace tests.
1010

1111
## Terminal fixtures
1212

@@ -26,13 +26,16 @@ Rendering, scheduling, notifications, and lifecycle behavior belong in the UI te
2626

2727
The configuration explicitly excludes unsupported directories. Add includes or narrow exclusions as cases pass. Selecting a source runs all of our adapted cases from that file; it does not imply complete coverage of the upstream file or interface.
2828

29-
Include the source or case in the configuration while implementing it. Vitest's `-t` can narrow the configured selection by source path and case name:
29+
Include the source or case in the configuration while implementing it. Run matching cases by supplying plain text from a source path or case name:
3030

3131
```sh
32-
pnpm --filter @clack/ui test src/dom.compatibility.test.ts -t 'Document-createElement.html.*createElement\(foo\)'
32+
pnpm wpt createElement
33+
pnpm wpt 'createElement(foo) in HTML document'
3334
```
3435

35-
If the shared package is already built, avoid rebuilding by using `pnpm --filter @clack/ui exec bsh test src/dom.compatibility.test.ts` with the same name filter.
36+
The script invokes the package-owned `wpt` CLI, which uses `@bomb.sh/router` to parse arguments and launches Vitest with the UI test entrypoint. It reuses the existing WPT build. The search is a literal substring, so punctuation needs no regex escaping. Omit the search text (`pnpm wpt`) to run all configured cases. Matching happens before Vitest registers tests, so unrelated cases do not appear as skipped.
37+
38+
The root Vitest configuration imports `wptNameFilter()` from `@bomb.sh/web-platform-tests/vitest`; the UI entrypoint uses the worker adapter from `@bomb.sh/web-platform-tests/vitest/runner`. Direct Vitest runs still support `-t` regular expressions. Watch mode retains the full configured catalogue so changing its interactive name filter can discover other cases.
3639

3740
When implementing behavior, read the source-named file under [`src/wpt`](../../web-platform-tests/src/wpt), implement its operations, and update the configuration once its cases pass. Extend the fixture when cases need document parsing, host input, or cleanup. Implementation-specific rendering, notification, and lifecycle checks remain in the UI tests.
3841

‎packages/web-platform-tests/README.md‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,51 @@ The WPT suite must contain only faithful adaptations of existing upstream cases.
1616

1717
The shared suite is the long-term home of upstream WPT coverage for the UI. Implementation-specific rendering, notification, and lifecycle checks belong in the corresponding UI integration tests.
1818

19+
### Vitest integration
20+
21+
Register `wptNameFilter()` in the consumer's Vitest configuration:
22+
23+
```ts
24+
import { defineConfig } from 'vitest/config';
25+
import { wptNameFilter } from '@bomb.sh/web-platform-tests/vitest';
26+
27+
export default defineConfig({ plugins: [wptNameFilter()] });
28+
```
29+
30+
The test entrypoint supplies the DOM implementation and case selection:
31+
1932
```ts
20-
import { testDOMCompatibility } from '@bomb.sh/web-platform-tests';
21-
import { describe, it, expect } from 'vitest';
33+
import { testDOMCompatibility } from '@bomb.sh/web-platform-tests/vitest/runner';
2234
import { createDocument, dispose } from './implementation-fixture.ts';
2335
import config from './wpt.config.ts';
2436

2537
testDOMCompatibility({
26-
runner: { describe, it, expect },
2738
config,
2839
create: createDocument,
2940
dispose,
3041
// input: document => createHostInputSession(document),
3142
});
3243
```
3344

45+
The configuration plugin is safe to import outside a test worker. The separate worker adapter supplies Vitest's assertions and filters cases before registration. Direct Vitest `-t` filters work too; watch mode retains the full configured catalogue so interactive filter changes can discover other cases.
46+
47+
The main `@bomb.sh/web-platform-tests` entrypoint remains independent of Vitest. Other runners can use its `testDOMCompatibility()` with their own `runner: { describe, it, expect, filter? }`.
48+
49+
### CLI
50+
51+
The package provides a `wpt` executable using `@bomb.sh/router`. Install Vitest in the consuming workspace and build the WPT package before running it:
52+
53+
```sh
54+
pnpm --filter @bomb.sh/web-platform-tests build
55+
pnpm exec wpt --file path/to/dom.compatibility.test.ts createElement
56+
pnpm exec wpt --file path/to/dom.compatibility.test.ts 'createElement(foo) in HTML document'
57+
pnpm exec wpt --help
58+
```
59+
60+
`--file` selects the consumer's test entrypoint. `--config` optionally selects its Vitest configuration; otherwise Vitest discovers the configuration from the current working directory. Paths are relative to the caller, so the CLI does not depend on this repository's layout or package manager. The configuration must include `wptNameFilter()` and the entrypoint must use the worker adapter shown above.
61+
62+
Search text is an optional literal substring of a source path or case name. Multiple words are joined with spaces; use `--` before search text beginning with a dash. Omit the search to run all configured cases. The CLI forwards Vitest's exit status and never runs a build. Rebuild after changing WPT package sources, then reuse the output across focused runs.
63+
3464
### Selecting tests
3565

3666
The `config` option is optional; omitting it runs all adapted cases. A `WPTConfig` supplies source-path selectors in `include` and `exclude`; an explicit include always wins. Each value is `true` for the entire source file or an array of exact case names and regular expressions matching case names.
@@ -50,7 +80,7 @@ export default {
5080

5181
Source paths support `*` within a path segment and `**` across directories; `**/` also matches zero directories. Other characters are literal. Case-name strings match exactly. Empty, invalid, or unmatched selectors fail configuration before any cases register, so stale exclusions remain visible.
5282

53-
Cases have no test-to-test prerequisite gates. A selected case exercises its supporting DOM operations and reports failures normally. Globals and host input are resolved lazily when the case uses them. The runner can narrow selected cases further with its usual name filter.
83+
Cases have no test-to-test prerequisite gates. A selected case exercises its supporting DOM operations and reports failures normally. Globals and host input are resolved lazily when the case uses them. An optional `runner.filter(source, name)` narrows configured cases before registering suites or tests with the runner. Configuration is still validated against the full catalogue. If this filter matches nothing, the harness registers nothing.
5484

5585
Run `pnpm generate` after adding, moving, or removing source files. The build also regenerates the registry from filenames. Only files exporting `register` are test entrypoints; upstream support files are imported by those tests. `node scripts/generate-registry.mjs --check` verifies that the checked-in registry is current.
5686

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
await import('../dist/cli.mjs');

0 commit comments

Comments
 (0)