test: update wpt test for streams

PR-URL: https://github.com/nodejs/node/pull/54129
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
devstone authored and Michaël Zasso committed 2024-10-02 07:57:26 +02:00
1 parent d30145f663
commit c8587ec90d
7 files changed
+107 -38

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ Last update:
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
- resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing
- resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources
- streams: https://github.com/web-platform-tests/wpt/tree/9b03282a99/streams
- streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams
- url: https://github.com/web-platform-tests/wpt/tree/6a39784534/url
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
+40
View File
@@ -183,6 +183,46 @@ for (const reason of [null, undefined, error1]) {
}, `(reason: '${reason}') all pending writes should complete on abort`);
}
for (const reason of [null, undefined, error1]) {
promise_test(async t => {
let rejectPull;
const pullPromise = new Promise((_, reject) => {
rejectPull = reject;
});
let rejectCancel;
const cancelPromise = new Promise((_, reject) => {
rejectCancel = reject;
});
const rs = recordingReadableStream({
async pull() {
await Promise.race([
pullPromise,
cancelPromise,
]);
},
cancel(reason) {
rejectCancel(reason);
},
});
const ws = new WritableStream();
const abortController = new AbortController();
const signal = abortController.signal;
const pipeToPromise = rs.pipeTo(ws, { signal });
pipeToPromise.catch(() => {}); // Prevent unhandled rejection.
await delay(0);
abortController.abort(reason);
rejectPull('should not catch pull rejection');
await delay(0);
assert_equals(rs.eventsWithoutPulls.length, 2, 'cancel should have been called');
assert_equals(rs.eventsWithoutPulls[0], 'cancel', 'first event should be cancel');
if (reason !== undefined) {
await promise_rejects_exactly(t, reason, pipeToPromise, 'pipeTo rejects with abort reason');
} else {
await promise_rejects_dom(t, 'AbortError', pipeToPromise, 'pipeTo rejects with AbortError');
}
}, `(reason: '${reason}') underlyingSource.cancel() should called when abort, even with pending pull`);
}
promise_test(t => {
const rs = new ReadableStream({
pull(controller) {
@@ -1,21 +0,0 @@
<!DOCTYPE html>
<body>
<script>
window.onload = () => {
const i = document.createElement("iframe");
i.src = "about:blank";
document.body.appendChild(i);
const rs = new i.contentWindow.ReadableStream({
start(controller) { controller.error(); }
});
const ws = new i.contentWindow.WritableStream();
i.remove();
// pipeTo() should not crash with a ReadableStream or WritableStream from
// a detached iframe.
rs.pipeTo(ws);
};
</script>
</body>
@@ -234,3 +234,28 @@ promise_test(() => {
return Promise.all([rs.cancel(), rs.getReader().closed]);
}, 'ReadableStream cancellation: cancelling before start finishes should prevent pull() from being called');
promise_test(async () => {
const events = [];
const pendingPromise = new Promise(() => {});
const rs = new ReadableStream({
pull() {
events.push('pull');
return pendingPromise;
},
cancel() {
events.push('cancel');
}
});
const reader = rs.getReader();
reader.read().catch(() => {}); // No await.
await delay(0);
await Promise.all([reader.cancel(), reader.closed]);
assert_array_equals(events, ['pull', 'cancel'], 'cancel should have been called');
}, 'ReadableStream cancellation: underlyingSource.cancel() should called, even with pending pull');
+30 -12
View File
@@ -51,44 +51,50 @@ const iterableFactories = [
['a sync iterable of values', () => {
const chunks = ['a', 'b'];
const it = {
const iterator = {
next() {
return {
done: chunks.length === 0,
value: chunks.shift()
};
},
[Symbol.iterator]: () => it
}
};
return it;
const iterable = {
[Symbol.iterator]: () => iterator
};
return iterable;
}],
['a sync iterable of promises', () => {
const chunks = ['a', 'b'];
const it = {
const iterator = {
next() {
return chunks.length === 0 ? { done: true } : {
done: false,
value: Promise.resolve(chunks.shift())
};
},
[Symbol.iterator]: () => it
}
};
return it;
const iterable = {
[Symbol.iterator]: () => iterator
};
return iterable;
}],
['an async iterable', () => {
const chunks = ['a', 'b'];
const it = {
const asyncIterator = {
next() {
return Promise.resolve({
done: chunks.length === 0,
value: chunks.shift()
})
},
[Symbol.asyncIterator]: () => it
}
};
return it;
const asyncIterable = {
[Symbol.asyncIterator]: () => asyncIterator
};
return asyncIterable;
}],
['a ReadableStream', () => {
@@ -186,6 +192,18 @@ test(t => {
assert_throws_exactly(theError, () => ReadableStream.from(iterable), 'from() should re-throw the error');
}, `ReadableStream.from ignores @@iterator if @@asyncIterator exists`);
test(() => {
const theError = new Error('a unique string');
const iterable = {
[Symbol.asyncIterator]: null,
[Symbol.iterator]() {
throw theError
}
};
assert_throws_exactly(theError, () => ReadableStream.from(iterable), 'from() should re-throw the error');
}, `ReadableStream.from ignores a null @@asyncIterator`);
promise_test(async () => {
const iterable = {
+1 -1
View File
@@ -64,7 +64,7 @@
"path": "resources"
},
"streams": {
"commit": "9b03282a99ef2314c1c2d5050a105a74a2940019",
"commit": "2bd26e124cf17b2f0a25c150794d640b07b2a870",
"path": "streams"
},
"url": {
+10 -3
View File
@@ -16,6 +16,13 @@
"readable-streams/cross-realm-crash.window.js": {
"skip": "Browser-specific test"
},
"readable-streams/from.any.js": {
"fail": {
"expected": [
"ReadableStream.from ignores a null @@asyncIterator"
]
}
},
"readable-streams/owning-type-message-port.any.js": {
"fail": {
"note": "Readable streams with type owning are not yet supported",
@@ -40,6 +47,9 @@
]
}
},
"readable-streams/read-task-handling.window.js": {
"skip": "Browser-specific test"
},
"transferable/deserialize-error.window.js": {
"skip": "Browser-specific test"
},
@@ -56,8 +66,5 @@
},
"transform-streams/invalid-realm.tentative.window.js": {
"skip": "Browser-specific test"
},
"readable-streams/read-task-handling.window.js": {
"skip": "Browser-specific test"
}
}