(sync)
| 24 | runTests(true); |
| 25 | |
| 26 | function runTests(sync) { |
| 27 | { |
| 28 | // A single buffer write must end up in the file. |
| 29 | const dest = getTempFile(); |
| 30 | const stream = new Utf8Stream({ dest, sync, contentMode: 'buffer' }); |
| 31 | |
| 32 | stream.on('ready', common.mustCall(() => { |
| 33 | assert.ok(stream.write(Buffer.from('hello world\n'))); |
| 34 | stream.end(); |
| 35 | |
| 36 | stream.on('finish', common.mustCall(() => { |
| 37 | readFile(dest, 'utf8', common.mustSucceed((data) => { |
| 38 | assert.strictEqual(data, 'hello world\n'); |
| 39 | })); |
| 40 | })); |
| 41 | })); |
| 42 | } |
| 43 | |
| 44 | { |
| 45 | // Writes that exceed maxWrite start a new batch; data must survive |
| 46 | // the batch boundary and be written in order. |
| 47 | const dest = getTempFile(); |
| 48 | const stream = new Utf8Stream({ |
| 49 | dest, |
| 50 | sync, |
| 51 | contentMode: 'buffer', |
| 52 | minLength: 60, |
| 53 | maxWrite: 64, |
| 54 | }); |
| 55 | |
| 56 | stream.on('ready', common.mustCall(() => { |
| 57 | stream.write(Buffer.from('a'.repeat(40))); |
| 58 | stream.write(Buffer.from('b'.repeat(40))); |
| 59 | stream.write(Buffer.from('c'.repeat(40))); |
| 60 | stream.end(); |
| 61 | |
| 62 | stream.on('finish', common.mustCall(() => { |
| 63 | readFile(dest, 'utf8', common.mustSucceed((data) => { |
| 64 | assert.strictEqual( |
| 65 | data, |
| 66 | 'a'.repeat(40) + 'b'.repeat(40) + 'c'.repeat(40), |
| 67 | ); |
| 68 | })); |
| 69 | })); |
| 70 | })); |
| 71 | } |
| 72 | } |
no test coverage detected
searching dependent graphs…