forked from cucumber/cucumber-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (52 loc) · 1.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { join, resolve } = require('path')
const window = require('electron-window')
const { app, ipcMain: ipc } = require('electron')
app.commandLine.appendSwitch('--disable-http-cache')
const Options = require('./cli/options')
const options = new Options(process.argv)
global.mainProcessDebug = function ({ namespaces, args }) {
const debug = require('debug')
const log = debug(namespaces)
log(...args)
}
let win
app.on('ready', () => {
win = window.createWindow({
height: 900,
width: 1000,
focusable: options.electronDebug,
show: false,
webPreferences: {
webSecurity: process.env.CUCUMBER_ELECTRON_DISABLE_WEB_SECURITY !== '1'
}
})
win.webContents.once('did-finish-load', () => {
if (options.electronDebug) {
win.show()
win.webContents.openDevTools()
win.webContents.on('devtools-opened', () => {
// Debugger is not immediately ready
setTimeout(() => {
win.webContents.send('run-cucumber')
// after the first run, reloading the electron window re-runs cucumber
ipc.on('ready-to-run-cucumber', () => {
win.webContents.send('run-cucumber')
})
}, 250)
})
} else {
win.webContents.send('run-cucumber')
}
})
if (!options.electronDebug && process.platform === 'darwin') {
app.dock.hide()
}
const indexPath = resolve(join(__dirname, 'renderer/index.html'))
// undocumented call in electron-window
win._loadURLWithArgs(indexPath, {}, () => {})
})
// in debug mode electron window stays open after ctrc-c
// the code below force quits the window
app.on('before-quit', function () {
app.exit()
})