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 fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
100% test coverage (#1018)ehmickybefore adoption9f65b86
line 1why, one step back1import {on} from 'node:events';TweaksSindre Sorhusbefore adoption698a1b8
lines 2–3why, one step back2import assert from 'node:assert/strict';3import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 4–5why, one step back4import {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 back6import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 7why, one step back7import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';TweaksSindre Sorhusbefore adoption698a1b8
lines 8–9why, one step back8import {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 back1011setFixtureDirectory();12TweaksSindre Sorhusbefore adoption698a1b8
line 13why, one step back13test('Prints stdout one line at a time', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 14why, one step back14 const subprocess = nestedInstance('noop-progressive.js', [foobarString], {verbose: 'full'});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 15why, one step back15TweaksSindre Sorhusbefore adoption698a1b8
line 16why, one step back16 let outputLine;100% test coverage (#1018)ehmickybefore adoption9f65b86
line 17why, one step back17 for await (const chunk of on(subprocess.stderr, 'data')) {TweaksSindre Sorhusbefore adoption698a1b8
line 18why, one step back18 outputLine = getOutputLine(chunk.toString().trim());100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 19–23why, one step back19 if (outputLine !== undefined) {20 break;21 }22 }23TweaksSindre Sorhusbefore adoption698a1b8
line 24why, one step back24 assert.equal(outputLine, `${testTimestamp} [0] ${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 25–27why, one step back25 await subprocess;26});27TweaksSindre Sorhusbefore adoption698a1b8
line 28why, one step back28test('Prints stdout progressively, interleaved', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 29why, one step back29 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 back30Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
lines 31–32why, one step back31 let isFirstSubprocessPrinted = false;32 let isSecondSubprocessPrinted = false;100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 33–39why, one step back33 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 back40 assert.equal(outputLine, `${testTimestamp} [0] ${foobarString}`);Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 41why, one step back41 isFirstSubprocessPrinted ||= true;100% test coverage (#1018)ehmickybefore adoption9f65b86
line 42why, one step back42 } else {TweaksSindre Sorhusbefore adoption698a1b8
line 43why, one step back43 assert.equal(outputLine, `${testTimestamp} [1] ${foobarString.toUpperCase()}`);Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 44why, one step back44 isSecondSubprocessPrinted ||= true;100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 45–46why, one step back45 }46Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 47why, one step back47 if (isFirstSubprocessPrinted && isSecondSubprocessPrinted) {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 48–52why, one step back48 break;49 }50 }5152 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
line 53why, one step back53 await assertRejects(subprocess);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 54–55why, one step back54});55TweaksSindre Sorhusbefore adoption698a1b8
line 56why, one step back56const testInterleaved = async (expectedLines, isSync) => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 57why, one step back57 const {stderr} = await nestedSubprocess('noop-132.js', {verbose: 'full', isSync});TweaksSindre Sorhusbefore adoption698a1b8
line 58why, one step back58 assert.deepEqual(getOutputLines(stderr), expectedLines.map(line => `${testTimestamp} [0] ${line}`));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 59–60why, one step back59};60TweaksSindre Sorhusbefore adoption698a1b8
lines 61–64why, one step back61test('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 */