Skip to content

Commit 758f59f

Browse files
dedo1911sindresorhus
authored andcommittedSep 8, 2019
Fix race issue with protocol registration (#19)
1 parent 8eed33e commit 758f59f

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed
 

‎index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ module.exports = options => {
6565
]);
6666
}
6767

68-
(async () => {
69-
await electron.app.whenReady();
70-
68+
electron.app.on('ready', () => {
7169
const session = options.partition ?
7270
electron.session.fromPartition(options.partition) :
7371
electron.session.defaultSession;
@@ -77,7 +75,7 @@ module.exports = options => {
7775
throw error;
7876
}
7977
});
80-
})();
78+
});
8179

8280
return async win => {
8381
await win.loadURL(`${options.scheme}://-`);

‎test/fixture-on-ready.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
const {app, BrowserWindow} = require('electron');
3+
const serve = require('..');
4+
5+
const loadUrl = serve({directory: __dirname});
6+
7+
let mainWindow;
8+
9+
app.on('ready', () => {
10+
mainWindow = new BrowserWindow();
11+
loadUrl(mainWindow);
12+
});

‎test/test.js

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ test('serves directory index', async t => {
1919
t.pass();
2020
});
2121

22+
test('serves directory index on app ready', async t => {
23+
t.context.spectron = new Application({
24+
path: electron,
25+
args: ['fixture-on-ready.js']
26+
});
27+
await t.context.spectron.start();
28+
const {client} = t.context.spectron;
29+
await client.waitUntilWindowLoaded();
30+
await client.waitUntilTextExists('h1', '🦄', 5000);
31+
t.pass();
32+
});
33+
2234
test('allows special characters in file paths', async t => {
2335
t.context.spectron = new Application({
2436
path: electron,

0 commit comments

Comments
 (0)
Please sign in to comment.