diff --git a/test/common/wpt.js b/test/common/wpt.js index 52f48685f315e3..bc6e66d75a4278 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -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, { diff --git a/test/wpt/status/url.json b/test/wpt/status/url.json index 36ff89e8e07d85..812f7a9ffce237 100644 --- a/test/wpt/status/url.json +++ b/test/wpt/status/url.json @@ -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"], diff --git a/test/wpt/test-url.js b/test/wpt/test-url.js index 0b731dbe89c608..f64189ea3f66d6 100644 --- a/test/wpt/test-url.js +++ b/test/wpt/test-url.js @@ -15,5 +15,13 @@ runner.setInitScript(` global.DOMException = DOMException; `); +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();