test: pass URL's toascii.window.js WPT

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
XadillaX 2021-08-27 16:45:01 +08:00
parent d14878dc7c
commit b63e449b2e
3 changed files with 28 additions and 7 deletions

View File

@ -301,6 +301,8 @@ class WPTRunner {
this.inProgress = new Set();
this.workers = new Map();
this.unexpectedFailures = [];
this.scriptsModifier = null;
}
/**
@ -319,6 +321,14 @@ class WPTRunner {
this.initScript = script;
}
/**
* Set the scripts modifier for each script.
* @param {(meta: { code: string, filename: string }) => void}
*/
setScriptModifier(modifier) {
this.scriptsModifier = modifier;
}
get fullInitScript() {
if (this.initScript === null && this.dummyGlobalThisScript === null) {
return null;
@ -330,7 +340,7 @@ class WPTRunner {
return this.initScript;
}
return `${this.fullInitScript}\n\n//===\n${this.initScript}`;
return `${this.dummyGlobalThisScript}\n\n//===\n${this.initScript}`;
}
/**
@ -387,17 +397,21 @@ class WPTRunner {
// Scripts specified with the `// META: script=` header
if (meta.script) {
for (const script of meta.script) {
scriptsToRun.push({
const obj = {
filename: this.resource.toRealFilePath(relativePath, script),
code: this.resource.read(relativePath, script, false)
});
};
this.scriptsModifier?.(obj);
scriptsToRun.push(obj);
}
}
// The actual test
scriptsToRun.push({
const obj = {
code: content,
filename: absolutePath
});
};
this.scriptsModifier?.(obj);
scriptsToRun.push(obj);
const workerPath = path.join(__dirname, 'wpt/worker.js');
const worker = new Worker(workerPath, {

View File

@ -1,7 +1,6 @@
{
"toascii.window.js": {
"requires": ["small-icu"],
"skip": "TODO: port from .window.js"
"requires": ["small-icu"]
},
"percent-encoding.window.js": {
"requires": ["small-icu"],

View File

@ -5,5 +5,13 @@ const { WPTRunner } = require('../common/wpt');
const runner = new WPTRunner('url');
runner.setScriptModifier((obj) => {
if (obj.filename.includes('toascii.window.js')) {
// `a` and `area` in `toascii.window.js` is for testing `Element` that
// created via `document.createElement`. So we need to ignore them and just
// test `URL`.
obj.code = obj.code.replace(/\["url", "a", "area"\]/, '[ "url" ]');
}
});
runner.pretendGlobalThisAs('Window');
runner.runJsTests();