File tree Expand file tree Collapse file tree 1 file changed +5
-38
lines changed
server/src/util/__tests__ Expand file tree Collapse file tree 1 file changed +5
-38
lines changed Original file line number Diff line number Diff line change 1
- import * as ChildPorcess from 'child_process'
2
- // @ts -ignore
3
- ChildPorcess . spawn = jest . fn ( ChildPorcess . spawn )
4
-
5
1
/* eslint-disable no-useless-escape */
6
2
import * as sh from '../sh'
7
3
8
4
describe ( 'execShellScript' , ( ) => {
9
5
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
26
7
} )
27
8
28
9
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' )
47
14
} )
48
15
} )
49
16
You can’t perform that action at this time.
0 commit comments