-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
verbose
to be a function for custom logging
- Loading branch information
Showing
19 changed files
with
244 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const getOptions = ({type, eventProperty}) => ({ | ||
verbose: (logLine, logEvent) => logEvent.type === type ? `${logEvent[eventProperty]}` : undefined, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const getOptions = ({fdNumber, secondFdNumber}) => ({ | ||
verbose: { | ||
[fdNumber](logLine) { | ||
console.warn(logLine); | ||
}, | ||
[secondFdNumber]() {}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const setFdSpecific = (fdNumber, option) => fdNumber === undefined | ||
? option | ||
: {[fdNumber]: option}; | ||
|
||
export const getOptions = ({fdNumber}) => ({ | ||
verbose: setFdSpecific(fdNumber, logLine => { | ||
console.warn(logLine); | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const getOptions = ({logOutput}) => ({ | ||
verbose(logLine, {type}) { | ||
return type === 'command' ? logOutput : undefined; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const getOptions = ({errorMessage}) => ({ | ||
verbose() { | ||
throw new Error(errorMessage); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const getOptions = () => ({ | ||
verbose(logLine, {type}) { | ||
return type === 'command' ? logLine.replace('noop', 'NOOP') : undefined; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import test from 'ava'; | ||
import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; | ||
import {foobarString} from '../helpers/input.js'; | ||
import {nestedSubprocess} from '../helpers/nested.js'; | ||
import {getCommandLine, testTimestamp} from '../helpers/verbose.js'; | ||
|
||
setFixtureDirectory(); | ||
|
||
const testCustomReturn = async (t, logOutput, expectedOutput) => { | ||
const {stderr} = await nestedSubprocess( | ||
'noop.js', | ||
['.'], | ||
{optionsFixture: 'custom-return.js', optionsInput: {logOutput}}, | ||
{stripFinalNewline: false}, | ||
); | ||
t.is(stderr, expectedOutput); | ||
}; | ||
|
||
test('"verbose" returning a string prints it', testCustomReturn, `${foobarString}\n`, `${foobarString}\n`); | ||
test('"verbose" returning a string without a newline adds it', testCustomReturn, foobarString, `${foobarString}\n`); | ||
test('"verbose" returning a string with multiple newlines keeps them', testCustomReturn, `${foobarString}\n\n`, `${foobarString}\n\n`); | ||
test('"verbose" returning an empty string prints an empty line', testCustomReturn, '', '\n'); | ||
test('"verbose" returning undefined ignores it', testCustomReturn, undefined, ''); | ||
test('"verbose" returning a number ignores it', testCustomReturn, 0, ''); | ||
test('"verbose" returning a bigint ignores it', testCustomReturn, 0n, ''); | ||
test('"verbose" returning a boolean ignores it', testCustomReturn, true, ''); | ||
test('"verbose" returning an object ignores it', testCustomReturn, {}, ''); | ||
test('"verbose" returning an array ignores it', testCustomReturn, [], ''); | ||
|
||
test('"verbose" receives logLine string as first argument', async t => { | ||
const {stderr} = await nestedSubprocess('noop.js', [foobarString], {optionsFixture: 'custom-uppercase.js'}); | ||
t.is(getCommandLine(stderr), `${testTimestamp} [0] $ NOOP.js ${foobarString}`); | ||
}); |
Oops, something went wrong.