Skip to content

Commit b63e449

Browse files
committed
test: pass URL's toascii.window.js WPT
PR-URL: #39910 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Nitzan Uziely <linkgoron@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
1 parent d14878d commit b63e449

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

test/common/wpt.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ class WPTRunner {
301301
this.inProgress = new Set();
302302
this.workers = new Map();
303303
this.unexpectedFailures = [];
304+
305+
this.scriptsModifier = null;
304306
}
305307

306308
/**
@@ -319,6 +321,14 @@ class WPTRunner {
319321
this.initScript = script;
320322
}
321323

324+
/**
325+
* Set the scripts modifier for each script.
326+
* @param {(meta: { code: string, filename: string }) => void}
327+
*/
328+
setScriptModifier(modifier) {
329+
this.scriptsModifier = modifier;
330+
}
331+
322332
get fullInitScript() {
323333
if (this.initScript === null && this.dummyGlobalThisScript === null) {
324334
return null;
@@ -330,7 +340,7 @@ class WPTRunner {
330340
return this.initScript;
331341
}
332342

333-
return `${this.fullInitScript}\n\n//===\n${this.initScript}`;
343+
return `${this.dummyGlobalThisScript}\n\n//===\n${this.initScript}`;
334344
}
335345

336346
/**
@@ -387,17 +397,21 @@ class WPTRunner {
387397
// Scripts specified with the `// META: script=` header
388398
if (meta.script) {
389399
for (const script of meta.script) {
390-
scriptsToRun.push({
400+
const obj = {
391401
filename: this.resource.toRealFilePath(relativePath, script),
392402
code: this.resource.read(relativePath, script, false)
393-
});
403+
};
404+
this.scriptsModifier?.(obj);
405+
scriptsToRun.push(obj);
394406
}
395407
}
396408
// The actual test
397-
scriptsToRun.push({
409+
const obj = {
398410
code: content,
399411
filename: absolutePath
400-
});
412+
};
413+
this.scriptsModifier?.(obj);
414+
scriptsToRun.push(obj);
401415

402416
const workerPath = path.join(__dirname, 'wpt/worker.js');
403417
const worker = new Worker(workerPath, {

test/wpt/status/url.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"toascii.window.js": {
3-
"requires": ["small-icu"],
4-
"skip": "TODO: port from .window.js"
3+
"requires": ["small-icu"]
54
},
65
"percent-encoding.window.js": {
76
"requires": ["small-icu"],

test/wpt/test-url.js

+8
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@ const { WPTRunner } = require('../common/wpt');
55

66
const runner = new WPTRunner('url');
77

8+
runner.setScriptModifier((obj) => {
9+
if (obj.filename.includes('toascii.window.js')) {
10+
// `a` and `area` in `toascii.window.js` is for testing `Element` that
11+
// created via `document.createElement`. So we need to ignore them and just
12+
// test `URL`.
13+
obj.code = obj.code.replace(/\["url", "a", "area"\]/, '[ "url" ]');
14+
}
15+
});
816
runner.pretendGlobalThisAs('Window');
917
runner.runJsTests();

0 commit comments

Comments
 (0)