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

fix WPT test harness #3158

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/workerd/api/wpt/url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { run } from 'harness';

export const idnaTestV2Window = run('IdnaTestV2.window.js');
export const historical = run('historical.any.js', {
expectedFailures: ["Setting URL's href attribute and base URLs"],
expectedFailures: [
'Constructor only takes strings',
"Setting URL's href attribute and base URLs",
'URL: no structured serialize/deserialize support',
'URLSearchParams: no structured serialize/deserialize support',
],
});
// TODO(soon): Implement `globalThis.document`
export const javascriptUrlsWindow = run('javascript-urls.window.js', {
Expand Down
58 changes: 36 additions & 22 deletions src/wpt/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ globalThis.promise_test = (callback, message) => {
}

try {
globalThis.promises.push(callback());
globalThis.promises.push(callback.call(this));
} catch (err) {
globalThis.errors.push(new AggregateError([err], message));
const agg_err = new AggregateError([err], message);
agg_err.stack = err.stack;
globalThis.errors.push(agg_err);
}
};

Expand Down Expand Up @@ -184,33 +186,49 @@ globalThis.assert_throws_js = (
}
};

globalThis.assert_throws_exactly = (expected, fn, message) => {
globalThis.assert_throws_exactly = (expected, fn, message, assertion_type) => {
try {
fn();
fn.call(this);
ok(false, assertion_type, message, `${fn} did not throw`);
} catch (actual) {
if (e instanceof AssertionError) {
throw e;
}
deepStrictEqual(actual, expected, message);
}
};

globalThis.assert_throws_dom = (name, fn, message) => {
throws(
fn,
(err) => {
ok(err instanceof DOMException, message);
deepStrictEqual(err.name, name, message);
return true;
},
message
);
globalThis.assert_throws_dom = (
type,
func,
description,
assertion_type,
constructor
) => {
try {
fn.call(this);
ok(false, assertion_type, description, `${func} did not throw`);
} catch (e) {
if (e instanceof AssertionError) {
throw e;
}

strictEqual(
typeof e,
'object',
`${func} threw with type ${typeof e}, not an object`
);
strictEqual(e, null, `${func} threw null, not an object`);
}
};

globalThis.test = (callback, message) => {
globalThis.test = (fn, message) => {
if (!shouldRunTest(message)) {
return;
}

try {
callback();
fn.call(this);
} catch (err) {
globalThis.errors.push(new AggregateError([err], message));
}
Expand Down Expand Up @@ -253,13 +271,9 @@ async function validate(options) {
const expectedFailures = new Set(options.expectedFailures ?? []);

for (const err of globalThis.errors) {
const sanitizedError = new AggregateError(
err.errors,
sanitizeMessage(err.message)
);
if (!expectedFailures.delete(err.message)) {
console.error(sanitizedError);
throw new Error('Test failed');
err.message = sanitizeMessage(err.message);
throw err;
}
}

Expand Down