mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
test: pull html/webappapis/microtask-queuing WPT
With the command: ``` git node wpt html/webappapis/microtask-queuing ``` PR-URL: https://github.com/nodejs/node/pull/25616 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host>
This commit is contained in:
5 files changed
+104
No files matched your search
Vendored
+1
@@ -15,6 +15,7 @@ Last update:
|
||||
- url: https://github.com/web-platform-tests/wpt/tree/75b0f336c5/url
|
||||
- resources: https://github.com/web-platform-tests/wpt/tree/679a364421/resources
|
||||
- interfaces: https://github.com/web-platform-tests/wpt/tree/712c9f275e/interfaces
|
||||
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing
|
||||
|
||||
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
|
||||
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// META: global=window,worker
|
||||
"use strict";
|
||||
|
||||
setup({
|
||||
allow_uncaught_exception: true
|
||||
});
|
||||
|
||||
async_test(t => {
|
||||
const error = new Error("boo");
|
||||
self.addEventListener("error", t.step_func_done(ev => {
|
||||
assert_equals(ev.error, error);
|
||||
}));
|
||||
|
||||
queueMicrotask(() => { throw error; });
|
||||
}, "It rethrows exceptions");
|
||||
@@ -0,0 +1,39 @@
|
||||
// META: global=window,worker
|
||||
"use strict";
|
||||
|
||||
test(() => {
|
||||
assert_equals(typeof queueMicrotask, "function");
|
||||
}, "It exists and is a function");
|
||||
|
||||
test(() => {
|
||||
assert_throws(new TypeError(), () => queueMicrotask(), "no argument");
|
||||
assert_throws(new TypeError(), () => queueMicrotask(undefined), "undefined");
|
||||
assert_throws(new TypeError(), () => queueMicrotask(null), "null");
|
||||
assert_throws(new TypeError(), () => queueMicrotask(0), "0");
|
||||
assert_throws(new TypeError(), () => queueMicrotask({ handleEvent() { } }), "an event handler object");
|
||||
assert_throws(new TypeError(), () => queueMicrotask("window.x = 5;"), "a string");
|
||||
}, "It throws when given non-functions");
|
||||
|
||||
async_test(t => {
|
||||
let called = false;
|
||||
queueMicrotask(t.step_func_done(() => {
|
||||
called = true;
|
||||
}));
|
||||
assert_false(called);
|
||||
}, "It calls the callback asynchronously");
|
||||
|
||||
async_test(t => {
|
||||
queueMicrotask(t.step_func_done(function () { // note: intentionally not an arrow function
|
||||
assert_array_equals(arguments, []);
|
||||
}), "x", "y");
|
||||
}, "It does not pass any arguments");
|
||||
|
||||
async_test(t => {
|
||||
const happenings = [];
|
||||
Promise.resolve().then(() => happenings.push("a"));
|
||||
queueMicrotask(() => happenings.push("b"));
|
||||
Promise.reject().catch(() => happenings.push("c"));
|
||||
queueMicrotask(t.step_func_done(() => {
|
||||
assert_array_equals(happenings, ["a", "b", "c"]);
|
||||
}));
|
||||
}, "It interleaves with promises as expected");
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
// This does not work as you expect because mutation observer compound microtasks are confusing.
|
||||
// Basically you can only use it once per test.
|
||||
function queueMicrotaskViaMO(cb) {
|
||||
const observer = new MutationObserver(cb);
|
||||
const node = document.createTextNode("");
|
||||
observer.observe(node, { characterData: true });
|
||||
node.data = "foo";
|
||||
}
|
||||
|
||||
// Need to use promise_test to get sequential ordering; otherwise the global mutation observer
|
||||
// compound microtask business screws us over.
|
||||
|
||||
promise_test(() => {
|
||||
return new Promise(resolve => {
|
||||
const happenings = [];
|
||||
|
||||
queueMicrotaskViaMO(() => happenings.push("x"));
|
||||
queueMicrotask(() => happenings.push("a"));
|
||||
|
||||
queueMicrotask(() => {
|
||||
assert_array_equals(happenings, ["x", "a"]);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}, "It interleaves with MutationObservers as expected");
|
||||
|
||||
promise_test(() => {
|
||||
return new Promise(resolve => {
|
||||
const happenings = [];
|
||||
|
||||
queueMicrotask(() => happenings.push("a"));
|
||||
Promise.reject().catch(() => happenings.push("x"));
|
||||
queueMicrotaskViaMO(() => happenings.push(1));
|
||||
Promise.resolve().then(() => happenings.push("y"));
|
||||
queueMicrotask(() => happenings.push("b"));
|
||||
queueMicrotask(() => happenings.push("c"));
|
||||
|
||||
queueMicrotask(() => {
|
||||
assert_array_equals(happenings, ["a", "x", 1, "y", "b", "c"]);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}, "It interleaves with MutationObservers and promises together as expected");
|
||||
Vendored
+4
@@ -18,5 +18,9 @@
|
||||
"interfaces": {
|
||||
"commit": "712c9f275e83997884749dbcaa503f12c0ff5bba",
|
||||
"path": "interfaces"
|
||||
},
|
||||
"html/webappapis/microtask-queuing": {
|
||||
"commit": "0c3bed38df6d9dcd1441873728fb5c1bb59c92df",
|
||||
"path": "html/webappapis/microtask-queuing"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user