-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: The existing banner is now emitted using `proc-log` instead of `console.log`. It is always emitted. Consuming libraries can decide under which situations to show the banner.
- Loading branch information
Showing
2 changed files
with
26 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,19 @@ const isWindows = process.platform === 'win32' | |
const emptyDir = t.testdir({}) | ||
|
||
const pkill = process.kill | ||
const consoleLog = console.log | ||
|
||
const mockConsole = t => { | ||
const logs = [] | ||
console.log = (...args) => logs.push(args) | ||
t.teardown(() => console.log = consoleLog) | ||
return logs | ||
const output = [] | ||
const appendOutput = (level, ...args) => { | ||
if (level === 'standard') { | ||
output.push([...args]) | ||
} | ||
} | ||
process.on('output', appendOutput) | ||
t.afterEach(() => output.length = 0) | ||
t.teardown(() => process.removeListener('output', appendOutput)) | ||
|
||
t.test('run-script-pkg', async t => { | ||
await t.test('do the banner when stdio is inherited, handle line breaks', async t => { | ||
const logs = mockConsole(t) | ||
await t.test('output with no args and a pkgid', async t => { | ||
spawk.spawn('sh', a => a.includes('bar\nbaz\n')) | ||
await runScript({ | ||
event: 'foo', | ||
|
@@ -33,34 +34,11 @@ t.test('run-script-pkg', async t => { | |
scripts: {}, | ||
}, | ||
}) | ||
t.strictSame(logs, [['\n> [email protected] foo\n> bar\n> baz\n']]) | ||
t.strictSame(output, [['\n> [email protected] foo\n']]) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('do not show banner when stdio is inherited, if suppressed', async t => { | ||
const logs = mockConsole(t) | ||
spawk.spawn('sh', a => a.includes('bar')) | ||
await runScript({ | ||
event: 'foo', | ||
path: emptyDir, | ||
scriptShell: 'sh', | ||
env: { | ||
environ: 'value', | ||
}, | ||
stdio: 'inherit', | ||
cmd: 'bar', | ||
pkg: { | ||
_id: '[email protected]', | ||
scripts: {}, | ||
}, | ||
banner: false, | ||
}) | ||
t.strictSame(logs, []) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('do the banner with no pkgid', async t => { | ||
const logs = mockConsole(t) | ||
await t.test('output with args and no pkgid', async t => { | ||
spawk.spawn('sh', a => a.includes('bar baz buzz')) | ||
await runScript({ | ||
event: 'foo', | ||
|
@@ -76,12 +54,11 @@ t.test('run-script-pkg', async t => { | |
scripts: {}, | ||
}, | ||
}) | ||
t.strictSame(logs, [['\n> foo\n> bar baz buzz\n']]) | ||
t.strictSame(output, [['\n> foo\n> bar baz buzz\n']]) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('pkg has foo script', async t => { | ||
const logs = mockConsole(t) | ||
spawk.spawn('sh', a => a.includes('bar')) | ||
await runScript({ | ||
event: 'foo', | ||
|
@@ -98,12 +75,11 @@ t.test('run-script-pkg', async t => { | |
}, | ||
}, | ||
}) | ||
t.strictSame(logs, []) | ||
t.strictSame(output, [['\n> [email protected] foo\n']]) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('pkg has foo script, with args', async t => { | ||
const logs = mockConsole(t) | ||
spawk.spawn('sh', a => a.includes('bar a b c')) | ||
await runScript({ | ||
event: 'foo', | ||
|
@@ -122,7 +98,7 @@ t.test('run-script-pkg', async t => { | |
args: ['a', 'b', 'c'], | ||
binPaths: false, | ||
}) | ||
t.strictSame(logs, []) | ||
t.strictSame(output, [['\n> [email protected] foo\n> bar a b c\n']]) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
|
@@ -131,7 +107,6 @@ t.test('run-script-pkg', async t => { | |
'binding.gyp': 'exists', | ||
}) | ||
|
||
const logs = mockConsole(t) | ||
spawk.spawn('sh', a => a.includes('node-gyp rebuild')) | ||
await runScript({ | ||
event: 'install', | ||
|
@@ -146,7 +121,7 @@ t.test('run-script-pkg', async t => { | |
scripts: {}, | ||
}, | ||
}) | ||
t.strictSame(logs, []) | ||
t.strictSame(output, [['\n> [email protected] install\n']]) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
|