Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
submodules: true
- uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0
- run: pnpm install --frozen-lockfile
- run: pnpm --filter @bomb.sh/web-platform-tests exec playwright install --with-deps chromium
- run: pnpm test

dom-wpt:
Expand Down
26 changes: 16 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Fork the repo, then clone your fork:
```sh
git clone https://github.com/<your-username>/ui.git
cd ui
git submodule update --init packages/web-platform-tests/wpt
```

You need the exact Node and pnpm versions listed under `devEngines` in the root `package.json`. This part is picky. The wrong Node stops `pnpm install` right away, and pnpm 11 fails on the `node-pty` build.
Use the Node and pnpm versions listed under `devEngines` in the root `package.json`. The build and test scripts rely on pnpm's workspace task runner.

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`.

Expand All @@ -25,15 +26,20 @@ pnpm install

Run these from the repo root. You don't need to build before you run the tests.

| Command | What it does |
| ------------------------------------------ | ----------------------------------------- |
| `pnpm test` | Runs every test |
| `pnpm test packages/ui/src/layout.test.ts` | Runs one test file |
| `pnpm lint` | Runs the linter |
| `pnpm format` | Formats the code |
| `pnpm format:check` | Checks the formatting and changes nothing |
| `pnpm build` | Builds the packages |
| `pnpm bench` | Runs the benchmarks |
| Command | What it does |
| ----------------------------------------------- | --------------------------------------------------- |
| `pnpm test` | Runs unit tests once, then builds and runs WPT |
| `pnpm test:unit` | Runs unit tests in watch mode |
| `pnpm test:unit packages/ui/src/layout.test.ts` | Watches one unit test file |
| `pnpm test:unit:run` | Runs unit tests once, without watch mode |
| `pnpm test:wpt` | Runs WPT watching for changes in interactive terminals |
| `pnpm lint` | Runs the linter |
| `pnpm format` | Formats the code |
| `pnpm format:check` | Checks the formatting and changes nothing |
| `pnpm build` | Builds the packages |
| `pnpm bench` | Runs the benchmarks |

`pnpm install` installs the Chromium browser used by WPT. The WPT submodule must also be initialized (as above). The WPT command builds its runner automatically; no manual build is needed.

The benchmarks take a few minutes, so you only need them for changes that could affect rendering speed.

Expand Down
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@bomb.sh/ui-workspace",
"name": "root",
"private": "true",
"version": "0.0.0",
"keywords": [
"bombshell",
Expand Down Expand Up @@ -27,13 +28,17 @@
"access": "public"
},
"scripts": {
"prepare": "pnpm --filter @bomb.sh/web-platform-tests exec playwright install --with-deps chromium",
"dev": "bsh dev",
"build": "pnpm --filter @bomb.sh/web-platform-tests build && pnpm --filter \"@clack/*\" run build",
"bench": "vitest bench --reporter=verbose",
"build": "pnpm -r --filter '@clack/*...' run build",
"bench": "vitest bench --project 'bench (bench)' --reporter=verbose",
"format": "bsh format",
"format:check": "bsh format --check",
"lint": "bsh lint .",
"test": "pnpm --filter @bomb.sh/web-platform-tests build && bsh test && pnpm --filter @clack/ui exec wpt"
"test": "pnpm -r --filter root run --workspace-concurrency=1 '/^test:(unit:run|wpt)$/' --run",
"test:unit": "vitest --config vitest.config.mts --project unit",
"test:unit:run": "vitest run --config vitest.config.mts --project unit",
"test:wpt": "pnpm --filter @clack/ui test:wpt"
},
"devDependencies": {
"@bomb.sh/tools": "^0.8.0",
Expand All @@ -48,13 +53,13 @@
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "10.7.0",
"version": "11.28.13",
"onFail": "warn"
},
"runtime": {
"name": "node",
"version": "22.23.4",
"onFail": "error"
"version": "22.23.5",
"onFail": "warn"
}
}
}
17 changes: 12 additions & 5 deletions packages/ui/bench/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export async function setupUI(
shape: (typeof shapes)[number],
): Promise<UIWorkloadFixture> {
const input = new PassThrough();
const controller = new AbortController();
let writes = 0;
const output = new Writable({
write(_chunk, _encoding, callback) {
Expand All @@ -95,10 +96,11 @@ export async function setupUI(
});
},
});
const ui = await createUI({ input, output, width: 80, height: 24 });
const ui = await createUI({ input, output, width: 80, height: 24, signal: controller.signal });
const { texts } = createTree({ document: ui.document, nodeCount, shape });
const initialWrites = writes;
let started = false;
let running: Promise<void> | undefined;
return {
document: ui.document,
root: ui.document.documentElement,
Expand All @@ -110,13 +112,18 @@ export async function setupUI(
async start() {
if (started) return;
started = true;
void ui.main();
running = ui.main();
void running.catch(() => {});
await waitFor(() => writes > initialWrites);
},
async close() {
await ui[Symbol.asyncDispose]();
input.destroy();
output.destroy();
controller.abort();
try {
await running;
} finally {
input.destroy();
output.destroy();
}
},
};
}
Expand Down
19 changes: 5 additions & 14 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,21 @@
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"scripts": {
"dev": "bsh dev",
"bench": "vitest bench --config ../../vitest.config.mts --reporter=verbose",
"build": "bsh build --dts",
"format": "bsh format",
"lint": "bsh lint",
"test": "pnpm --filter @bomb.sh/web-platform-tests build && bsh test && wpt"
"test:wpt": "pnpm -r --filter '{.}...' run .wpt",
".wpt": "wpt --config ./wpt.config.ts"
},
"dependencies": {
"@bomb.sh/tty": "catalog:",
"css-select": "^7.0.0"
},
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "^10.7.0",
"onFail": "error"
},
"runtime": {
"name": "node",
"version": "^22.14.0",
"onFail": "error"
}
},
"devDependencies": {
"@bomb.sh/web-platform-tests": "workspace:*"
}
Expand Down
31 changes: 16 additions & 15 deletions packages/web-platform-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ pnpm --filter @clack/ui exec wpt --config wpt.config.ts Document-createElementNS
pnpm --filter @clack/ui exec wpt --watch Node-parentNode -t 'Root element'
```

