complete.js
This file
Path
test/verbose/complete.js
131 lines · 8.2 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132import assert from 'node:assert/strict';import {stripVTControlCharacters} from 'node:util';import test from 'node:test';import {setFixtureDirectory} from '../helpers/fixtures-directory.js';import {foobarString} from '../helpers/input.js';import {nestedSubprocess} from '../helpers/nested.js';import { runErrorSubprocess, runWarningSubprocess, runEarlyErrorSubprocess, getCompletionLine, getCompletionLines, testTimestamp, getVerboseOption, getStdioForFd3Option, stdoutNoneOption, stdoutShortOption, stdoutFullOption, stderrNoneOption, stderrShortOption, stderrFullOption, fd3NoneOption, fd3ShortOption, fd3FullOption, ipcNoneOption, ipcShortOption, ipcFullOption,} from '../helpers/verbose.js';
setFixtureDirectory();
const testPrintCompletion = async (verbose, isSync) => { const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, ...getStdioForFd3Option(verbose), isSync}); assert.equal(getCompletionLine(stderr), `${testTimestamp} [0] √ (done in 0ms)`);};
test('Prints completion, verbose "short"', () => testPrintCompletion('short', false));test('Prints completion, verbose "full"', () => testPrintCompletion('full', false));test('Prints completion, verbose "short", fd-specific stdout', () => testPrintCompletion(stdoutShortOption, false));test('Prints completion, verbose "full", fd-specific stdout', () => testPrintCompletion(stdoutFullOption, false));test('Prints completion, verbose "short", fd-specific stderr', () => testPrintCompletion(stderrShortOption, false));test('Prints completion, verbose "full", fd-specific stderr', () => testPrintCompletion(stderrFullOption, false));test('Prints completion, verbose "short", fd-specific fd3', () => testPrintCompletion(fd3ShortOption, false));test('Prints completion, verbose "full", fd-specific fd3', () => testPrintCompletion(fd3FullOption, false));test('Prints completion, verbose "short", fd-specific ipc', () => testPrintCompletion(ipcShortOption, false));test('Prints completion, verbose "full", fd-specific ipc', () => testPrintCompletion(ipcFullOption, false));test('Prints completion, verbose "short", sync', () => testPrintCompletion('short', true));test('Prints completion, verbose "full", sync', () => testPrintCompletion('full', true));test('Prints completion, verbose "short", fd-specific stdout, sync', () => testPrintCompletion(stdoutShortOption, true));test('Prints completion, verbose "full", fd-specific stdout, sync', () => testPrintCompletion(stdoutFullOption, true));test('Prints completion, verbose "short", fd-specific stderr, sync', () => testPrintCompletion(stderrShortOption, true));test('Prints completion, verbose "full", fd-specific stderr, sync', () => testPrintCompletion(stderrFullOption, true));test('Prints completion, verbose "short", fd-specific fd3, sync', () => testPrintCompletion(fd3ShortOption, true));test('Prints completion, verbose "full", fd-specific fd3, sync', () => testPrintCompletion(fd3FullOption, true));test('Prints completion, verbose "short", fd-specific ipc, sync', () => testPrintCompletion(ipcShortOption, true));test('Prints completion, verbose "full", fd-specific ipc, sync', () => testPrintCompletion(ipcFullOption, true));
const testNoPrintCompletion = async (verbose, isSync) => { const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, ...getStdioForFd3Option(verbose), isSync}); assert.equal(stderr, '');};
test('Does not print completion, verbose "none"', () => testNoPrintCompletion('none', false));test('Does not print completion, verbose default', () => testNoPrintCompletion(undefined, false));test('Does not print completion, verbose "none", fd-specific stdout', () => testNoPrintCompletion(stdoutNoneOption, false));test('Does not print completion, verbose "none", fd-specific stderr', () => testNoPrintCompletion(stderrNoneOption, false));test('Does not print completion, verbose "none", fd-specific fd3', () => testNoPrintCompletion(fd3NoneOption, false));test('Does not print completion, verbose "none", fd-specific ipc', () => testNoPrintCompletion(ipcNoneOption, false));test('Does not print completion, verbose default, fd-specific', () => testNoPrintCompletion({}, false));test('Does not print completion, verbose "none", sync', () => testNoPrintCompletion('none', true));test('Does not print completion, verbose default, sync', () => testNoPrintCompletion(undefined, true));test('Does not print completion, verbose "none", fd-specific stdout, sync', () => testNoPrintCompletion(stdoutNoneOption, true));test('Does not print completion, verbose "none", fd-specific stderr, sync', () => testNoPrintCompletion(stderrNoneOption, true));test('Does not print completion, verbose "none", fd-specific fd3, sync', () => testNoPrintCompletion(fd3NoneOption, true));test('Does not print completion, verbose "none", fd-specific ipc, sync', () => testNoPrintCompletion(ipcNoneOption, true));test('Does not print completion, verbose default, fd-specific, sync', () => testNoPrintCompletion({}, true));
const testPrintCompletionError = async isSync => { const stderr = await runErrorSubprocess('short', isSync); assert.equal(getCompletionLine(stderr), `${testTimestamp} [0] × (done in 0ms)`);};
test('Prints completion after errors', () => testPrintCompletionError(false));test('Prints completion after errors, sync', () => testPrintCompletionError(true));
const testPrintCompletionWarning = async isSync => { const stderr = await runWarningSubprocess(isSync); assert.equal(getCompletionLine(stderr), `${testTimestamp} [0] ‼ (done in 0ms)`);};
test('Prints completion after errors, "reject" false', () => testPrintCompletionWarning(false));test('Prints completion after errors, "reject" false, sync', () => testPrintCompletionWarning(true));
const testPrintCompletionEarly = async isSync => { const stderr = await runEarlyErrorSubprocess(isSync); assert.equal(getCompletionLine(stderr), undefined);};
test('Prints completion after early validation errors', () => testPrintCompletionEarly(false));test('Prints completion after early validation errors, sync', () => testPrintCompletionEarly(true));
test('Prints duration', async () => { const {stderr} = await nestedSubprocess('delay.js', ['1000'], {verbose: 'short'}); assert.match(stripVTControlCharacters(stderr).split('\n').at(-1), /\(done in [\d.]+s\)/);});
const testPipeDuration = async (parentFixture, sourceVerbose, destinationVerbose) => { const {stderr} = await nestedSubprocess('noop.js', [foobarString], { parentFixture, sourceOptions: getVerboseOption(sourceVerbose), destinationFile: 'stdin.js', destinationOptions: getVerboseOption(destinationVerbose), });
const lines = getCompletionLines(stderr); assert.equal(lines.includes(`${testTimestamp} [0] √ (done in 0ms)`), sourceVerbose || destinationVerbose); assert.equal(lines.includes(`${testTimestamp} [1] √ (done in 0ms)`), sourceVerbose && destinationVerbose);};
test('Prints both durations piped with .pipe("file")', () => testPipeDuration('nested-pipe-file.js', true, true));test('Prints both durations piped with .pipe`command`', () => testPipeDuration('nested-pipe-script.js', true, true));test('Prints both durations piped with .pipe(subprocess)', () => testPipeDuration('nested-pipe-subprocesses.js', true, true));test('Prints first duration piped with .pipe("file")', () => testPipeDuration('nested-pipe-file.js', true, false));test('Prints first duration piped with .pipe`command`', () => testPipeDuration('nested-pipe-script.js', true, false));test('Prints first duration piped with .pipe(subprocess)', () => testPipeDuration('nested-pipe-subprocesses.js', true, false));test('Prints second duration piped with .pipe("file")', () => testPipeDuration('nested-pipe-file.js', false, true));test('Prints second duration piped with .pipe`command`', () => testPipeDuration('nested-pipe-script.js', false, true));test('Prints second duration piped with .pipe(subprocess)', () => testPipeDuration('nested-pipe-subprocesses.js', false, true));test('Prints neither durations piped with .pipe("file")', () => testPipeDuration('nested-pipe-file.js', false, false));test('Prints neither durations piped with .pipe`command`', () => testPipeDuration('nested-pipe-script.js', false, false));test('Prints neither durations piped with .pipe(subprocess)', () => testPipeDuration('nested-pipe-subprocesses.js', false, false));