Skip to content

Commit f2c128e

Browse files
anulmanMarshallOfSound
authored andcommitted
test(starter): add test for returned childProcess.spawn
1 parent b5ba30e commit f2c128e

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

test/slow/start_spec_slow.js

+30-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
import { expect } from 'chai';
1+
import chai, { expect } from 'chai';
2+
import chaiAsPromised from 'chai-as-promised';
23
import proxyquire from 'proxyquire';
34
import sinon from 'sinon';
45

6+
chai.use(chaiAsPromised);
7+
58
describe('start', () => {
69
let start;
710
let resolveStub;
8-
let spawnSpy;
11+
let spawnStub;
912

1013
beforeEach(() => {
1114
resolveStub = sinon.stub();
12-
spawnSpy = sinon.spy();
15+
spawnStub = sinon.stub();
1316
start = proxyquire.noCallThru().load('../../src/api/start', {
1417
'../util/resolve-dir': async dir => resolveStub(dir),
1518
'../util/read-package-json': () => Promise.resolve(require('../fixture/dummy_app/package.json')),
1619
'../util/rebuild': () => Promise.resolve(),
1720
child_process: {
18-
spawn: spawnSpy,
21+
spawn: spawnStub,
1922
},
2023
}).default;
2124
});
@@ -26,10 +29,10 @@ describe('start', () => {
2629
dir: __dirname,
2730
interactive: false,
2831
});
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');
3336
});
3437

3538
it('should enable electron logging if enableLogging=true', async () => {
@@ -39,13 +42,14 @@ describe('start', () => {
3942
interactive: false,
4043
enableLogging: true,
4144
});
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);
4548
});
4649

4750
it('should throw if no dir could be found', async () => {
4851
resolveStub.returns(null);
52+
4953
await expect(start()).to.eventually.be.rejectedWith(
5054
'Failed to locate startable Electron application'
5155
);
@@ -54,13 +58,25 @@ describe('start', () => {
5458
it('should pass all args through to the spawned Electron instance', async () => {
5559
const args = ['magic_arg', 123, 'thingy'];
5660
resolveStub.returnsArg(0);
61+
spawnStub.returns(0);
5762
await start({
5863
dir: __dirname,
5964
interactive: false,
6065
args,
6166
});
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');
6581
});
6682
});

0 commit comments

Comments
 (0)