Skip to content

Commit d3d7ccc

Browse files
committed
tested from Mocha
1 parent f2e689d commit d3d7ccc

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

__snapshots__/stub-spawn-once-spec.js.snap-shot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@ exports['plain execa.shell 1'] = {
99
"timedOut": false
1010
}
1111

12+
exports['mocks command with exit code, stdout and stderr 1'] = {
13+
"stdout": "foo",
14+
"stderr": "bar",
15+
"code": 0,
16+
"failed": false,
17+
"killed": false,
18+
"signal": null,
19+
"cmd": "/bin/sh -c echo \"hello\"",
20+
"timedOut": false
21+
}
22+

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function spawnStub (command, exitCode, stdout, stderr) {
5151
setTimeout(() => {
5252
if (listeners.exit) {
5353
listeners.exit.forEach(cb => {
54-
console.log('calling exit code %d and signal %s', exitCode, exitSignal)
54+
debug('calling exit code %d and signal %s', exitCode, exitSignal)
5555
cb(exitCode, exitSignal)
5656
})
5757
}

src/stub-spawn-once-spec.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22

33
const execa = require('execa')
44
const snapshot = require('snap-shot')
5+
const la = require('lazy-ass')
6+
const is = require('check-more-types')
57

68
/* global describe, it */
7-
// const stubSpawnOnce = require('.')
89

910
describe('stub-spawn-once', () => {
11+
const { stubSpawnOnce } = require('.')
12+
1013
it('plain execa.shell', () => {
1114
return snapshot(execa.shell('echo "hello"'))
1215
})
16+
17+
it('is a function', () => {
18+
la(is.fn(stubSpawnOnce))
19+
})
20+
21+
it('mocks command with exit code, stdout and stderr', () => {
22+
const cmd = 'echo "hello"'
23+
// this is command for execa.shell
24+
stubSpawnOnce(`/bin/sh -c ${cmd}`, 0, 'foo', 'bar')
25+
return snapshot(execa.shell(cmd))
26+
})
1327
})

0 commit comments

Comments
 (0)