import * as electron from 'electron';
import { expect } from 'chai';
import rewiremock from 'rewiremock';

import 'mocha';
import { Application } from 'spectron';
import packageJson from '../package.json';

rewiremock.disable();

describe('Application @slow', function () {
  this.timeout(20000);

  before(function () {
    this.app = new Application({
      // @ts-ignore this does give the path to electron executable (hopefully platform agnostic)
      path: electron.default,
      args: [packageJson.main],
    });
    return this.app.start();
  });

  after(function () {
    if (this.app && this.app.isRunning()) {
      return this.app.stop();
    }
  });

  it('shows an initial window', function () {
    return this.app.client.getWindowCount().then((count: number) => {
      expect(count).to.be.gte(1);
    });
  });
});
