import * as electron from 'electron'; import { expect } from 'chai'; import { Context } from 'mocha'; import rewiremock from 'rewiremock'; import 'mocha'; import { Application } from 'spectron'; import packageJson from '../package.json'; rewiremock.disable(); describe('Application @slow', function () { this.timeout(20000); interface IApplicationContext extends Context { app: Application; } before(function (this, done): void { const context = this as IApplicationContext; context.app = new Application({ // @ts-ignore this does give the path to electron executable when this script is running outside of electron (which it does in the test files) path: ((electron as unknown) as { default: string }).default, args: [packageJson.main], }); context.app .start() .then(() => done()) .catch((reason) => done(reason)); }); after(function (this) { const context = this as IApplicationContext; if (context.app && context.app.isRunning()) { return context.app.stop(); } }); it('shows an initial window', function (this: Context) { const context = this as IApplicationContext; return context.app.client.getWindowCount().then((count: number) => { expect(count).to.be.gte(1); }); }); });