Skip to content
Myr

verbose.js

This file

Path

test/helpers/verbose.js

105 lines · 4.5 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

lines 2–5why, one step back
2import {platform} from 'node:process';
3import {stripVTControlCharacters} from 'node:util';4import {replaceSymbols} from 'figures';5import {foobarString} from './input.js';

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

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

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

line 7why, one step back
7import {fullStdio} from './stdio.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 8–11why, one step back
8
9const isWindows = platform === 'win32';10export const QUOTE = isWindows ? '"' : '\'';11

TweaksSindre Sorhusbefore adoption698a1b8

line 12why, one step back
12export const runErrorSubprocess = async (verbose, isSync = false, options = {}) => {

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

lines 13–14why, one step back
13 const {expectExitCode = true, ...subprocessOptions} = options;
14 const {stderr, nestedResult} = await nestedSubprocess('noop-fail.js', ['1', foobarString], {verbose, isSync, ...subprocessOptions});

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15 assert.ok(nestedResult instanceof Error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 16why, one step back
16 if (expectExitCode) {

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17 assert.ok(stderr.includes('exit code 2'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 18–22why, one step back
18 }
1920 return stderr;21};22

TweaksSindre Sorhusbefore adoption698a1b8

line 23why, one step back
23export const runWarningSubprocess = async isSync => {

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

line 24why, one step back
24 const {stderr, nestedResult} = await nestedSubprocess('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false, isSync});

TweaksSindre Sorhusbefore adoption698a1b8

lines 25–26why, one step back
25 assert.ok(nestedResult instanceof Error);
26 assert.ok(stderr.includes('exit code 2'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 27–29why, one step back
27 return stderr;
28};29

TweaksSindre Sorhusbefore adoption698a1b8

line 30why, one step back
30export const runEarlyErrorSubprocess = async isSync => {

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

line 31why, one step back
31 const {stderr, nestedResult} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short', cwd: true, isSync});

TweaksSindre Sorhusbefore adoption698a1b8

lines 32–33why, one step back
32 assert.ok(nestedResult instanceof Error);
33 assert.ok(nestedResult.message.startsWith('The "cwd" option must'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 34–36why, one step back
34 return stderr;
35};36

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 37–49why, one step back
37export const runVerboseSubprocess = ({
38 isSync = false,39 type,40 eventProperty,41 optionName,42 errorMessage,43 fdNumber,44 secondFdNumber,45 optionsFixture = 'custom-event.js',46 output = '. .',47 ...options48}) => nestedSubprocess('noop-verbose.js', [output], {49 ipc: !isSync,

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

line 50why, one step back
50 ...getStdioForFd3Option(fdNumber, secondFdNumber),

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 51–62why, one step back
51 optionsFixture,
52 optionsInput: {53 type,54 eventProperty,55 optionName,56 errorMessage,57 fdNumber,58 secondFdNumber,59 },60 isSync,61 ...options,62});

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

lines 63–66why, one step back
63
64export const getStdioForFd3Option = (...values) => values.some(value => hasFd3Option(value)) ? fullStdio : {};6566const hasFd3Option = value => value === 'fd3' || (typeof value === 'object' && value !== null && Object.hasOwn(value, 'fd3'));

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 67why, one step back
67

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 68–73why, one step back
68export const getCommandLine = stderr => getCommandLines(stderr)[0];
69export const getCommandLines = stderr => getNormalizedLines(stderr).filter(line => isCommandLine(line));70const isCommandLine = line => line.includes(' $ ') || line.includes(' | ');71export const getOutputLine = stderr => getOutputLines(stderr)[0];72export const getOutputLines = stderr => getNormalizedLines(stderr).filter(line => isOutputLine(line));73const isOutputLine = line => line.includes('] ');

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 74–76why, one step back
74export const getIpcLine = stderr => getIpcLines(stderr)[0];
75export const getIpcLines = stderr => getNormalizedLines(stderr).filter(line => isIpcLine(line));76const isIpcLine = line => line.includes(' * ');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 77–82why, one step back
77export const getErrorLine = stderr => getErrorLines(stderr)[0];
78export const getErrorLines = stderr => getNormalizedLines(stderr).filter(line => isErrorLine(line));79const isErrorLine = line => (line.includes(' × ') || line.includes(' ‼ ')) && !isCompletionLine(line);80export const getCompletionLine = stderr => getCompletionLines(stderr)[0];81export const getCompletionLines = stderr => getNormalizedLines(stderr).filter(line => isCompletionLine(line));82const isCompletionLine = line => line.includes('(done in');

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 83why, one step back
83export const getNormalizedLine = stderr => getNormalizedLines(stderr)[0];

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 84–88why, one step back
84export const getNormalizedLines = stderr => splitLines(normalizeStderr(stderr));
85const splitLines = stderr => stderr.split('\n');8687const normalizeStderr = stderr => replaceSymbols(normalizeDuration(normalizeTimestamp(stripVTControlCharacters(stderr))), {useFallback: true});88export const testTimestamp = '[00:00:00.000]';

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

line 89why, one step back
89const normalizeTimestamp = stderr => stderr.replaceAll(/^\[\d{2}:\d{2}:\d{2}.\d{3}\]/gm, () => testTimestamp);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 90–93why, one step back
90const normalizeDuration = stderr => stderr.replaceAll(/\(done in [^)]+\)/g, '(done in 0ms)');
9192export const getVerboseOption = (isVerbose, verbose = 'short') => ({verbose: isVerbose ? verbose : 'none'});93

Add more tests for the `verbose` option (#1127)ehmickybefore adoption37e0024

lines 94–102why, one step back
94export const stdoutNoneOption = {stdout: 'none'};
95export const stdoutShortOption = {stdout: 'short'};96export const stdoutFullOption = {stdout: 'full'};97export const stderrNoneOption = {stderr: 'none'};98export const stderrShortOption = {stderr: 'short'};99export const stderrFullOption = {stderr: 'full'};100export const fd3NoneOption = {fd3: 'none'};101export const fd3ShortOption = {fd3: 'short'};102export const fd3FullOption = {fd3: 'full'};

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 103–105why, one step back
103export const ipcNoneOption = {ipc: 'none'};
104export const ipcShortOption = {ipc: 'short'};105export const ipcFullOption = {ipc: 'full'};