Kræn Hansen e4e1431c55 Running js tests in Electron renderer process (#1196)
* First take on running the tests inside an Electron render process

* Making progress

* Making it possible to override the location of the admin token

* Ignoreing the realm-object-server files

* Fixing a console.log to return a string instead of a boolean

But it should probably be removed entirely

* Making the downloaded ROS log less

* Adjusting comments in the test.sh

* Checking number of windows to determine an Electron crash

* Added a test that triggers garbage collection of ArrayBuffers

* Enabled the ability to run the tests in Electrons main process

* Run tests first in main process and the render

* Added a README.md that documents how Electron tests can be run

* Added a comment on why the garbage-collection test was added.

* Waiting with reading the admin token, until it is actually used

* Disabling the GarbageCollectionTests for now
2017-08-11 10:30:57 +02:00

70 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
// This file is pretty much a copy of https://github.com/electron/electron-quick-start/blob/master/main.js
const electron = require("electron");
// Module to control application life.
const app = electron.app;
// Increasing memory
// app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096');
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
const path = require("path");
const url = require("url");
const JASMIN_FILTER_KEY = "--filter";
const MAIN_PROCESS_KEY = "--process";
function getJasminFilter() {
const filterArg = process.argv.find((arg) => arg.indexOf(JASMIN_FILTER_KEY) === 0);
return filterArg ? filterArg.slice(JASMIN_FILTER_KEY.length + 1) : null;
}
function getProcess() {
const filterArg = process.argv.find((arg) => arg.indexOf(MAIN_PROCESS_KEY) === 0);
return filterArg ? filterArg.slice(MAIN_PROCESS_KEY.length + 1) : 'render';
}
const filter = getJasminFilter();
const runIn = getProcess();
// Keep a global reference of the window object, if you don´t, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
app.on("ready", () => {
// Create the browser window.
mainWindow = new BrowserWindow({
show: false
});
global.options = {
filter,
runIn
};
// Load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
}));
if (runIn === "main") {
console.log("Running tests in the main process.");
const jasmine = require("./jasmine.js").execute(filter);
jasmine.onComplete((passed) => {
process.exit(passed ? 0 : -1);
});
} else if(runIn === "render") {
console.log("Running tests in the render process.");
} else {
throw new Error("Can only run the tests in the 'main' or 'render' process");
}
});
app.on("quit", (e, exitCode) => {
console.log("Electron process stopped, with status", exitCode);
});