Skip to content

Commit 572a70f

Browse files
joyeecheungMylesBorins
authored andcommitted
test: pull html/webappapis/microtask-queuing WPT
With the command: ``` git node wpt html/webappapis/microtask-queuing ``` PR-URL: #25616 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent c59edca commit 572a70f

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

test/fixtures/wpt/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Last update:
1515
- url: https://github.com/web-platform-tests/wpt/tree/75b0f336c5/url
1616
- resources: https://github.com/web-platform-tests/wpt/tree/679a364421/resources
1717
- interfaces: https://github.com/web-platform-tests/wpt/tree/712c9f275e/interfaces
18+
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing
1819

1920
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
2021
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// META: global=window,worker
2+
"use strict";
3+
4+
setup({
5+
allow_uncaught_exception: true
6+
});
7+
8+
async_test(t => {
9+
const error = new Error("boo");
10+
self.addEventListener("error", t.step_func_done(ev => {
11+
assert_equals(ev.error, error);
12+
}));
13+
14+
queueMicrotask(() => { throw error; });
15+
}, "It rethrows exceptions");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// META: global=window,worker
2+
"use strict";
3+
4+
test(() => {
5+
assert_equals(typeof queueMicrotask, "function");
6+
}, "It exists and is a function");
7+
8+
test(() => {
9+
assert_throws(new TypeError(), () => queueMicrotask(), "no argument");
10+
assert_throws(new TypeError(), () => queueMicrotask(undefined), "undefined");
11+
assert_throws(new TypeError(), () => queueMicrotask(null), "null");
12+
assert_throws(new TypeError(), () => queueMicrotask(0), "0");
13+
assert_throws(new TypeError(), () => queueMicrotask({ handleEvent() { } }), "an event handler object");
14+
assert_throws(new TypeError(), () => queueMicrotask("window.x = 5;"), "a string");
15+
}, "It throws when given non-functions");
16+
17+
async_test(t => {
18+
let called = false;
19+
queueMicrotask(t.step_func_done(() => {
20+
called = true;
21+
}));
22+
assert_false(called);
23+
}, "It calls the callback asynchronously");
24+
25+
async_test(t => {
26+
queueMicrotask(t.step_func_done(function () { // note: intentionally not an arrow function
27+
assert_array_equals(arguments, []);
28+
}), "x", "y");
29+
}, "It does not pass any arguments");
30+
31+
async_test(t => {
32+
const happenings = [];
33+
Promise.resolve().then(() => happenings.push("a"));
34+
queueMicrotask(() => happenings.push("b"));
35+
Promise.reject().catch(() => happenings.push("c"));
36+
queueMicrotask(t.step_func_done(() => {
37+
assert_array_equals(happenings, ["a", "b", "c"]);
38+
}));
39+
}, "It interleaves with promises as expected");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use strict";
2+
3+
// This does not work as you expect because mutation observer compound microtasks are confusing.
4+
// Basically you can only use it once per test.
5+
function queueMicrotaskViaMO(cb) {
6+
const observer = new MutationObserver(cb);
7+
const node = document.createTextNode("");
8+
observer.observe(node, { characterData: true });
9+
node.data = "foo";
10+
}
11+
12+
// Need to use promise_test to get sequential ordering; otherwise the global mutation observer
13+
// compound microtask business screws us over.
14+
15+
promise_test(() => {
16+
return new Promise(resolve => {
17+
const happenings = [];
18+
19+
queueMicrotaskViaMO(() => happenings.push("x"));
20+
queueMicrotask(() => happenings.push("a"));
21+
22+
queueMicrotask(() => {
23+
assert_array_equals(happenings, ["x", "a"]);
24+
resolve();
25+
});
26+
});
27+
}, "It interleaves with MutationObservers as expected");
28+
29+
promise_test(() => {
30+
return new Promise(resolve => {
31+
const happenings = [];
32+
33+
queueMicrotask(() => happenings.push("a"));
34+
Promise.reject().catch(() => happenings.push("x"));
35+
queueMicrotaskViaMO(() => happenings.push(1));
36+
Promise.resolve().then(() => happenings.push("y"));
37+
queueMicrotask(() => happenings.push("b"));
38+
queueMicrotask(() => happenings.push("c"));
39+
40+
queueMicrotask(() => {
41+
assert_array_equals(happenings, ["a", "x", 1, "y", "b", "c"]);
42+
resolve();
43+
});
44+
});
45+
}, "It interleaves with MutationObservers and promises together as expected");

test/fixtures/wpt/versions.json

+4
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@
1818
"interfaces": {
1919
"commit": "712c9f275e83997884749dbcaa503f12c0ff5bba",
2020
"path": "interfaces"
21+
},
22+
"html/webappapis/microtask-queuing": {
23+
"commit": "0c3bed38df6d9dcd1441873728fb5c1bb59c92df",
24+
"path": "html/webappapis/microtask-queuing"
2125
}
2226
}

0 commit comments

Comments
 (0)