-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.test.js
62 lines (54 loc) · 1.82 KB
/
index.test.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
61
62
const path = require('path');
const { app, BrowserWindow, ipcMain } = require('electron');
const base = (process.env.NODE_ENV === 'test:src') ? 'src' : 'lib';
const {
MessageChannel, /* must required in index.js even if you don't use it */
BrowserService,
} = require(`./${base}/index`);
const test = require('./test/');
const entryHtml = path.join(__dirname, 'test/index.html');
const entryService = path.join(__dirname, 'test/services/app.service.js');
const otherService = path.join(__dirname, 'test/services/other.service.js');
const argv = require('minimist')(process.argv.slice(2));
// allow require native modules in renderer process
app.allowRendererProcessReuse = false;
/* 创建窗口 */
async function createWindow() {
global.mainWindow = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
},
});
global.mainWindow.loadFile(entryHtml);
global.mainWindow.openDevTools();
}
/* prepare to test */
describe('app ready => ', function() {
this.timeout(120e3);
before(async () => {
await app.whenReady().then(() => {
ipcMain.on('console', (event, info) => console.log('console => ', info));
});
global.appService = new BrowserService('app',
entryService,
{ dev: true, webPreferences: { webSecurity: false } }
);
global.otherService = new BrowserService('other',
otherService,
{ dev: true, webPreferences: { webSecurity: false } }
);
await global.appService.connected();
await global.otherService.connected();
global.appService.openDevTools();
global.otherService.openDevTools();
await createWindow();
await new Promise(resolve => {
global.mainWindow.webContents.on('did-finish-load', () => {
setTimeout(resolve, 3e3);
});
});
});
test.run(argv);
});