Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions test/common/wpt.js
Expand Up @@ -301,6 +301,8 @@ class WPTRunner {
this.inProgress = new Set();
this.workers = new Map();
this.unexpectedFailures = [];

this.scriptsModifier = null;
}

/**
Expand All @@ -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;
Expand All @@ -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}`;
}

/**
Expand Down Expand Up @@ -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, {
Expand Down
3 changes: 1 addition & 2 deletions 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"],
Expand Down
8 changes: 8 additions & 0 deletions test/wpt/test-url.js
Expand Up @@ -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();