Skip to content
Myr

lines-mixed.js

This file

Path

test/stdio/lines-mixed.js

61 lines · 2.6 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 2why, one step back
2import {Writable} from 'node:stream';

TweaksSindre Sorhusbefore adoption698a1b8

line 3why, one step back
3import test from 'node:test';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–14why, one step back
4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';
5import {assertStreamOutput, assertStreamDataEvents, assertIterableChunks} from '../helpers/convert.js';6import {7 simpleFull,8 simpleLines,9 noNewlinesChunks,10 getSimpleChunkSubprocessAsync,11} from '../helpers/lines.js';1213setFixtureDirectory();14

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15const testAsyncIteration = async (expectedLines, stripFinalNewline) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 16why, one step back
16 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});

TweaksSindre Sorhusbefore adoption698a1b8

lines 17–18why, one step back
17 assert.equal(subprocess.stdout.readableObjectMode, false);
18 await assertStreamOutput(subprocess.stdout, simpleFull);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 19why, one step back
19 const {stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 20why, one step back
20 assert.deepEqual(stdout, expectedLines);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 21–22why, one step back
21};
22

TweaksSindre Sorhusbefore adoption698a1b8

lines 23–24why, one step back
23test('"lines: true" works with stream async iteration', () => testAsyncIteration(simpleLines, false));
24test('"lines: true" works with stream async iteration, stripFinalNewline', () => testAsyncIteration(noNewlinesChunks, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 25why, one step back
25

TweaksSindre Sorhusbefore adoption698a1b8

line 26why, one step back
26const testDataEvents = async (expectedLines, stripFinalNewline) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 27why, one step back
27 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});

TweaksSindre Sorhusbefore adoption698a1b8

line 28why, one step back
28 await assertStreamDataEvents(subprocess.stdout, simpleFull);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 29why, one step back
29 const {stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 30why, one step back
30 assert.deepEqual(stdout, expectedLines);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 31–32why, one step back
31};
32

TweaksSindre Sorhusbefore adoption698a1b8

lines 33–34why, one step back
33test('"lines: true" works with stream "data" events', () => testDataEvents(simpleLines, false));
34test('"lines: true" works with stream "data" events, stripFinalNewline', () => testDataEvents(noNewlinesChunks, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 35why, one step back
35

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36const testWritableStream = async (expectedLines, stripFinalNewline) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 37–45why, one step back
37 let output = '';
38 const writable = new Writable({39 write(line, encoding, done) {40 output += line.toString();41 done();42 },43 decodeStrings: false,44 });45 const {stdout} = await getSimpleChunkSubprocessAsync({stripFinalNewline, stdout: ['pipe', writable]});

TweaksSindre Sorhusbefore adoption698a1b8

lines 46–47why, one step back
46 assert.deepEqual(output, simpleFull);
47 assert.deepEqual(stdout, expectedLines);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 48–49why, one step back
48};
49

TweaksSindre Sorhusbefore adoption698a1b8

lines 50–51why, one step back
50test('"lines: true" works with writable streams targets', () => testWritableStream(simpleLines, false));
51test('"lines: true" works with writable streams targets, stripFinalNewline', () => testWritableStream(noNewlinesChunks, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 52why, one step back
52

TweaksSindre Sorhusbefore adoption698a1b8

line 53why, one step back
53const testIterable = async (expectedLines, stripFinalNewline) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 54why, one step back
54 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});

TweaksSindre Sorhusbefore adoption698a1b8

line 55why, one step back
55 await assertIterableChunks(subprocess, noNewlinesChunks);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 56why, one step back
56 const {stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 57why, one step back
57 assert.deepEqual(stdout, expectedLines);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 58–59why, one step back
58};
59

TweaksSindre Sorhusbefore adoption698a1b8

lines 60–61why, one step back
60test('"lines: true" works with subprocess.iterable()', () => testIterable(simpleLines, false));
61test('"lines: true" works with subprocess.iterable(), stripFinalNewline', () => testIterable(noNewlinesChunks, true));