Files
node/test/parallel/test-quic-stream-iteration-pull.mjs
Ethan Arrowood c3189d436e test: replace discard loops with dump()
Replaces the `for await (const _ of source) {}` discard idiom with
dump(), which says what it does and does not need an eslint-disable
for the unused loop variable. The eslint-disable directives and
comments that become redundant are removed with it.

Only files that already declare --experimental-stream-iter are
converted, so no test gains an experimental flag it did not already
opt into. Files still using the old idiom are left as they are;
converting them would change what those tests run under and belongs
in a separate discussion.

Loops that break early are left alone: those cancel the source rather
than reading it to completion, which is not what dump() does.

Assisted-by: Claude Opus 5
Signed-off-by: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: https://github.com/nodejs/node/pull/65598
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-10-07 20:01:31 +00:00

52 lines
1.5 KiB
JavaScript

// Flags: --experimental-quic --experimental-stream-iter --no-warnings
// Test: pull applies a transform to a QUIC stream.
// Verifies that pull() can process chunks from a QUIC stream through
// a synchronous transform function.
import { hasQuic, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import { dump } from 'node:stream/iter';
if (!hasQuic) {
skip('QUIC is not enabled');
}
const { listen, connect } = await import('../common/quic.mjs');
const { bytes, pull } = await import('stream/iter');
const encoder = new TextEncoder();
const message = 'pull test';
const expected = encoder.encode(message);
const serverDone = Promise.withResolvers();
const serverEndpoint = await listen(mustCall((serverSession) => {
serverSession.onstream = mustCall(async (stream) => {
// Use pull with an identity transform — pass chunks through.
const transformed = pull(stream, (chunk) => {
if (chunk === null) return null;
return chunk;
});
const result = await bytes(transformed);
assert.deepStrictEqual(result, expected);
stream.writer.endSync();
await stream.closed;
serverSession.close();
serverDone.resolve();
});
}));
const clientSession = await connect(serverEndpoint.address);
await clientSession.opened;
const stream = await clientSession.createBidirectionalStream({
body: encoder.encode(message),
});
await dump(stream);
await Promise.all([stream.closed, serverDone.promise]);
await clientSession.close();
await serverEndpoint.close();