Skip to content
Permalink
Browse files

test(starter): add test for returned childProcess.spawn

  • Loading branch information
anulman authored and MarshallOfSound committed Jan 31, 2017
1 parent b5ba30e commit f2c128e41b56b22d302d16c10ea1fc4ea315ea56
Showing with 30 additions and 14 deletions.
  1. +30 −14 test/slow/start_spec_slow.js
@@ -1,21 +1,24 @@
import { expect } from 'chai';
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import proxyquire from 'proxyquire';
import sinon from 'sinon';

chai.use(chaiAsPromised);

describe('start', () => {
let start;
let resolveStub;
let spawnSpy;
let spawnStub;

beforeEach(() => {
resolveStub = sinon.stub();
spawnSpy = sinon.spy();
spawnStub = sinon.stub();
start = proxyquire.noCallThru().load('../../src/api/start', {
'../util/resolve-dir': async dir => resolveStub(dir),
'../util/read-package-json': () => Promise.resolve(require('../fixture/dummy_app/package.json')),
'../util/rebuild': () => Promise.resolve(),
child_process: {
spawn: spawnSpy,
spawn: spawnStub,
},
}).default;
});
@@ -26,10 +29,10 @@ describe('start', () => {
dir: __dirname,
interactive: false,
});
expect(spawnSpy.callCount).to.equal(1);
expect(spawnSpy.firstCall.args[0]).to.contain('electron');
expect(spawnSpy.firstCall.args[2]).to.have.property('cwd', __dirname);
expect(spawnSpy.firstCall.args[2].env).to.not.have.property('ELECTRON_ENABLE_LOGGING');
expect(spawnStub.callCount).to.equal(1);
expect(spawnStub.firstCall.args[0]).to.contain('electron');
expect(spawnStub.firstCall.args[2]).to.have.property('cwd', __dirname);
expect(spawnStub.firstCall.args[2].env).to.not.have.property('ELECTRON_ENABLE_LOGGING');
});

it('should enable electron logging if enableLogging=true', async () => {
@@ -39,13 +42,14 @@ describe('start', () => {
interactive: false,
enableLogging: true,
});
expect(spawnSpy.callCount).to.equal(1);
expect(spawnSpy.firstCall.args[0]).to.contain('electron');
expect(spawnSpy.firstCall.args[2].env).to.have.property('ELECTRON_ENABLE_LOGGING', true);
expect(spawnStub.callCount).to.equal(1);
expect(spawnStub.firstCall.args[0]).to.contain('electron');
expect(spawnStub.firstCall.args[2].env).to.have.property('ELECTRON_ENABLE_LOGGING', true);
});

it('should throw if no dir could be found', async () => {
resolveStub.returns(null);

await expect(start()).to.eventually.be.rejectedWith(
'Failed to locate startable Electron application'
);
@@ -54,13 +58,25 @@ describe('start', () => {
it('should pass all args through to the spawned Electron instance', async () => {
const args = ['magic_arg', 123, 'thingy'];
resolveStub.returnsArg(0);
spawnStub.returns(0);
await start({
dir: __dirname,
interactive: false,
args,
});
expect(spawnSpy.callCount).to.equal(1);
expect(spawnSpy.firstCall.args[0]).to.contain('electron');
expect(spawnSpy.firstCall.args[1].slice(1)).to.deep.equal(args);
expect(spawnStub.callCount).to.equal(1);
expect(spawnStub.firstCall.args[0]).to.contain('electron');
expect(spawnStub.firstCall.args[1].slice(1)).to.deep.equal(args);
});

it('should resolve with a handle to the spawned instance', async () => {
resolveStub.returnsArg(0);
spawnStub.returns('child');

await expect(start({
dir: __dirname,
interactive: false,
enableLogging: true,
})).to.eventually.equal('child');
});
});

0 comments on commit f2c128e

Please sign in to comment.
You can’t perform that action at this time.