Skip to content

Commit 689decb

Browse files
committed
Fixes execShellScript tests
1 parent fc8aafc commit 689decb

File tree

1 file changed

+5
-38
lines changed

1 file changed

+5
-38
lines changed

server/src/util/__tests__/sh.test.ts

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,16 @@
1-
import * as ChildPorcess from 'child_process'
2-
// @ts-ignore
3-
ChildPorcess.spawn = jest.fn(ChildPorcess.spawn)
4-
51
/* eslint-disable no-useless-escape */
62
import * as sh from '../sh'
73

84
describe('execShellScript', () => {
95
it('resolves if childprocess sends close signal', async () => {
10-
// @ts-ignore
11-
ChildPorcess.spawn.mockReturnValueOnce({
12-
stdout: {
13-
on: (eventName: string, cb: (s: string) => {}) => {
14-
setImmediate(() => {
15-
cb('abc')
16-
})
17-
},
18-
},
19-
on: (eventName: string, cb: (n: number) => {}) => {
20-
setImmediate(() => {
21-
cb(0)
22-
})
23-
},
24-
})
25-
return expect(sh.execShellScript('something')).resolves.toBe('abc')
6+
return expect(sh.execShellScript('echo')).resolves
267
})
278

289
it('rejects if childprocess sends error signal', async () => {
29-
// @ts-ignore
30-
ChildPorcess.spawn.mockReturnValueOnce({
31-
stdout: {
32-
on: (eventName: string, cb: (s: string) => {}) => {
33-
setImmediate(() => {
34-
cb('abc')
35-
})
36-
},
37-
},
38-
on: (eventName: string, cb: (err: Error) => {}) => {
39-
setImmediate(() => {
40-
cb(new Error('err'))
41-
})
42-
},
43-
})
44-
return expect(sh.execShellScript('something')).rejects.toBe(
45-
'Failed to execute something',
46-
)
10+
// an error is sent if child_process cant spawn 'some-nonexistant-command'
11+
return expect(
12+
sh.execShellScript('something', 'some-nonexistant-command'),
13+
).rejects.toBe('Failed to execute something')
4714
})
4815
})
4916

0 commit comments

Comments
 (0)