Skip to content

Commit

Permalink
Add more tests for the verbose option (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 18, 2024
1 parent f9f1199 commit 37e0024
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 67 deletions.
19 changes: 9 additions & 10 deletions test/helpers/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ const normalizeDuration = stderr => stderr.replaceAll(/\(done in [^)]+\)/g, '(do

export const getVerboseOption = (isVerbose, verbose = 'short') => ({verbose: isVerbose ? verbose : 'none'});

export const fdNoneOption = {stdout: 'none', stderr: 'none'};
export const fdShortOption = {stdout: 'short', stderr: 'none'};
export const fdFullOption = {stdout: 'full', stderr: 'none'};
export const fdStdoutNoneOption = {stdout: 'none', stderr: 'full'};
export const fdStderrNoneOption = {stdout: 'full', stderr: 'none'};
export const fdStderrShortOption = {stdout: 'none', stderr: 'short'};
export const fdStderrFullOption = {stdout: 'none', stderr: 'full'};
export const fd3NoneOption = {stdout: 'full', fd3: 'none'};
export const fd3ShortOption = {stdout: 'none', fd3: 'short'};
export const fd3FullOption = {stdout: 'none', fd3: 'full'};
export const stdoutNoneOption = {stdout: 'none'};
export const stdoutShortOption = {stdout: 'short'};
export const stdoutFullOption = {stdout: 'full'};
export const stderrNoneOption = {stderr: 'none'};
export const stderrShortOption = {stderr: 'short'};
export const stderrFullOption = {stderr: 'full'};
export const fd3NoneOption = {fd3: 'none'};
export const fd3ShortOption = {fd3: 'short'};
export const fd3FullOption = {fd3: 'full'};
export const ipcNoneOption = {ipc: 'none'};
export const ipcShortOption = {ipc: 'short'};
export const ipcFullOption = {ipc: 'full'};
45 changes: 36 additions & 9 deletions test/verbose/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ import {
getCompletionLines,
testTimestamp,
getVerboseOption,
fdNoneOption,
fdShortOption,
fdFullOption,
stdoutNoneOption,
stdoutShortOption,
stdoutFullOption,
stderrNoneOption,
stderrShortOption,
stderrFullOption,
fd3NoneOption,
fd3ShortOption,
fd3FullOption,
ipcNoneOption,
ipcShortOption,
ipcFullOption,
} from '../helpers/verbose.js';

setFixtureDirectory();
Expand All @@ -29,12 +38,24 @@ const testPrintCompletion = async (t, verbose, execaMethod) => {

test('Prints completion, verbose "short"', testPrintCompletion, 'short', parentExecaAsync);
test('Prints completion, verbose "full"', testPrintCompletion, 'full', parentExecaAsync);
test('Prints completion, verbose "short", fd-specific', testPrintCompletion, fdShortOption, parentExecaAsync);
test('Prints completion, verbose "full", fd-specific', testPrintCompletion, fdFullOption, parentExecaAsync);
test('Prints completion, verbose "short", fd-specific stdout', testPrintCompletion, stdoutShortOption, parentExecaAsync);
test('Prints completion, verbose "full", fd-specific stdout', testPrintCompletion, stdoutFullOption, parentExecaAsync);
test('Prints completion, verbose "short", fd-specific stderr', testPrintCompletion, stderrShortOption, parentExecaAsync);
test('Prints completion, verbose "full", fd-specific stderr', testPrintCompletion, stderrFullOption, parentExecaAsync);
test('Prints completion, verbose "short", fd-specific fd3', testPrintCompletion, fd3ShortOption, parentExecaAsync);
test('Prints completion, verbose "full", fd-specific fd3', testPrintCompletion, fd3FullOption, parentExecaAsync);
test('Prints completion, verbose "short", fd-specific ipc', testPrintCompletion, ipcShortOption, parentExecaAsync);
test('Prints completion, verbose "full", fd-specific ipc', testPrintCompletion, ipcFullOption, parentExecaAsync);
test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', parentExecaSync);
test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', parentExecaSync);
test('Prints completion, verbose "short", fd-specific, sync', testPrintCompletion, fdShortOption, parentExecaSync);
test('Prints completion, verbose "full", fd-specific, sync', testPrintCompletion, fdFullOption, parentExecaSync);
test('Prints completion, verbose "short", fd-specific stdout, sync', testPrintCompletion, stdoutShortOption, parentExecaSync);
test('Prints completion, verbose "full", fd-specific stdout, sync', testPrintCompletion, stdoutFullOption, parentExecaSync);
test('Prints completion, verbose "short", fd-specific stderr, sync', testPrintCompletion, stderrShortOption, parentExecaSync);
test('Prints completion, verbose "full", fd-specific stderr, sync', testPrintCompletion, stderrFullOption, parentExecaSync);
test('Prints completion, verbose "short", fd-specific fd3, sync', testPrintCompletion, fd3ShortOption, parentExecaSync);
test('Prints completion, verbose "full", fd-specific fd3, sync', testPrintCompletion, fd3FullOption, parentExecaSync);
test('Prints completion, verbose "short", fd-specific ipc, sync', testPrintCompletion, ipcShortOption, parentExecaSync);
test('Prints completion, verbose "full", fd-specific ipc, sync', testPrintCompletion, ipcFullOption, parentExecaSync);

const testNoPrintCompletion = async (t, verbose, execaMethod) => {
const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});
Expand All @@ -43,11 +64,17 @@ const testNoPrintCompletion = async (t, verbose, execaMethod) => {

test('Does not print completion, verbose "none"', testNoPrintCompletion, 'none', parentExecaAsync);
test('Does not print completion, verbose default"', testNoPrintCompletion, undefined, parentExecaAsync);
test('Does not print completion, verbose "none", fd-specific', testNoPrintCompletion, fdNoneOption, parentExecaAsync);
test('Does not print completion, verbose "none", fd-specific stdout', testNoPrintCompletion, stdoutNoneOption, parentExecaAsync);
test('Does not print completion, verbose "none", fd-specific stderr', testNoPrintCompletion, stderrNoneOption, parentExecaAsync);
test('Does not print completion, verbose "none", fd-specific fd3', testNoPrintCompletion, fd3NoneOption, parentExecaAsync);
test('Does not print completion, verbose "none", fd-specific ipc', testNoPrintCompletion, ipcNoneOption, parentExecaAsync);
test('Does not print completion, verbose default", fd-specific', testNoPrintCompletion, {}, parentExecaAsync);
test('Does not print completion, verbose "none", sync', testNoPrintCompletion, 'none', parentExecaSync);
test('Does not print completion, verbose default", sync', testNoPrintCompletion, undefined, parentExecaSync);
test('Does not print completion, verbose "none", fd-specific, sync', testNoPrintCompletion, fdNoneOption, parentExecaSync);
test('Does not print completion, verbose "none", fd-specific stdout, sync', testNoPrintCompletion, stdoutNoneOption, parentExecaSync);
test('Does not print completion, verbose "none", fd-specific stderr, sync', testNoPrintCompletion, stderrNoneOption, parentExecaSync);
test('Does not print completion, verbose "none", fd-specific fd3, sync', testNoPrintCompletion, fd3NoneOption, parentExecaSync);
test('Does not print completion, verbose "none", fd-specific ipc, sync', testNoPrintCompletion, ipcNoneOption, parentExecaSync);
test('Does not print completion, verbose default", fd-specific, sync', testNoPrintCompletion, {}, parentExecaSync);

const testPrintCompletionError = async (t, execaMethod) => {
Expand Down
45 changes: 36 additions & 9 deletions test/verbose/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ import {
getErrorLines,
testTimestamp,
getVerboseOption,
fdNoneOption,
fdShortOption,
fdFullOption,
stdoutNoneOption,
stdoutShortOption,
stdoutFullOption,
stderrNoneOption,
stderrShortOption,
stderrFullOption,
fd3NoneOption,
fd3ShortOption,
fd3FullOption,
ipcNoneOption,
ipcShortOption,
ipcFullOption,
} from '../helpers/verbose.js';

setFixtureDirectory();
Expand All @@ -30,12 +39,24 @@ const testPrintError = async (t, verbose, execaMethod) => {

test('Prints error, verbose "short"', testPrintError, 'short', runErrorSubprocessAsync);
test('Prints error, verbose "full"', testPrintError, 'full', runErrorSubprocessAsync);
test('Prints error, verbose "short", fd-specific', testPrintError, fdShortOption, runErrorSubprocessAsync);
test('Prints error, verbose "full", fd-specific', testPrintError, fdFullOption, runErrorSubprocessAsync);
test('Prints error, verbose "short", fd-specific stdout', testPrintError, stdoutShortOption, runErrorSubprocessAsync);
test('Prints error, verbose "full", fd-specific stdout', testPrintError, stdoutFullOption, runErrorSubprocessAsync);
test('Prints error, verbose "short", fd-specific stderr', testPrintError, stderrShortOption, runErrorSubprocessAsync);
test('Prints error, verbose "full", fd-specific stderr', testPrintError, stderrFullOption, runErrorSubprocessAsync);
test('Prints error, verbose "short", fd-specific fd3', testPrintError, fd3ShortOption, runErrorSubprocessAsync);
test('Prints error, verbose "full", fd-specific fd3', testPrintError, fd3FullOption, runErrorSubprocessAsync);
test('Prints error, verbose "short", fd-specific ipc', testPrintError, ipcShortOption, runErrorSubprocessAsync);
test('Prints error, verbose "full", fd-specific ipc', testPrintError, ipcFullOption, runErrorSubprocessAsync);
test('Prints error, verbose "short", sync', testPrintError, 'short', runErrorSubprocessSync);
test('Prints error, verbose "full", sync', testPrintError, 'full', runErrorSubprocessSync);
test('Prints error, verbose "short", fd-specific, sync', testPrintError, fdShortOption, runErrorSubprocessSync);
test('Prints error, verbose "full", fd-specific, sync', testPrintError, fdFullOption, runErrorSubprocessSync);
test('Prints error, verbose "short", fd-specific stdout, sync', testPrintError, stdoutShortOption, runErrorSubprocessSync);
test('Prints error, verbose "full", fd-specific stdout, sync', testPrintError, stdoutFullOption, runErrorSubprocessSync);
test('Prints error, verbose "short", fd-specific stderr, sync', testPrintError, stderrShortOption, runErrorSubprocessSync);
test('Prints error, verbose "full", fd-specific stderr, sync', testPrintError, stderrFullOption, runErrorSubprocessSync);
test('Prints error, verbose "short", fd-specific fd3, sync', testPrintError, fd3ShortOption, runErrorSubprocessSync);
test('Prints error, verbose "full", fd-specific fd3, sync', testPrintError, fd3FullOption, runErrorSubprocessSync);
test('Prints error, verbose "short", fd-specific ipc, sync', testPrintError, ipcShortOption, runErrorSubprocessSync);
test('Prints error, verbose "full", fd-specific ipc, sync', testPrintError, ipcFullOption, runErrorSubprocessSync);

const testNoPrintError = async (t, verbose, execaMethod) => {
const stderr = await execaMethod(t, verbose, false);
Expand All @@ -44,11 +65,17 @@ const testNoPrintError = async (t, verbose, execaMethod) => {

test('Does not print error, verbose "none"', testNoPrintError, 'none', runErrorSubprocessAsync);
test('Does not print error, verbose default', testNoPrintError, undefined, runErrorSubprocessAsync);
test('Does not print error, verbose "none", fd-specific', testNoPrintError, fdNoneOption, runErrorSubprocessAsync);
test('Does not print error, verbose "none", fd-specific stdout', testNoPrintError, stdoutNoneOption, runErrorSubprocessAsync);
test('Does not print error, verbose "none", fd-specific stderr', testNoPrintError, stderrNoneOption, runErrorSubprocessAsync);
test('Does not print error, verbose "none", fd-specific fd3', testNoPrintError, fd3NoneOption, runErrorSubprocessAsync);
test('Does not print error, verbose "none", fd-specific ipc', testNoPrintError, ipcNoneOption, runErrorSubprocessAsync);
test('Does not print error, verbose default, fd-specific', testNoPrintError, {}, runErrorSubprocessAsync);
test('Does not print error, verbose "none", sync', testNoPrintError, 'none', runErrorSubprocessSync);
test('Does not print error, verbose default, sync', testNoPrintError, undefined, runErrorSubprocessSync);
test('Does not print error, verbose "none", fd-specific, sync', testNoPrintError, fdNoneOption, runErrorSubprocessSync);
test('Does not print error, verbose "none", fd-specific stdout, sync', testNoPrintError, stdoutNoneOption, runErrorSubprocessSync);
test('Does not print error, verbose "none", fd-specific stderr, sync', testNoPrintError, stderrNoneOption, runErrorSubprocessSync);
test('Does not print error, verbose "none", fd-specific fd3, sync', testNoPrintError, fd3NoneOption, runErrorSubprocessSync);
test('Does not print error, verbose "none", fd-specific ipc, sync', testNoPrintError, ipcNoneOption, runErrorSubprocessSync);
test('Does not print error, verbose default, fd-specific, sync', testNoPrintError, {}, runErrorSubprocessSync);

const testPrintNoError = async (t, execaMethod) => {
Expand Down
23 changes: 13 additions & 10 deletions test/verbose/output-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.
import {
getOutputLine,
testTimestamp,
fdFullOption,
fdStderrFullOption,
stdoutNoneOption,
stdoutFullOption,
stderrFullOption,
} from '../helpers/verbose.js';

setFixtureDirectory();
Expand All @@ -18,20 +19,22 @@ const testPrintOutputNoBuffer = async (t, verbose, buffer, execaMethod) => {

test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, parentExecaAsync);
test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaAsync);
test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, fdFullOption, false, parentExecaAsync);
test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, stdoutFullOption, false, parentExecaAsync);
test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, parentExecaSync);
test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaSync);
test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, fdFullOption, false, parentExecaSync);
test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, stdoutFullOption, false, parentExecaSync);

const testPrintOutputNoBufferFalse = async (t, buffer, execaMethod) => {
const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: fdStderrFullOption, buffer});
const testPrintOutputNoBufferFalse = async (t, verbose, buffer, execaMethod) => {
const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});
t.is(getOutputLine(stderr), undefined);
};

test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, false, parentExecaAsync);
test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaAsync);
test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, false, parentExecaSync);
test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaSync);
test('Does not print stdout, buffer: false, fd-specific none', testPrintOutputNoBufferFalse, stdoutNoneOption, false, parentExecaAsync);
test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, stderrFullOption, false, parentExecaAsync);
test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, parentExecaAsync);
test('Does not print stdout, buffer: false, fd-specific none, sync', testPrintOutputNoBufferFalse, stdoutNoneOption, false, parentExecaSync);
test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, stderrFullOption, false, parentExecaSync);
test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, parentExecaSync);

const testPrintOutputNoBufferTransform = async (t, buffer, isSync) => {
const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {
Expand Down
Loading

0 comments on commit 37e0024

Please sign in to comment.