|
1 | 1 | // Flags: --experimental-stream-iter |
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | | -// Edge case tests for pipeToSync: endSync fallback, preventFail. |
| 4 | +// Edge case tests for pipeToSync close and failure behavior. |
5 | 5 |
|
6 | 6 | const common = require('../common'); |
7 | 7 | const assert = require('assert'); |
8 | 8 | const { pipeToSync, fromSync } = require('stream/iter'); |
9 | 9 |
|
10 | | -// pipeToSync endSync returns negative → falls back to end() |
11 | | -async function testPipeToSyncEndSyncFallback() { |
| 10 | +// pipeToSync cannot complete when endSync() requires async fallback. |
| 11 | +async function testPipeToSyncEndSyncFailure() { |
12 | 12 | let endCalled = false; |
13 | 13 | const writer = { |
14 | 14 | writeSync() { return true; }, |
15 | | - endSync() { return -1; }, // Negative → triggers end() fallback |
| 15 | + endSync() { return -1; }, |
16 | 16 | end() { endCalled = true; }, |
17 | 17 | }; |
18 | | - pipeToSync(fromSync('data'), writer); |
19 | | - assert.strictEqual(endCalled, true); |
| 18 | + assert.throws( |
| 19 | + () => pipeToSync(fromSync('data'), writer, { preventFail: true }), |
| 20 | + { code: 'ERR_INVALID_STATE' }, |
| 21 | + ); |
| 22 | + assert.strictEqual(endCalled, false); |
20 | 23 | } |
21 | 24 |
|
22 | | -// pipeToSync endSync missing → falls back to end() |
| 25 | +// pipeToSync requires endSync() when closing is enabled. |
23 | 26 | async function testPipeToSyncNoEndSync() { |
| 27 | + let writeCalled = false; |
24 | 28 | let endCalled = false; |
25 | 29 | const writer = { |
26 | | - writeSync() { return true; }, |
| 30 | + writeSync() { writeCalled = true; return true; }, |
27 | 31 | end() { endCalled = true; }, |
28 | 32 | }; |
29 | | - pipeToSync(fromSync('data'), writer); |
30 | | - assert.strictEqual(endCalled, true); |
| 33 | + assert.throws( |
| 34 | + () => pipeToSync(fromSync('data'), writer), |
| 35 | + { code: 'ERR_INVALID_ARG_TYPE' }, |
| 36 | + ); |
| 37 | + assert.strictEqual(writeCalled, false); |
| 38 | + assert.strictEqual(endCalled, false); |
31 | 39 | } |
32 | 40 |
|
33 | 41 | // pipeToSync with preventFail: true — source error does NOT call fail() |
@@ -61,7 +69,7 @@ async function testPipeToSyncPreventClose() { |
61 | 69 | } |
62 | 70 |
|
63 | 71 | Promise.all([ |
64 | | - testPipeToSyncEndSyncFallback(), |
| 72 | + testPipeToSyncEndSyncFailure(), |
65 | 73 | testPipeToSyncNoEndSync(), |
66 | 74 | testPipeToSyncPreventFail(), |
67 | 75 | testPipeToSyncPreventClose(), |
|
0 commit comments