We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 72710cc commit b7f4b66Copy full SHA for b7f4b66
README.md
@@ -131,6 +131,13 @@ cp.exec('echo "hello"', (code, out, errors) => {
131
})
132
```
133
134
+You can use alias `stubExecOnce` to `stubSpawnOnce`
135
+
136
+```js
137
+const {stubExecOnce} = require('stub-spawn-once')
138
+stubExecOnce('echo "hi"', "bye")
139
+```
140
141
[execFile]: https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback
142
143
### Small print
src/index.js
@@ -129,4 +129,9 @@ function stubSpawnShellOnce (command, exitCode, stdout, stderr) {
129
}
130
-module.exports = { stubSpawnOnce, stubSpawnShellOnce }
+module.exports = {
+ stubSpawnOnce,
+ stubSpawnShellOnce,
+ stubExecOnce: stubSpawnOnce,
+ stubExecFileOnce: stubSpawnOnce
+}
src/stub-spawn-once-spec.js
@@ -48,6 +48,37 @@ describe('stub-spawn-once', () => {
48
49
50
51
+ describe('stubExecOnce', () => {
52
+ const { stubExecOnce } = require('..')
53
54
+ it('is a function', () => {
55
+ la(is.fn(stubExecOnce))
56
+ })
57
58
+ it('stubs cp.exec', done => {
59
+ const cmd = 'does not exist'
60
+ stubExecOnce(cmd, 0, 'foo')
61
+ cp.exec(cmd, (code, stdout) => {
62
+ la(code === 0, 'wrong code', code)
63
+ la(stdout === 'foo', 'wrong stdout', stdout)
64
+ done()
65
66
67
68
+ it('restores cp.exec after that', done => {
69
70
71
72
73
74
+ cp.exec(cmd, (err, out) => {
75
+ la(is.error(err), 'hmm, command succeeded', err, out)
76
77
78
79
80
81
82
describe('stubSpawnOnce', () => {
83
it('is a function', () => {
84
la(is.fn(stubSpawnOnce))
0 commit comments