custom-common.js
This file
Path
test/verbose/custom-common.js
49 lines · 2.5 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–2why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 3–9why, one step back3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {nestedSubprocess} from '../helpers/nested.js';6import {QUOTE, getCommandLine, testTimestamp} from '../helpers/verbose.js';78setFixtureDirectory();9TweaksSindre Sorhusbefore adoption698a1b8
line 10why, one step back10const testCustomReturn = async (verboseOutput, expectedOutput) => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 11–15why, one step back11 const {stderr} = await nestedSubprocess(12 'empty.js',13 {optionsFixture: 'custom-return.js', optionsInput: {verboseOutput}},14 {stripFinalNewline: false},15 );TweaksSindre Sorhusbefore adoption698a1b8
line 16why, one step back16 assert.equal(stderr, expectedOutput);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 17–18why, one step back17};18TweaksSindre Sorhusbefore adoption698a1b8
lines 19–28why, one step back19test('"verbose" returning a string prints it', () => testCustomReturn(`${foobarString}\n`, `${foobarString}\n`));20test('"verbose" returning a string without a newline adds it', () => testCustomReturn(foobarString, `${foobarString}\n`));21test('"verbose" returning a string with multiple newlines keeps them', () => testCustomReturn(`${foobarString}\n\n`, `${foobarString}\n\n`));22test('"verbose" returning an empty string prints an empty line', () => testCustomReturn('', '\n'));23test('"verbose" returning undefined ignores it', () => testCustomReturn(undefined, ''));24test('"verbose" returning a number ignores it', () => testCustomReturn(0, ''));25test('"verbose" returning a bigint ignores it', () => testCustomReturn(0n, ''));26test('"verbose" returning a boolean ignores it', () => testCustomReturn(true, ''));27test('"verbose" returning an object ignores it', () => testCustomReturn({}, ''));28test('"verbose" returning an array ignores it', () => testCustomReturn([], ''));Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 29why, one step back29TweaksSindre Sorhusbefore adoption698a1b8
line 30why, one step back30test('"verbose" receives verboseLine string as first argument', async () => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 31why, one step back31 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {optionsFixture: 'custom-uppercase.js'});TweaksSindre Sorhusbefore adoption698a1b8
line 32why, one step back32 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ NOOP.js ${foobarString}`);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 33–34why, one step back33});34TweaksSindre Sorhusbefore adoption698a1b8
line 35why, one step back35test('"verbose" can print as JSON', async () => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 36–37why, one step back36 const {stderr} = await nestedSubprocess('noop.js', ['. .'], {optionsFixture: 'custom-json.js', type: 'duration', reject: false});37 const {type, message, escapedCommand, commandId, timestamp, piped, result, options} = JSON.parse(stderr);TweaksSindre Sorhusbefore adoption698a1b8
lines 38–48why, one step back38 assert.equal(type, 'duration');39 assert.ok(message.includes('done in'));40 assert.equal(escapedCommand, `noop.js ${QUOTE}. .${QUOTE}`);41 assert.equal(commandId, '0');42 assert.ok(Number.isInteger(new Date(timestamp).getTime()));43 assert.equal(piped, false);44 assert.equal(result.failed, false);45 assert.equal(result.exitCode, 0);46 assert.equal(result.stdout, '. .');47 assert.equal(result.stderr, '');48 assert.equal(options.reject, false);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 49why, one step back49});