Skip to content

Commit c670984

Browse files
committed
improve web-platform test harness
1 parent e3d2573 commit c670984

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/wpt/harness/assertions.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,14 @@ declare global {
8181
maybeDescription?: string
8282
): Promise<unknown>;
8383

84+
function assert_own_property(
85+
object: object,
86+
property_name: string | symbol,
87+
description?: string
88+
): void;
8489
function assert_not_own_property(
8590
object: object,
86-
property_name: string,
91+
property_name: string | symbol,
8792
description?: string
8893
): void;
8994
function promise_rejects_js(
@@ -439,6 +444,21 @@ globalThis.promise_rejects_dom = (
439444
});
440445
};
441446

447+
/**
448+
* Assert that ``object`` has an own property with name ``property_name``.
449+
*
450+
* @param object - Object that should have the given property.
451+
* @param property_name - Property name to test.
452+
* @param [description] - Description of the condition being tested.
453+
*/
454+
globalThis.assert_own_property = (object, property_name, description): void => {
455+
ok(
456+
Object.prototype.hasOwnProperty.call(object, property_name),
457+
`expected property ${String(property_name)} missing on object: ` +
458+
(description ?? '')
459+
);
460+
};
461+
442462
/**
443463
* Assert that ``object`` does not have an own property with name ``property_name``.
444464
*
@@ -453,7 +473,7 @@ globalThis.assert_not_own_property = (
453473
): void => {
454474
ok(
455475
!Object.prototype.hasOwnProperty.call(object, property_name),
456-
`unexpected property ${property_name} is found on object: ` +
476+
`unexpected property ${String(property_name)} is found on object: ` +
457477
(description ?? '')
458478
);
459479
};

src/wpt/harness/globals.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ import { getBindingPath } from './common';
2929
// @ts-expect-error We're just exposing enough stuff for the tests to pass; it's not a perfect match
3030
globalThis.self = globalThis;
3131

32+
// WPT tests use self.URL which requires URL to be an own property of globalThis
33+
globalThis.URL = URL;
34+
35+
// Some WPT tests reference addEventListener at the top level during file evaluation.
36+
// workerd doesn't have addEventListener on the global (it uses module exports instead),
37+
// so we provide a no-op stub to allow test files to load without throwing.
38+
// Tests that actually need addEventListener functionality should be marked as omitted.
39+
globalThis.addEventListener = (): void => {};
40+
3241
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access -- We're just exposing enough stuff for the tests to pass; it's not a perfect match
3342
globalThis.Window = Object.getPrototypeOf(globalThis).constructor;
3443

0 commit comments

Comments
 (0)