Skip to content

Commit

Permalink
test(starter): add test coverage for starter
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored and malept committed Jan 30, 2017
1 parent 4049e31 commit 0d2f571
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/api/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default async (providedOptions = {}) => {
enableLogging: false,
args: [],
}, providedOptions);
asyncOra.interactive = interactive;

await asyncOra('Locating Application', async () => {
dir = await resolveDir(dir);
Expand All @@ -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 {
Expand Down
66 changes: 66 additions & 0 deletions test/slow/start_spec_slow.js
Original file line number Diff line number Diff line change
@@ -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.