Skip to content
Myr

lines-main.js

This file

Path

test/stdio/lines-main.js

115 lines · 9.5 KiB · JavaScript

Last changed by

Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff

History of this file

Take it

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–3why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';3import {assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–21why, one step back
4import {execa, execaSync} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {fullStdio} from '../helpers/stdio.js';7import {getOutputsGenerator} from '../helpers/generator.js';8import {foobarString} from '../helpers/input.js';9import {10 simpleFull,11 simpleChunks,12 simpleFullEndChunks,13 simpleLines,14 simpleFullEndLines,15 noNewlinesChunks,16 getSimpleChunkSubprocessAsync,17} from '../helpers/lines.js';1819setFixtureDirectory();2021// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 22why, one step back
22const testStreamLines = async (fdNumber, input, expectedOutput, lines, stripFinalNewline, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 23why, one step back
23 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, input], {...fullStdio, lines, stripFinalNewline});

TweaksSindre Sorhusbefore adoption698a1b8

line 24why, one step back
24 assert.deepEqual(stdio[fdNumber], expectedOutput);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 25–26why, one step back
25};
26

TweaksSindre Sorhusbefore adoption698a1b8

lines 27–50why, one step back
27test('"lines: true" splits lines, stdout', () => testStreamLines(1, simpleFull, simpleLines, true, false, execa));
28test('"lines: true" splits lines, stdout, fd-specific', () => testStreamLines(1, simpleFull, simpleLines, {stdout: true}, false, execa));29test('"lines: true" splits lines, stderr', () => testStreamLines(2, simpleFull, simpleLines, true, false, execa));30test('"lines: true" splits lines, stderr, fd-specific', () => testStreamLines(2, simpleFull, simpleLines, {stderr: true}, false, execa));31test('"lines: true" splits lines, stdio[*]', () => testStreamLines(3, simpleFull, simpleLines, true, false, execa));32test('"lines: true" splits lines, stdio[*], fd-specific', () => testStreamLines(3, simpleFull, simpleLines, {fd3: true}, false, execa));33test('"lines: true" splits lines, stdout, stripFinalNewline', () => testStreamLines(1, simpleFull, noNewlinesChunks, true, true, execa));34test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific', () => testStreamLines(1, simpleFull, noNewlinesChunks, true, {stdout: true}, execa));35test('"lines: true" splits lines, stderr, stripFinalNewline', () => testStreamLines(2, simpleFull, noNewlinesChunks, true, true, execa));36test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific', () => testStreamLines(2, simpleFull, noNewlinesChunks, true, {stderr: true}, execa));37test('"lines: true" splits lines, stdio[*], stripFinalNewline', () => testStreamLines(3, simpleFull, noNewlinesChunks, true, true, execa));38test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific', () => testStreamLines(3, simpleFull, noNewlinesChunks, true, {fd3: true}, execa));39test('"lines: true" splits lines, stdout, sync', () => testStreamLines(1, simpleFull, simpleLines, true, false, execaSync));40test('"lines: true" splits lines, stdout, fd-specific, sync', () => testStreamLines(1, simpleFull, simpleLines, {stdout: true}, false, execaSync));41test('"lines: true" splits lines, stderr, sync', () => testStreamLines(2, simpleFull, simpleLines, true, false, execaSync));42test('"lines: true" splits lines, stderr, fd-specific, sync', () => testStreamLines(2, simpleFull, simpleLines, {stderr: true}, false, execaSync));43test('"lines: true" splits lines, stdio[*], sync', () => testStreamLines(3, simpleFull, simpleLines, true, false, execaSync));44test('"lines: true" splits lines, stdio[*], fd-specific, sync', () => testStreamLines(3, simpleFull, simpleLines, {fd3: true}, false, execaSync));45test('"lines: true" splits lines, stdout, stripFinalNewline, sync', () => testStreamLines(1, simpleFull, noNewlinesChunks, true, true, execaSync));46test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific, sync', () => testStreamLines(1, simpleFull, noNewlinesChunks, true, {stdout: true}, execaSync));47test('"lines: true" splits lines, stderr, stripFinalNewline, sync', () => testStreamLines(2, simpleFull, noNewlinesChunks, true, true, execaSync));48test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific, sync', () => testStreamLines(2, simpleFull, noNewlinesChunks, true, {stderr: true}, execaSync));49test('"lines: true" splits lines, stdio[*], stripFinalNewline, sync', () => testStreamLines(3, simpleFull, noNewlinesChunks, true, true, execaSync));50test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific, sync', () => testStreamLines(3, simpleFull, noNewlinesChunks, true, {fd3: true}, execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 51–57why, one step back
51
52const bigArray = Array.from({length: 1e5}).fill('.\n');53const bigString = bigArray.join('');54const bigStringNoNewlines = '.'.repeat(1e6);55const bigStringNoNewlinesEnd = `${bigStringNoNewlines}\n`;5657// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 58why, one step back
58const testStreamLinesGenerator = async (input, expectedLines, objectMode, binary, stripFinalNewline, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 59–63why, one step back
59 const {stdout} = await execaMethod('noop.js', {
60 stdout: getOutputsGenerator(input)(objectMode, binary),61 lines: true,62 stripFinalNewline,63 });

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 65–66why, one step back
65};
66

TweaksSindre Sorhusbefore adoption698a1b8

lines 67–86why, one step back
67test('"lines: true" works with strings generators', () => testStreamLinesGenerator(simpleChunks, simpleFullEndLines, false, false, false, execa));
68test('"lines: true" works with strings generators, binary', () => testStreamLinesGenerator(simpleChunks, simpleLines, false, true, false, execa));69test('"lines: true" works with big strings generators', () => testStreamLinesGenerator([bigString], bigArray, false, false, false, execa));70test('"lines: true" works with big strings generators without newlines', () => testStreamLinesGenerator([bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execa));71test('"lines: true" is a noop with strings generators, objectMode', () => testStreamLinesGenerator(simpleFullEndChunks, simpleFullEndChunks, true, false, false, execa));72test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode', () => testStreamLinesGenerator(simpleFullEndChunks, simpleFullEndChunks, true, false, true, execa));73test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode', () => testStreamLinesGenerator(simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execa));74test('"lines: true" is a noop with strings generators, binary, objectMode', () => testStreamLinesGenerator(simpleChunks, simpleChunks, true, true, false, execa));75test('"lines: true" is a noop big strings generators, objectMode', () => testStreamLinesGenerator([bigString], [bigString], true, false, false, execa));76test('"lines: true" is a noop big strings generators without newlines, objectMode', () => testStreamLinesGenerator([bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execa));77test('"lines: true" works with strings generators, sync', () => testStreamLinesGenerator(simpleChunks, simpleFullEndLines, false, false, false, execaSync));78test('"lines: true" works with strings generators, binary, sync', () => testStreamLinesGenerator(simpleChunks, simpleLines, false, true, false, execaSync));79test('"lines: true" works with big strings generators, sync', () => testStreamLinesGenerator([bigString], bigArray, false, false, false, execaSync));80test('"lines: true" works with big strings generators without newlines, sync', () => testStreamLinesGenerator([bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execaSync));81test('"lines: true" is a noop with strings generators, objectMode, sync', () => testStreamLinesGenerator(simpleFullEndChunks, simpleFullEndChunks, true, false, false, execaSync));82test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode, sync', () => testStreamLinesGenerator(simpleFullEndChunks, simpleFullEndChunks, true, false, true, execaSync));83test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode, sync', () => testStreamLinesGenerator(simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execaSync));84test('"lines: true" is a noop with strings generators, binary, objectMode, sync', () => testStreamLinesGenerator(simpleChunks, simpleChunks, true, true, false, execaSync));85test('"lines: true" is a noop big strings generators, objectMode, sync', () => testStreamLinesGenerator([bigString], [bigString], true, false, false, execaSync));86test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', () => testStreamLinesGenerator([bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 87why, one step back
87

TweaksSindre Sorhusbefore adoption698a1b8

line 88why, one step back
88test('"lines: true" stops on stream error', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 89why, one step back
89 const cause = new Error(foobarString);

TweaksSindre Sorhusbefore adoption698a1b8

line 90why, one step back
90 const error = await assertRejects(getSimpleChunkSubprocessAsync({

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 91–98why, one step back
91 * stdout(line) {
92 if (line === noNewlinesChunks[2]) {93 throw cause;94 }9596 yield line;97 },98 }));

TweaksSindre Sorhusbefore adoption698a1b8

lines 99–100why, one step back
99 assert.equal(error.cause, cause);
100 assert.deepEqual(error.stdout, noNewlinesChunks.slice(0, 2));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 101–102why, one step back
101});
102

TweaksSindre Sorhusbefore adoption698a1b8

line 103why, one step back
103test('"lines: true" stops on stream error event', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 104–106why, one step back
104 const cause = new Error(foobarString);
105 const subprocess = getSimpleChunkSubprocessAsync();106 subprocess.stdout.emit('error', cause);

TweaksSindre Sorhusbefore adoption698a1b8

lines 107–109why, one step back
107 const error = await assertRejects(subprocess);
108 assert.equal(error.cause, cause);109 assert.deepEqual(error.stdout, []);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 110why, one step back
110});

Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff

lines 111–115why, one step back
111
112test('"lines: true" keeps the trailing carriage return of an unterminated final line', () => testStreamLines(1, 'a\r\nb\r', ['a', 'b\r'], true, true, execa));113test('"lines: true" keeps the trailing carriage return of an unterminated final line, sync', () => testStreamLines(1, 'a\r\nb\r', ['a', 'b\r'], true, true, execaSync));114test('"lines: true" keeps newlines of an unterminated final line', () => testStreamLines(1, 'a\r\nb\r', ['a\r\n', 'b\r'], true, false, execa));115test('"lines: true" keeps newlines of an unterminated final line, sync', () => testStreamLines(1, 'a\r\nb\r', ['a\r\n', 'b\r'], true, false, execaSync));