Skip to content

Commit

Permalink
test: make sure tests fail properly instead of timing out
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Jun 28, 2020
1 parent 1c49e4e commit 31810bb
Show file tree
Hide file tree
Showing 20 changed files with 1,488 additions and 1,149 deletions.
42 changes: 16 additions & 26 deletions spec-main/api-app-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,17 @@ describe('app module', () => {
});

describe('app.requestSingleInstanceLock', () => {
it('prevents the second launch of app', function (done) {
it('prevents the second launch of app', async function () {
this.timeout(120000);
const appPath = path.join(fixturesPath, 'api', 'singleton');
const first = cp.spawn(process.execPath, [appPath]);
first.once('exit', code => {
expect(code).to.equal(0);
});
await emittedOnce(first.stdout, 'data');
// Start second app when received output.
first.stdout.once('data', () => {
const second = cp.spawn(process.execPath, [appPath]);
second.once('exit', code => {
expect(code).to.equal(1);
done();
});
});
const second = cp.spawn(process.execPath, [appPath]);
const [code2] = await emittedOnce(second, 'exit');
expect(code2).to.equal(1);
const [code1] = await emittedOnce(first, 'exit');
expect(code1).to.equal(0);
});

it('passes arguments to the second-instance event', async () => {
Expand Down Expand Up @@ -986,34 +982,28 @@ describe('app module', () => {
}
});

it('does not launch for argument following a URL', done => {
it('does not launch for argument following a URL', async () => {
const appPath = path.join(fixturesPath, 'api', 'quit-app');
// App should exit with non 123 code.
const first = cp.spawn(process.execPath, [appPath, 'electron-test:?', 'abc']);
first.once('exit', code => {
expect(code).to.not.equal(123);
done();
});
const [code] = await emittedOnce(first, 'exit');
expect(code).to.not.equal(123);
});

it('launches successfully for argument following a file path', done => {
it('launches successfully for argument following a file path', async () => {
const appPath = path.join(fixturesPath, 'api', 'quit-app');
// App should exit with code 123.
const first = cp.spawn(process.execPath, [appPath, 'e:\\abc', 'abc']);
first.once('exit', code => {
expect(code).to.equal(123);
done();
});
const [code] = await emittedOnce(first, 'exit');
expect(code).to.equal(123);
});

it('launches successfully for multiple URIs following --', done => {
it('launches successfully for multiple URIs following --', async () => {
const appPath = path.join(fixturesPath, 'api', 'quit-app');
// App should exit with code 123.
const first = cp.spawn(process.execPath, [appPath, '--', 'http://electronjs.org', 'electron-test://testdata']);
first.once('exit', code => {
expect(code).to.equal(123);
done();
});
const [code] = await emittedOnce(first, 'exit');
expect(code).to.equal(123);
});
});

Expand Down
31 changes: 14 additions & 17 deletions spec-main/api-auto-updater-spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { autoUpdater } from 'electron/main';
import { expect } from 'chai';
import { ifit, ifdescribe } from './spec-helpers';
import { emittedOnce } from './events-helpers';

ifdescribe(!process.mas)('autoUpdater module', function () {
describe('checkForUpdates', function () {
ifit(process.platform === 'win32')('emits an error on Windows if the feed URL is not set', function (done) {
autoUpdater.once('error', function (error) {
expect(error.message).to.equal('Update URL is not set');
done();
});
ifit(process.platform === 'win32')('emits an error on Windows if the feed URL is not set', async function () {
const errorEvent = emittedOnce(autoUpdater, 'error');
autoUpdater.setFeedURL({ url: '' });
autoUpdater.checkForUpdates();
const [error] = await errorEvent;
expect(error.message).to.equal('Update URL is not set');
});
});

Expand All @@ -19,11 +19,10 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
expect(autoUpdater.getFeedURL()).to.equal('');
});

ifit(process.platform === 'win32')('correctly fetches the previously set FeedURL', function (done) {
ifit(process.platform === 'win32')('correctly fetches the previously set FeedURL', function () {
const updateURL = 'https://fake-update.electron.io';
autoUpdater.setFeedURL({ url: updateURL });
expect(autoUpdater.getFeedURL()).to.equal(updateURL);
done();
});
});

Expand Down Expand Up @@ -56,12 +55,11 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
});

ifdescribe(process.platform === 'darwin')('on Mac', function () {
it('emits an error when the application is unsigned', done => {
autoUpdater.once('error', function (error) {
expect(error.message).equal('Could not get code signature for running application');
done();
});
it('emits an error when the application is unsigned', async () => {
const errorEvent = emittedOnce(autoUpdater, 'error');
autoUpdater.setFeedURL({ url: '' });
const [error] = await errorEvent;
expect(error.message).equal('Could not get code signature for running application');
});

it('does not throw if default is the serverType', () => {
Expand All @@ -81,12 +79,11 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
});

describe('quitAndInstall', () => {
ifit(process.platform === 'win32')('emits an error on Windows when no update is available', function (done) {
autoUpdater.once('error', function (error) {
expect(error.message).to.equal('No update available, can\'t quit and install');
done();
});
ifit(process.platform === 'win32')('emits an error on Windows when no update is available', async function () {
const errorEvent = emittedOnce(autoUpdater, 'error');
autoUpdater.quitAndInstall();
const [error] = await errorEvent;
expect(error.message).to.equal('No update available, can\'t quit and install');
});
});
});
15 changes: 7 additions & 8 deletions spec-main/api-browser-view-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,16 @@ describe('BrowserView module', () => {
});

describe('window.open()', () => {
it('works in BrowserView', (done) => {
it('works in BrowserView', async () => {
view = new BrowserView();
w.setBrowserView(view);
view.webContents.once('new-window', (e, url, frameName, disposition, options, additionalFeatures) => {
e.preventDefault();
expect(url).to.equal('http://host/');
expect(frameName).to.equal('host');
expect(additionalFeatures[0]).to.equal('this-is-not-a-standard-feature');
done();
});
const newWindow = emittedOnce(view.webContents, 'new-window');
view.webContents.once('new-window', event => event.preventDefault());
view.webContents.loadFile(path.join(fixtures, 'pages', 'window-open.html'));
const [, url, frameName,,, additionalFeatures] = await newWindow;
expect(url).to.equal('http://host/');
expect(frameName).to.equal('host');
expect(additionalFeatures[0]).to.equal('this-is-not-a-standard-feature');
});
});
});

0 comments on commit 31810bb

Please sign in to comment.