UNPKG

1.56 kBJavaScriptView Raw
1//
2// This script does double-duty. It can be included from testem-electron.js
3// to define an Electron test runner like so:
4//
5// // testem.js
6// module.exports = {
7// "launchers": {
8// "Electron": require("ember-electron/lib/test-runner")
9// },
10// "launch_in_ci": [
11// "Electron"
12// ],
13// "launch_in_dev": [
14// "Electron"
15// ]
16// }
17//
18// The runner is configured to invoke this script as a command-line executable
19// with the proper arguments to run electron and communicate back to testem.
20//
21
22module.exports = {
23 exe: process.execPath,
24 // These arguments are used in `lib/test-support/index.js`, which is called
25 // from the test main process (via the blueprint-generated
26 // `electron-app/tests/index.js`)
27 args: [__filename, '<testPage>', '<baseUrl>', '<id>'],
28 protocol: 'browser',
29};
30
31async function main() {
32 const path = require('path');
33 const treeKill = require('tree-kill');
34 const { api } = require('ember-electron/lib/utils/forge-core');
35 const {
36 electronProjectPath,
37 } = require('ember-electron/lib/utils/build-paths');
38
39 let [, , testPageUrl, testemUrl, testemId] = process.argv;
40
41 // Start electron
42 let { pid } = await api.start({
43 dir: path.join(process.cwd(), electronProjectPath),
44 appPath: './tests',
45 args: [
46 '--', // needed because https://github.com/electron/electron/pull/13039
47 testPageUrl,
48 testemUrl,
49 testemId,
50 ],
51 });
52 // Clean up when we're killed
53 process.on('SIGTERM', () => {
54 treeKill(pid);
55 });
56}
57
58if (require.main === module) {
59 main();
60}