1
- import { expect } from 'chai' ;
1
+ import chai , { expect } from 'chai' ;
2
+ import chaiAsPromised from 'chai-as-promised' ;
2
3
import proxyquire from 'proxyquire' ;
3
4
import sinon from 'sinon' ;
4
5
6
+ chai . use ( chaiAsPromised ) ;
7
+
5
8
describe ( 'start' , ( ) => {
6
9
let start ;
7
10
let resolveStub ;
8
- let spawnSpy ;
11
+ let spawnStub ;
9
12
10
13
beforeEach ( ( ) => {
11
14
resolveStub = sinon . stub ( ) ;
12
- spawnSpy = sinon . spy ( ) ;
15
+ spawnStub = sinon . stub ( ) ;
13
16
start = proxyquire . noCallThru ( ) . load ( '../../src/api/start' , {
14
17
'../util/resolve-dir' : async dir => resolveStub ( dir ) ,
15
18
'../util/read-package-json' : ( ) => Promise . resolve ( require ( '../fixture/dummy_app/package.json' ) ) ,
16
19
'../util/rebuild' : ( ) => Promise . resolve ( ) ,
17
20
child_process : {
18
- spawn : spawnSpy ,
21
+ spawn : spawnStub ,
19
22
} ,
20
23
} ) . default ;
21
24
} ) ;
@@ -26,10 +29,10 @@ describe('start', () => {
26
29
dir : __dirname ,
27
30
interactive : false ,
28
31
} ) ;
29
- expect ( spawnSpy . callCount ) . to . equal ( 1 ) ;
30
- expect ( spawnSpy . firstCall . args [ 0 ] ) . to . contain ( 'electron' ) ;
31
- expect ( spawnSpy . firstCall . args [ 2 ] ) . to . have . property ( 'cwd' , __dirname ) ;
32
- expect ( spawnSpy . firstCall . args [ 2 ] . env ) . to . not . have . property ( 'ELECTRON_ENABLE_LOGGING' ) ;
32
+ expect ( spawnStub . callCount ) . to . equal ( 1 ) ;
33
+ expect ( spawnStub . firstCall . args [ 0 ] ) . to . contain ( 'electron' ) ;
34
+ expect ( spawnStub . firstCall . args [ 2 ] ) . to . have . property ( 'cwd' , __dirname ) ;
35
+ expect ( spawnStub . firstCall . args [ 2 ] . env ) . to . not . have . property ( 'ELECTRON_ENABLE_LOGGING' ) ;
33
36
} ) ;
34
37
35
38
it ( 'should enable electron logging if enableLogging=true' , async ( ) => {
@@ -39,13 +42,14 @@ describe('start', () => {
39
42
interactive : false ,
40
43
enableLogging : true ,
41
44
} ) ;
42
- expect ( spawnSpy . callCount ) . to . equal ( 1 ) ;
43
- expect ( spawnSpy . firstCall . args [ 0 ] ) . to . contain ( 'electron' ) ;
44
- expect ( spawnSpy . firstCall . args [ 2 ] . env ) . to . have . property ( 'ELECTRON_ENABLE_LOGGING' , true ) ;
45
+ expect ( spawnStub . callCount ) . to . equal ( 1 ) ;
46
+ expect ( spawnStub . firstCall . args [ 0 ] ) . to . contain ( 'electron' ) ;
47
+ expect ( spawnStub . firstCall . args [ 2 ] . env ) . to . have . property ( 'ELECTRON_ENABLE_LOGGING' , true ) ;
45
48
} ) ;
46
49
47
50
it ( 'should throw if no dir could be found' , async ( ) => {
48
51
resolveStub . returns ( null ) ;
52
+
49
53
await expect ( start ( ) ) . to . eventually . be . rejectedWith (
50
54
'Failed to locate startable Electron application'
51
55
) ;
@@ -54,13 +58,25 @@ describe('start', () => {
54
58
it ( 'should pass all args through to the spawned Electron instance' , async ( ) => {
55
59
const args = [ 'magic_arg' , 123 , 'thingy' ] ;
56
60
resolveStub . returnsArg ( 0 ) ;
61
+ spawnStub . returns ( 0 ) ;
57
62
await start ( {
58
63
dir : __dirname ,
59
64
interactive : false ,
60
65
args,
61
66
} ) ;
62
- expect ( spawnSpy . callCount ) . to . equal ( 1 ) ;
63
- expect ( spawnSpy . firstCall . args [ 0 ] ) . to . contain ( 'electron' ) ;
64
- expect ( spawnSpy . firstCall . args [ 1 ] . slice ( 1 ) ) . to . deep . equal ( args ) ;
67
+ expect ( spawnStub . callCount ) . to . equal ( 1 ) ;
68
+ expect ( spawnStub . firstCall . args [ 0 ] ) . to . contain ( 'electron' ) ;
69
+ expect ( spawnStub . firstCall . args [ 1 ] . slice ( 1 ) ) . to . deep . equal ( args ) ;
70
+ } ) ;
71
+
72
+ it ( 'should resolve with a handle to the spawned instance' , async ( ) => {
73
+ resolveStub . returnsArg ( 0 ) ;
74
+ spawnStub . returns ( 'child' ) ;
75
+
76
+ await expect ( start ( {
77
+ dir : __dirname ,
78
+ interactive : false ,
79
+ enableLogging : true ,
80
+ } ) ) . to . eventually . equal ( 'child' ) ;
65
81
} ) ;
66
82
} ) ;
0 commit comments