From f22d08d1888fa98d49f9f0fd60d8250fabc72d95 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 24 Mar 2026 08:59:34 +0000 Subject: [PATCH] test: auto-init WPT submodule --- CONTRIBUTING.md | 4 +++ test/web-platform-tests/wpt-runner.mjs | 41 ++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fc84c50da3..c81acfaaba0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,6 +96,10 @@ Create a commit which includes all of the updated files in lib/llhttp. ### Steps: +`npm run test:wpt` and `node test/web-platform-tests/wpt-runner.mjs setup` will initialize the WPT submodule automatically when it is missing. + +If you want to prepare the checkout explicitly, run: + ```bash git submodule update --init --recursive ``` diff --git a/test/web-platform-tests/wpt-runner.mjs b/test/web-platform-tests/wpt-runner.mjs index b9bb94c2346..a1820a48ac3 100644 --- a/test/web-platform-tests/wpt-runner.mjs +++ b/test/web-platform-tests/wpt-runner.mjs @@ -11,17 +11,48 @@ import { } from './runner/utils.mjs' import * as jsondiffpatch from 'jsondiffpatch' +const REPO_ROOT = join(import.meta.dirname, '..', '..') const WPT_DIR = join(import.meta.dirname, 'wpt') +const WPT_SCRIPT_PATH = join(WPT_DIR, 'wpt') const EXPECTATION_PATH = join(import.meta.dirname, 'expectation.json') const CA_CERT_PATH = join(import.meta.dirname, 'runner/certs/cacert.pem') const log = debuglog('UNDICI_WPT') +async function ensureWPTCheckout () { + if (existsSync(WPT_SCRIPT_PATH)) { + return + } + + console.log('WPT checkout missing, attempting to initialize git submodule...') + + const submoduleProc = spawn('git', [ + 'submodule', + 'update', + '--init', + '--recursive', + '--', + 'test/web-platform-tests/wpt' + ], { + cwd: REPO_ROOT, + stdio: 'inherit' + }) + + const submoduleOk = await new Promise(resolve => { + submoduleProc.on('exit', code => resolve(code === 0)) + submoduleProc.on('error', () => resolve(false)) + }) + + if (!submoduleOk || !existsSync(WPT_SCRIPT_PATH)) { + throw new Error('WPT checkout is missing. Run `git submodule update --init --recursive test/web-platform-tests/wpt`.') + } +} + async function runWithTestUtil (testFunction) { const { promise, resolve, reject } = createDeferredPromise() console.log('Starting WPT server...') - const proc = spawn('python3', ['wpt', 'serve', '--config', '../runner/config.json'], { + const proc = spawn('python3', [WPT_SCRIPT_PATH, 'serve', '--config', '../runner/config.json'], { cwd: WPT_DIR, stdio: 'inherit' }) @@ -318,6 +349,8 @@ function generateWPTReport (results, startTime, endTime) { async function setup () { console.log('Setting up WPT environment...') + await ensureWPTCheckout() + // Check Python const pythonCheck = spawn('python3', ['--version'], { stdio: 'pipe' }) pythonCheck.stdout.setEncoding('ascii') @@ -343,7 +376,7 @@ async function setup () { const manifestPath = join(WPT_DIR, 'MANIFEST.json') if (!existsSync(manifestPath)) { console.log('Updating WPT manifest...') - const manifestProc = spawn('python3', ['wpt', 'manifest'], { + const manifestProc = spawn('python3', [WPT_SCRIPT_PATH, 'manifest'], { cwd: WPT_DIR, stdio: 'inherit' }) @@ -368,7 +401,7 @@ async function setup () { const etcHostsConfigured = hostsContent.includes('web-platform.test') async function setupHostsFile () { - const makeHostsProc = spawn('python3', ['wpt', 'make-hosts-file'], { + const makeHostsProc = spawn('python3', [WPT_SCRIPT_PATH, 'make-hosts-file'], { cwd: WPT_DIR, stdio: ['ignore', 'pipe', 'pipe'] }) @@ -438,6 +471,8 @@ async function setup () { } async function run (filters = []) { + await ensureWPTCheckout() + const startTime = Date.now() const expectation = getExpectation() const tests = discoverTestsToRun(filters, expectation)