Skip to content

Commit be61793

Browse files
Nahee-Parktargos
authored andcommitted
test: update wpt test for streams
PR-URL: #54129 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 350e699 commit be61793

File tree

7 files changed

+107
-38
lines changed

7 files changed

+107
-38
lines changed

test/fixtures/wpt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Last update:
2727
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
2828
- resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing
2929
- resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources
30-
- streams: https://github.com/web-platform-tests/wpt/tree/9b03282a99/streams
30+
- streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams
3131
- url: https://github.com/web-platform-tests/wpt/tree/6a39784534/url
3232
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
3333
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi

test/fixtures/wpt/streams/piping/abort.any.js

+40
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,46 @@ for (const reason of [null, undefined, error1]) {
183183
}, `(reason: '${reason}') all pending writes should complete on abort`);
184184
}
185185

186+
for (const reason of [null, undefined, error1]) {
187+
promise_test(async t => {
188+
let rejectPull;
189+
const pullPromise = new Promise((_, reject) => {
190+
rejectPull = reject;
191+
});
192+
let rejectCancel;
193+
const cancelPromise = new Promise((_, reject) => {
194+
rejectCancel = reject;
195+
});
196+
const rs = recordingReadableStream({
197+
async pull() {
198+
await Promise.race([
199+
pullPromise,
200+
cancelPromise,
201+
]);
202+
},
203+
cancel(reason) {
204+
rejectCancel(reason);
205+
},
206+
});
207+
const ws = new WritableStream();
208+
const abortController = new AbortController();
209+
const signal = abortController.signal;
210+
const pipeToPromise = rs.pipeTo(ws, { signal });
211+
pipeToPromise.catch(() => {}); // Prevent unhandled rejection.
212+
await delay(0);
213+
abortController.abort(reason);
214+
rejectPull('should not catch pull rejection');
215+
await delay(0);
216+
assert_equals(rs.eventsWithoutPulls.length, 2, 'cancel should have been called');
217+
assert_equals(rs.eventsWithoutPulls[0], 'cancel', 'first event should be cancel');
218+
if (reason !== undefined) {
219+
await promise_rejects_exactly(t, reason, pipeToPromise, 'pipeTo rejects with abort reason');
220+
} else {
221+
await promise_rejects_dom(t, 'AbortError', pipeToPromise, 'pipeTo rejects with AbortError');
222+
}
223+
}, `(reason: '${reason}') underlyingSource.cancel() should called when abort, even with pending pull`);
224+
}
225+
186226
promise_test(t => {
187227
const rs = new ReadableStream({
188228
pull(controller) {

test/fixtures/wpt/streams/piping/detached-context-crash.html

-21
This file was deleted.

test/fixtures/wpt/streams/readable-streams/cancel.any.js

+25
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,28 @@ promise_test(() => {
234234
return Promise.all([rs.cancel(), rs.getReader().closed]);
235235

236236
}, 'ReadableStream cancellation: cancelling before start finishes should prevent pull() from being called');
237+
238+
promise_test(async () => {
239+
240+
const events = [];
241+
242+
const pendingPromise = new Promise(() => {});
243+
244+
const rs = new ReadableStream({
245+
pull() {
246+
events.push('pull');
247+
return pendingPromise;
248+
},
249+
cancel() {
250+
events.push('cancel');
251+
}
252+
});
253+
254+
const reader = rs.getReader();
255+
reader.read().catch(() => {}); // No await.
256+
await delay(0);
257+
await Promise.all([reader.cancel(), reader.closed]);
258+
259+
assert_array_equals(events, ['pull', 'cancel'], 'cancel should have been called');
260+
261+
}, 'ReadableStream cancellation: underlyingSource.cancel() should called, even with pending pull');

test/fixtures/wpt/streams/readable-streams/from.any.js

+30-12
Original file line numberDiff line numberDiff line change
@@ -51,44 +51,50 @@ const iterableFactories = [
5151

5252
['a sync iterable of values', () => {
5353
const chunks = ['a', 'b'];
54-
const it = {
54+
const iterator = {
5555
next() {
5656
return {
5757
done: chunks.length === 0,
5858
value: chunks.shift()
5959
};
60-
},
61-
[Symbol.iterator]: () => it
60+
}
61+
};
62+
const iterable = {
63+
[Symbol.iterator]: () => iterator
6264
};
63-
return it;
65+
return iterable;
6466
}],
6567

6668
['a sync iterable of promises', () => {
6769
const chunks = ['a', 'b'];
68-
const it = {
70+
const iterator = {
6971
next() {
7072
return chunks.length === 0 ? { done: true } : {
7173
done: false,
7274
value: Promise.resolve(chunks.shift())
7375
};
74-
},
75-
[Symbol.iterator]: () => it
76+
}
77+
};
78+
const iterable = {
79+
[Symbol.iterator]: () => iterator
7680
};
77-
return it;
81+
return iterable;
7882
}],
7983

8084
['an async iterable', () => {
8185
const chunks = ['a', 'b'];
82-
const it = {
86+
const asyncIterator = {
8387
next() {
8488
return Promise.resolve({
8589
done: chunks.length === 0,
8690
value: chunks.shift()
8791
})
88-
},
89-
[Symbol.asyncIterator]: () => it
92+
}
93+
};
94+
const asyncIterable = {
95+
[Symbol.asyncIterator]: () => asyncIterator
9096
};
91-
return it;
97+
return asyncIterable;
9298
}],
9399

94100
['a ReadableStream', () => {
@@ -186,6 +192,18 @@ test(t => {
186192
assert_throws_exactly(theError, () => ReadableStream.from(iterable), 'from() should re-throw the error');
187193
}, `ReadableStream.from ignores @@iterator if @@asyncIterator exists`);
188194

195+
test(() => {
196+
const theError = new Error('a unique string');
197+
const iterable = {
198+
[Symbol.asyncIterator]: null,
199+
[Symbol.iterator]() {
200+
throw theError
201+
}
202+
};
203+
204+
assert_throws_exactly(theError, () => ReadableStream.from(iterable), 'from() should re-throw the error');
205+
}, `ReadableStream.from ignores a null @@asyncIterator`);
206+
189207
promise_test(async () => {
190208

191209
const iterable = {

test/fixtures/wpt/versions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"path": "resources"
6969
},
7070
"streams": {
71-
"commit": "9b03282a99ef2314c1c2d5050a105a74a2940019",
71+
"commit": "2bd26e124cf17b2f0a25c150794d640b07b2a870",
7272
"path": "streams"
7373
},
7474
"url": {

test/wpt/status/streams.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
"readable-streams/cross-realm-crash.window.js": {
1717
"skip": "Browser-specific test"
1818
},
19+
"readable-streams/from.any.js": {
20+
"fail": {
21+
"expected": [
22+
"ReadableStream.from ignores a null @@asyncIterator"
23+
]
24+
}
25+
},
1926
"readable-streams/owning-type-message-port.any.js": {
2027
"fail": {
2128
"note": "Readable streams with type owning are not yet supported",
@@ -40,6 +47,9 @@
4047
]
4148
}
4249
},
50+
"readable-streams/read-task-handling.window.js": {
51+
"skip": "Browser-specific test"
52+
},
4353
"transferable/deserialize-error.window.js": {
4454
"skip": "Browser-specific test"
4555
},
@@ -56,8 +66,5 @@
5666
},
5767
"transform-streams/invalid-realm.tentative.window.js": {
5868
"skip": "Browser-specific test"
59-
},
60-
"readable-streams/read-task-handling.window.js": {
61-
"skip": "Browser-specific test"
6269
}
6370
}

0 commit comments

Comments
 (0)