custom-result.js
This file
Path
test/verbose/custom-result.js
78 lines · 4.3 KiB · JavaScript
Last changed by
Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff
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–4why, one step back3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {runVerboseSubprocess} from '../helpers/verbose.js';TweaksSindre Sorhusbefore adoption698a1b8
line 5why, one step back5import {assertLike} from '../helpers/assert.js';Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 6–14why, one step back6import {7 earlyErrorOptions,8 earlyErrorOptionsSync,9 expectedEarlyError,10 expectedEarlyErrorSync,11} from '../helpers/early-error.js';1213setFixtureDirectory();14TweaksSindre Sorhusbefore adoption698a1b8
line 15why, one step back15const testVerboseResultEnd = async (type, isSync) => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 16–21why, one step back16 const {stderr: parentStderr} = await runVerboseSubprocess({17 isSync,18 type,19 optionsFixture: 'custom-result.js',20 });21 const {failed, exitCode, stdout, stderr, ipcOutput, durationMs} = JSON.parse(parentStderr);TweaksSindre Sorhusbefore adoption698a1b8
lines 22–27why, one step back22 assert.equal(failed, true);23 assert.equal(exitCode, 2);24 assert.equal(stdout, '. .');25 assert.equal(stderr, '');26 assert.equal(typeof durationMs, 'number');27 assert.deepEqual(ipcOutput, isSync ? [] : ['. .']);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 28–29why, one step back28};29TweaksSindre Sorhusbefore adoption698a1b8
lines 30–33why, one step back30test('"verbose" function receives verboseObject.result, "error"', () => testVerboseResultEnd('error', false));31test('"verbose" function receives verboseObject.result, "duration"', () => testVerboseResultEnd('duration', false));32test('"verbose" function receives verboseObject.result, "error", sync', () => testVerboseResultEnd('error', true));33test('"verbose" function receives verboseObject.result, "duration", sync', () => testVerboseResultEnd('duration', true));Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 34why, one step back34TweaksSindre Sorhusbefore adoption698a1b8
line 35why, one step back35const testVerboseResultEndSpawn = async (type, options, expectedOutput, isSync) => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 36–43why, one step back36 const {stderr: parentStderr} = await runVerboseSubprocess({37 isSync,38 type,39 optionsFixture: 'custom-result.js',40 ...options,41 });42 const lastLine = parentStderr.split('\n').at(-1);43 const result = JSON.parse(lastLine);TweaksSindre Sorhusbefore adoption698a1b8
lines 44–46why, one step back44 assertLike(result, expectedOutput);45 assert.equal(result.failed, true);46 assert.equal(result.exitCode, undefined);Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff
lines 47–49why, one step back47 // The subprocess never spawned, so its output is empty48 assert.equal(result.stdout, '');49 assert.equal(result.stderr, '');TweaksSindre Sorhusbefore adoption698a1b8
lines 50–51why, one step back50 assert.equal(typeof result.durationMs, 'number');51 assert.deepEqual(result.ipcOutput, []);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 52–53why, one step back52};53TweaksSindre Sorhusbefore adoption698a1b8
lines 54–57why, one step back54test('"verbose" function receives verboseObject.result, "error", spawn error', () => testVerboseResultEndSpawn('error', earlyErrorOptions, expectedEarlyError, false));55test('"verbose" function receives verboseObject.result, "duration", spawn error', () => testVerboseResultEndSpawn('duration', earlyErrorOptions, expectedEarlyError, false));56test('"verbose" function receives verboseObject.result, "error", spawn error, sync', () => testVerboseResultEndSpawn('error', earlyErrorOptionsSync, expectedEarlyErrorSync, true));57test('"verbose" function receives verboseObject.result, "duration", spawn error, sync', () => testVerboseResultEndSpawn('duration', earlyErrorOptionsSync, expectedEarlyErrorSync, true));Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 58why, one step back58TweaksSindre Sorhusbefore adoption698a1b8
line 59why, one step back59const testVerboseResultStart = async (type, options, isSync) => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 60–65why, one step back60 const {stderr: parentStderr} = await runVerboseSubprocess({61 isSync,62 type,63 optionsFixture: 'custom-result.js',64 ...options,65 });TweaksSindre Sorhusbefore adoption698a1b8
line 66why, one step back66 assert.equal(parentStderr, '');Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 67–68why, one step back67};68TweaksSindre Sorhusbefore adoption698a1b8
lines 69–78why, one step back69test('"verbose" function does not receive verboseObject.result, "command"', () => testVerboseResultStart('command', {}, false));70test('"verbose" function does not receive verboseObject.result, "output"', () => testVerboseResultStart('output', {}, false));71test('"verbose" function does not receive verboseObject.result, "ipc"', () => testVerboseResultStart('ipc', {}, false));72test('"verbose" function does not receive verboseObject.result, "command", spawn error', () => testVerboseResultStart('command', earlyErrorOptions, false));73test('"verbose" function does not receive verboseObject.result, "output", spawn error', () => testVerboseResultStart('output', earlyErrorOptions, false));74test('"verbose" function does not receive verboseObject.result, "ipc", spawn error', () => testVerboseResultStart('ipc', earlyErrorOptions, false));75test('"verbose" function does not receive verboseObject.result, "command", sync', () => testVerboseResultStart('command', {}, true));76test('"verbose" function does not receive verboseObject.result, "output", sync', () => testVerboseResultStart('output', {}, true));77test('"verbose" function does not receive verboseObject.result, "command", spawn error, sync', () => testVerboseResultStart('command', earlyErrorOptionsSync, true));78test('"verbose" function does not receive verboseObject.result, "output", spawn error, sync', () => testVerboseResultStart('output', earlyErrorOptionsSync, true));