Skip to content
Myr

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 file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–2why, one step back
1import 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 back
3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';
4import {runVerboseSubprocess} from '../helpers/verbose.js';

TweaksSindre Sorhusbefore adoption698a1b8

line 5why, one step back
5import {assertLike} from '../helpers/assert.js';

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

lines 6–14why, one step back
6import {
7 earlyErrorOptions,8 earlyErrorOptionsSync,9 expectedEarlyError,10 expectedEarlyErrorSync,11} from '../helpers/early-error.js';1213setFixtureDirectory();14

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15const testVerboseResultEnd = async (type, isSync) => {

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

lines 16–21why, one step back
16 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 back
22 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 back
28};
29

TweaksSindre Sorhusbefore adoption698a1b8

lines 30–33why, one step back
30test('"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 back
34

TweaksSindre Sorhusbefore adoption698a1b8

line 35why, one step back
35const testVerboseResultEndSpawn = async (type, options, expectedOutput, isSync) => {

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

lines 36–43why, one step back
36 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 back
44 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 back
47 // The subprocess never spawned, so its output is empty
48 assert.equal(result.stdout, '');49 assert.equal(result.stderr, '');

TweaksSindre Sorhusbefore adoption698a1b8

lines 50–51why, one step back
50 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 back
52};
53

TweaksSindre Sorhusbefore adoption698a1b8

lines 54–57why, one step back
54test('"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 back
58

TweaksSindre Sorhusbefore adoption698a1b8

line 59why, one step back
59const testVerboseResultStart = async (type, options, isSync) => {

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

lines 60–65why, one step back
60 const {stderr: parentStderr} = await runVerboseSubprocess({
61 isSync,62 type,63 optionsFixture: 'custom-result.js',64 ...options,65 });

TweaksSindre Sorhusbefore adoption698a1b8

line 66why, one step back
66 assert.equal(parentStderr, '');

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

lines 67–68why, one step back
67};
68

TweaksSindre Sorhusbefore adoption698a1b8

lines 69–78why, one step back
69test('"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));