`--watch` (or `-w`) keeps the CLI running. It reruns the selected upstream files
when `wpt.config.ts` or a local implementation module imported by that config
changes, including transitive imports. Config edits reload source and case
selection. Each rerun starts fresh Vitest and WPT workers, so implementation
In an interactive terminal, the CLI watches by default similar to `vitest`. Using
`--watch` (or `-w`) forces watch mode in a non-interactive terminal. It reruns the
selected upstream files when `wpt.config.ts` or a local implementation module imported
by that config changes, including transitive imports. Config edits reload source and
case selection. Each rerun starts fresh Vitest and WPT workers, so implementation
changes take effect and upstream scripts execute again. The watcher ignores the
pinned WPT checkout, package helpers, dependencies, and generated output. Press
Ctrl+C to stop. Without `--watch`, the CLI runs once and retains its usual exit
status for CI.
Ctrl+C to stop. In CI or when passing `--run`, it forces a single run and exits
on completion.

`pnpm test` and `pnpm --filter @clack/ui test` build the harness, run the local
implementation tests, and run the configured WPT cases.
Expand All @@ -49,20 +50,20 @@ implementation's global bindings, then selects upstream source paths and origina
case names. See the [UI configuration](../ui/wpt.config.ts).

```ts
import type { WPTConfig } from '@bomb.sh/web-platform-tests/config';
import { createHTMLDocument, Node, Document, Element } from './dom.ts';
import type { WPTConfig } from "@bomb.sh/web-platform-tests/config";
import { createHTMLDocument, Node, Document, Element } from "./dom.ts";

export default {
createDocument: () => createHTMLDocument(),
globals: { Node, Document, Element },
include: {
'dom/nodes/Node-parentNode.html': ['Document', 'Root element'],
"dom/nodes/Node-parentNode.html": ["Document", "Root element"],
},
exclude: { '**': true },
exclude: { "**": true },
// excluded cases that run for their shared state, but we don't wait for
forceTimeout: {
// Waits on an iframe load the fixture cannot deliver.
'dom/nodes/Node-parentNode.html': ['Removed iframe'],
"dom/nodes/Node-parentNode.html": ["Removed iframe"],
},
} satisfies WPTConfig;
```
Expand Down Expand Up @@ -90,14 +91,14 @@ Solid, or Svelte. Pass them to `include` with `exclude: { '**': true }` to run
that profile against the consumer's document factory and globals:

```ts
import { framework, type WPTConfig } from '@bomb.sh/web-platform-tests';
import { createDocument, globals } from './dom.ts';
import { framework, type WPTConfig } from "@bomb.sh/web-platform-tests";
import { createDocument, globals } from "./dom.ts";

export default {
createDocument,
globals,
include: framework('preact'),
exclude: { '**': true },
include: framework("preact"),
exclude: { "**": true },
} satisfies WPTConfig;
```

Expand Down
2 changes: 1 addition & 1 deletion packages/web-platform-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"scripts": {
"build": "bsh build src/index.ts src/config.ts src/cli.ts src/vitest.ts src/vitest/runner.ts src/node/worker.ts --dts",
"test": "bsh test",
"test:unit": "vitest",
"typecheck": "tsc -p tsconfig.json",
"format": "bsh format",
"lint": "bsh lint"
Expand Down
10 changes: 9 additions & 1 deletion packages/web-platform-tests/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const app = command(
description('WPT configuration path, relative to the current directory.'),
schema(z.string().min(1).default('wpt.config.ts')),
),
toggle(
name('run'),
cli(['--run'], { switch: true }),
description('Run and exit on completion.'),
schema(z.boolean().default(false)),
),
option(
name('name'),
cli(['--name', '-t']),
Expand All @@ -35,6 +41,7 @@ const app = command(
name('watch'),
cli(['--watch', '-w'], { switch: true }),
description('Rerun selected WPT cases when the config or its implementation changes.'),
schema(z.boolean().default(process.stdout.isTTY === true)),
),
argument(
name('files'),
Expand All @@ -57,7 +64,8 @@ if (!result.ok) {
files: [...result.model.files, ...Array.from(result.literals, (literal) => literal.text)],
namePattern: result.model.name,
};
if (result.model.watch) {
const watch = !result.model.run && result.model.watch;
if (watch) {
await watchWPT(options);
} else {
const vitest = await runWPT(options);
Expand Down
Loading
Loading