Skip to content
Myr

output-progressive.js

This file

Path

test/verbose/output-progressive.js

64 lines · 2.3 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.

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 1why, one step back
1import {on} from 'node:events';

TweaksSindre Sorhusbefore adoption698a1b8

lines 2–3why, one step back
2import assert from 'node:assert/strict';
3import test from 'node:test';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–5why, one step back
4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';
5import {foobarString} from '../helpers/input.js';

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 6why, one step back
6import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 7why, one step back
7import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';

TweaksSindre Sorhusbefore adoption698a1b8

lines 8–9why, one step back
8import {assertRejects} from '../helpers/assert.js';
9/* eslint-disable node-test/no-conditional-assertion -- shared helper functions are called from conditional paths on purpose */

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 10–12why, one step back
10
11setFixtureDirectory();12

TweaksSindre Sorhusbefore adoption698a1b8

line 13why, one step back
13test('Prints stdout one line at a time', async () => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 14why, one step back
14 const subprocess = nestedInstance('noop-progressive.js', [foobarString], {verbose: 'full'});

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 15why, one step back
15

TweaksSindre Sorhusbefore adoption698a1b8

line 16why, one step back
16 let outputLine;

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 17why, one step back
17 for await (const chunk of on(subprocess.stderr, 'data')) {

TweaksSindre Sorhusbefore adoption698a1b8

line 18why, one step back
18 outputLine = getOutputLine(chunk.toString().trim());

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 19–23why, one step back
19 if (outputLine !== undefined) {
20 break;21 }22 }23

TweaksSindre Sorhusbefore adoption698a1b8

line 24why, one step back
24 assert.equal(outputLine, `${testTimestamp} [0] ${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 25–27why, one step back
25 await subprocess;
26});27

TweaksSindre Sorhusbefore adoption698a1b8

line 28why, one step back
28test('Prints stdout progressively, interleaved', async () => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 29why, one step back
29 const subprocess = nestedInstance('noop-repeat.js', ['1', `${foobarString}\n`], {parentFixture: 'nested-double.js', verbose: 'full'});

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 30why, one step back
30

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

lines 31–32why, one step back
31 let isFirstSubprocessPrinted = false;
32 let isSecondSubprocessPrinted = false;

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 33–39why, one step back
33 for await (const chunk of on(subprocess.stderr, 'data')) {
34 const outputLine = getOutputLine(chunk.toString().trim());35 if (outputLine === undefined) {36 continue;37 }3839 if (outputLine.includes(foobarString)) {

TweaksSindre Sorhusbefore adoption698a1b8

line 40why, one step back
40 assert.equal(outputLine, `${testTimestamp} [0] ${foobarString}`);

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 41why, one step back
41 isFirstSubprocessPrinted ||= true;

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 42why, one step back
42 } else {

TweaksSindre Sorhusbefore adoption698a1b8

line 43why, one step back
43 assert.equal(outputLine, `${testTimestamp} [1] ${foobarString.toUpperCase()}`);

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 44why, one step back
44 isSecondSubprocessPrinted ||= true;

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 45–46why, one step back
45 }
46

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 47why, one step back
47 if (isFirstSubprocessPrinted && isSecondSubprocessPrinted) {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 48–52why, one step back
48 break;
49 }50 }5152 subprocess.kill();

TweaksSindre Sorhusbefore adoption698a1b8

line 53why, one step back
53 await assertRejects(subprocess);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 54–55why, one step back
54});
55

TweaksSindre Sorhusbefore adoption698a1b8

line 56why, one step back
56const testInterleaved = async (expectedLines, isSync) => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 57why, one step back
57 const {stderr} = await nestedSubprocess('noop-132.js', {verbose: 'full', isSync});

TweaksSindre Sorhusbefore adoption698a1b8

line 58why, one step back
58 assert.deepEqual(getOutputLines(stderr), expectedLines.map(line => `${testTimestamp} [0] ${line}`));

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 61–64why, one step back
61test('Prints stdout + stderr interleaved', () => testInterleaved([1, 2, 3], false));
62test('Prints stdout + stderr not interleaved, sync', () => testInterleaved([1, 3, 2], true));6364/* eslint-enable node-test/no-conditional-assertion */