Skip to content
File

Blob: src/workerd/api/tests/identity-transform-stream-state-machine-test.js

javascript28 lines
1// Copyright (c) 2025 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4import { strictEqual } from 'node:assert';
5 
6// TODO(cleanup): This is a copy of an existing test in streams-test. Once the autogate is remvoed,
7// this separate test can be deleted.
8export const test = {
9 async test() {
10 const its = new IdentityTransformStream();
11 const writer = its.writable.getWriter();
12 const input = new TextEncoder().encode('Hello, world!');
13 const writePromise = writer.write(input);
14 const closePromise = writer.close();
15 const reader = its.readable.getReader();
16 const { value, done } = await reader.read();
17 strictEqual(done, false);
18 strictEqual(value instanceof Uint8Array, true);
19 strictEqual(value.length, input.length);
20 for (let i = 0; i < input.length; i++) {
21 strictEqual(value[i], input[i]);
22 }
23 await Promise.all([writePromise, closePromise]);
24 const { done: doneAfterClose } = await reader.read();
25 strictEqual(doneAfterClose, true);
26 },
27};