Browse documentation

web-platform-tests run through WPT's own testharness.js, one runner test per subtest

Date: 2026-12-03 Area: tests, web-apis Related: #2491, #2442, Testing

Context

test262 covers ECMAScript only. The web APIs GocciaScript ships (Encoding, fetch's Headers and Response, DOM events and abort, Blob, the HTML globals) had hand-written suites only, so their spec bugs surfaced one at a time. URL's web-platform-tests (WPT) cases already run as generated suites (#2442), but those are JSON data files that a generator turns into test/expect code. The other APIs' WPT tests are testharness.js scripts (.any.js): they call test, promise_test and async_test with testharness.js's assertions, and often load support scripts named in // META: script= lines. #2491 asked for them to run in the normal test run, each WPT subtest one runner test named as WPT names it, with results that follow testharness.js's semantics.

Translating these scripts into test/expect code, or writing a testharness.js look-alike, would re-implement WPT's assertions and harness rules (assert_throws_js comparing constructors, assert_equals using SameValue, sequential promise_tests, step_func and done() bookkeeping, harness errors). A look-alike that is looser than testharness.js passes subtests WPT fails.

Decision

tests/web-platform-tests/ runs WPT's own resources/testharness.js, vendored unchanged at the revision in tests/compliance/wpt-web-apis.pin by scripts/regenerate-wpt-web-api-tests.js, a maintainer-only step like the URL generator. Normal runs need neither Node.js nor the network.

  • Each suite is a classic script. For each WPT test file run, the generator writes a suite holding the META scripts the file names and then the file itself, in the order WPT's worker wrapper (tools/serve/serve.py) loads them, followed by done() as that wrapper calls it. The suite imports helpers/wpt-harness.js with a dynamic import() and runs that code in the import's callback, in one scope where support scripts and tests may declare the same function, as separate classic scripts may. The callback is sloppy code unless the test file starts with a "use strict" directive; then the generator starts the callback with one, so the test and its support scripts run as strict code. goccia.json in the directory turns on the compatibility flags WPT's style needs. testharness.js itself runs as module code, which WPT also does for module workers.
  • testharness.js picks its shell environment. helpers/wpt-environment.js defines self and the GLOBAL object WPT's wrappers define, with isWindow, isWorker and isShadowRealm all false, and keeps the runner's test and describe before testharness.js replaces the global test. Because the test code runs a microtask after testharness.js has loaded, the adapter sets explicit_done so that the harness waits for the suite's done().
  • One runner test per subtest. The adapter records each subtest as testharness.js creates it (add_test_state_callback). The suite's describe registers a runner test for each, under its WPT name; each one waits for the harness to complete and passes when its subtest's status is PASS. A last runner test, harness status, fails on a harness error, a subtest declared after loading, or an expectation that names no subtest. testharness.js drops a subtest declared after it has completed without reporting it, so the adapter wraps the global test, async_test, promise_test and generate_tests before the file runs, and records what they declare once the suite has ended loading, which it does just before done().
  • Expectations are data, not edits. helpers/expectations.js lists the subtests that do not pass: a known failure names its issue and its runner test fails once the subtest passes, so an entry goes with its fix; a left-out subtest says why it cannot run here and is skipped. A whole file that cannot run (a DOM, wptserve, an API GocciaScript does not ship) is listed with its reason in the generator, which fails when a directory at a new revision holds an .any.js file it neither runs nor leaves out, and removes the suites it wrote for a file it no longer runs.
  • Stand-ins only for support scripts. A WPT support script that reaches for an API GocciaScript does not ship to build its fixtures is replaced by a stand-in in helpers/ that builds the same fixtures another way, such as common/sab.js, which makes SharedArrayBuffers through WebAssembly.Memory. A test file is never edited.

Consequences

  • WPT's assertions and harness rules apply unchanged, and a new WPT revision brings WPT's own harness changes with it.
  • Every failing subtest is either fixed, listed under an issue, or left out with a reason; a fix that makes a known failure pass fails the run until its entry is removed.
  • The suites rely on dynamic import() settling before the runner's pass, and on testharness.js working as strict module code, as it must for WPT's module workers.
  • Window, DOM and wptserve tests stay out, as they did for URL. A top-level var or function of a test is not a property of globalThis, unlike in a classic script; no suite run here depends on that.