1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:17:34 +00:00

Tests/LibWeb: Add TransformStream flush callback test

This test proves the ability of TransformStream to execute
caller supplied code in the flush callback, and have access to
TransformStreamDefaultController.
This commit is contained in:
Kenneth Myhra 2023-07-14 07:47:05 +02:00 committed by Andreas Kling
parent 5c6125c92b
commit 221f18f72e
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,5 @@
Done: false
HELLO, WORLD!
Done: false
Enqueued in flush, this the last chunk that will be processed.
Done: true

View file

@ -0,0 +1,25 @@
<script src="../include.js"></script>
<script>
test(() => {
const {writable, readable} = new TransformStream({
transform(chunk, controller) {
controller.enqueue(chunk.toUpperCase());
},
flush(controller) {
controller.enqueue("Enqueued in flush, this the last chunk that will be processed.");
}
});
const writer = writable.getWriter();
writer.write("Hello, world!");
writer.close();
const reader = readable.getReader();
reader.read().then(function processText({done, value}) {
println(`Done: ${done}`);
if (done)
return;
println(value);
reader.read().then(processText);
});
});
</script>