Skip to content

Commit 0bf8a8b

Browse files
committed
WPT harness: add step_timeout
1 parent fc4d8d5 commit 0bf8a8b

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/wpt/harness/harness.ts

+29-16
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,11 @@ class Test {
186186
* value when calling ``func``. Defaults to the :js:class:`Test` object.
187187
*/
188188
public step_func(func: UnknownFunc, this_obj?: object): UnknownFunc {
189-
const test_this = this;
190-
191189
if (arguments.length === 1) {
192190
this_obj = this;
193191
}
194192

195-
return function (...params: unknown[]) {
196-
return test_this.step.call(test_this, func, this_obj, ...params);
197-
};
193+
return (...params: unknown[]) => this.step(func, this_obj, ...params);
198194
}
199195

200196
/**
@@ -210,18 +206,16 @@ class Test {
210206
* value when calling `func`. Defaults to the :js:class:`Test` object.
211207
*/
212208
public step_func_done(func?: UnknownFunc, this_obj?: object): UnknownFunc {
213-
const test_this = this;
214-
215209
if (arguments.length === 1) {
216-
this_obj = test_this;
210+
this_obj = this;
217211
}
218212

219-
return function (...params: unknown[]) {
213+
return (...params: unknown[]) => {
220214
if (func) {
221-
test_this.step.call(test_this, func, this_obj, ...params);
215+
this.step(func, this_obj, ...params);
222216
}
223217

224-
test_this.done();
218+
this.done();
225219
};
226220
}
227221

@@ -257,12 +251,8 @@ class Test {
257251
timeout: number,
258252
...rest: unknown[]
259253
): ReturnType<typeof setTimeout> {
260-
const test_this = this;
261-
262254
return setTimeout(
263-
this.step_func(function () {
264-
return func.call(test_this, ...rest);
265-
}),
255+
this.step_func(() => func(...rest)),
266256
timeout
267257
);
268258
}
@@ -439,6 +429,13 @@ declare global {
439429
properties?: unknown
440430
): void;
441431
function async_test(func: TestFn, name: string, properties?: unknown): void;
432+
433+
function step_timeout(
434+
func: UnknownFunc,
435+
timeout: number,
436+
...rest: unknown[]
437+
): ReturnType<typeof setTimeout>;
438+
442439
function assert_equals(a: unknown, b: unknown, message?: string): void;
443440
function assert_not_equals(a: unknown, b: unknown, message?: string): void;
444441
function assert_true(val: unknown, message?: string): void;
@@ -737,6 +734,22 @@ globalThis.test = (func, name, properties): void => {
737734
}
738735
};
739736

737+
/**
738+
* Global version of :js:func:`Test.step_timeout` for use in single page tests.
739+
*
740+
* @param func - Function to run after the timeout
741+
* @param timeout - Time in ms to wait before running the
742+
* test step. The actual wait time is ``timeout`` x
743+
* ``timeout_multiplier``.
744+
*/
745+
globalThis.step_timeout = (
746+
func: UnknownFunc,
747+
timeout: number,
748+
...rest: unknown[]
749+
): ReturnType<typeof setTimeout> => {
750+
return setTimeout(() => func(...rest), timeout);
751+
};
752+
740753
globalThis.assert_equals = (a, b, message): void => {
741754
strictEqual(a, b, message);
742755
};

0 commit comments

Comments
 (0)