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 <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host>
1 parent c59edca commit 572a70f

5 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎test/fixtures/wpt/README.md‎

Lines changed: 1 addition & 0 deletions
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
Lines changed: 15 additions & 0 deletions
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+
consterror=newError("boo");
10+
self.addEventListener("error",t.step_func_done(ev=>{
11+
assert_equals(ev.error,error);
12+
}));
13+
14+
queueMicrotask(()=>{throwerror;});
15+
},"It rethrows exceptions");
Lines changed: 39 additions & 0 deletions
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(typeofqueueMicrotask,"function");
6+
},"It exists and is a function");
7+
8+
test(()=>{
9+
assert_throws(newTypeError(),()=>queueMicrotask(),"no argument");
10+
assert_throws(newTypeError(),()=>queueMicrotask(undefined),"undefined");
11+
assert_throws(newTypeError(),()=>queueMicrotask(null),"null");
12+
assert_throws(newTypeError(),()=>queueMicrotask(0),"0");
13+
assert_throws(newTypeError(),()=>queueMicrotask({handleEvent(){}}),"an event handler object");
14+
assert_throws(newTypeError(),()=>queueMicrotask("window.x = 5;"),"a string");
15+
},"It throws when given non-functions");
16+
17+
async_test(t=>{
18+
letcalled=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+
consthappenings=[];
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");
Lines changed: 45 additions & 0 deletions
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+
functionqueueMicrotaskViaMO(cb){
6+
constobserver=newMutationObserver(cb);
7+
constnode=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+
returnnewPromise(resolve=>{
17+
consthappenings=[];
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+
returnnewPromise(resolve=>{
31+
consthappenings=[];
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‎

Lines changed: 4 additions & 0 deletions
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)