Skip to content
Permalink
Browse files

test(starter): add test coverage for starter

  • Loading branch information
MarshallOfSound authored and malept committed Jan 15, 2017
1 parent 4049e31 commit 0d2f57120a78994d3be2d2e5e311ef58ede8476f
Showing with 68 additions and 0 deletions.
  1. +2 −0 src/api/start.js
  2. +66 −0 test/slow/start_spec_slow.js
@@ -29,6 +29,7 @@ export default async (providedOptions = {}) => {
enableLogging: false,
args: [],
}, providedOptions);
asyncOra.interactive = interactive;

await asyncOra('Locating Application', async () => {
dir = await resolveDir(dir);
@@ -50,6 +51,7 @@ export default async (providedOptions = {}) => {
} : {}),
};
await asyncOra('Launching Application', async () => {
/* istanbul ignore if */
if (process.platform === 'win32') {
spawn(path.resolve(dir, 'node_modules/.bin/electron.cmd'), ['.'].concat(args), spawnOpts);
} else {
@@ -0,0 +1,66 @@
import { expect } from 'chai';
import proxyquire from 'proxyquire';
import sinon from 'sinon';

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

beforeEach(() => {
resolveStub = sinon.stub();
spawnSpy = sinon.spy();
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,
},
}).default;
});

it('should spawn electron in the correct dir', async () => {
resolveStub.returnsArg(0);
await 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');
});

it('should enable electron logging if enableLogging=true', async () => {
resolveStub.returnsArg(0);
await start({
dir: __dirname,
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);
});

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'
);
});

it('should pass all args through to the spawned Electron instance', async () => {
const args = ['magic_arg', 123, 'thingy'];
resolveStub.returnsArg(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);
});
});

0 comments on commit 0d2f571

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