Files
node/test/parallel/test-common-wpt-script-modifier.js
T
Filip Skokan 9b82b6f44f test: deflake user timing WPT assertions
The fixed 20 ms tolerance in mark.any.js can fail when execution pauses
between creating a mark and reading the clock. Adapt the test in memory
to check the mark timestamp against readings before and after mark().
Keep the vendored fixture and subtest names unchanged.

Apply script modifiers to worker entry scripts as well so the check
covers both WPT globals, and remove the suite-wide flaky expectation.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66036
Fixes: https://github.com/nodejs/node/issues/40449
Refs: https://github.com/nodejs/node/pull/41203
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-09-18 10:54:52 +00:00

39 lines
1.6 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const { spawnSync } = require('child_process');
if (process.env.NODE_TEST_WPT_MODIFIER_PROBE === '1') {
const { WPTRunner } = require('../common/wpt');
const runner = new WPTRunner('html/webappapis/atob');
runner.setScriptModifier(common.mustCall((script) => {
assert.strictEqual(script.filename,
fixtures.path('wpt', 'html/webappapis/atob', 'base64.any.js'));
script.filename += '.modified';
script.code = `test(() => {
assert_true(new Error().stack.includes(${JSON.stringify(`${script.filename}:`)}));
}, 'modified script retains its filename');`;
}, 2));
runner.runJsTests();
} else {
// eslint-disable-next-line no-unused-vars
const { NODE_TEST_WPT, WPT_REPORT, WPT_INSPECT, ...env } = { ...process.env, NODE_TEST_WPT_MODIFIER_PROBE: '1' };
for (const backend of ['thread', 'process']) {
const result = spawnSync(process.execPath, [__filename, 'base64.any.js'], {
env: { ...env, WPT_BACKEND: backend },
encoding: 'utf8',
timeout: common.platformTimeout(10_000),
});
const { error, status, stdout, stderr } = result;
assert.ifError(error);
assert.strictEqual(status, 0, stdout + stderr);
const results = stdout.split('\n').filter((line) => line.startsWith('[PASS]'));
assert.deepStrictEqual(results.sort(), [
'[PASS] html/webappapis/atob/base64.any.html: modified script retains its filename',
'[PASS] html/webappapis/atob/base64.any.worker.html: modified script retains its filename',
]);
}
}