realm-js/tests/electron/runner.js
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

54 lines
1.6 KiB
JavaScript

"use strict";
const assert = require("assert");
const path = require("path");
const Application = require("spectron").Application;
const ELECTRON_PATH = path.join(__dirname, "node_modules", ".bin", "electron");
const MAIN_PATH = path.join(__dirname, "app", "main.js");
const POLL_LOG_DELAY = 500;
const filterOption = process.argv[2] || null;
const doneMatcher = /Electron process stopped, with status ([-\d]+)/;
const app = new Application({
path: ELECTRON_PATH,
args: [ MAIN_PATH ].concat(process.argv.slice(2))
});
console.log("Trying to start an Electron process.");
app.start().then(() => {
console.log("The following messages are logs from the Electron process:");
// Keep reading the log, until Jasmine prints "ALL DONE"
return new Promise((resolve, reject) => {
const timeout = setInterval(() => {
app.client.getMainProcessLogs().then((logs) => {
logs.forEach((msg) => {
console.log(msg);
const doneTest = doneMatcher.exec(msg);
if(doneTest) {
const statusCode = parseInt(doneTest[1], 10);
clearTimeout(timeout);
resolve(statusCode);
}
});
app.client.getWindowCount().then((count) => {
if(count === 0) {
const err = new Error("All Electron windows unexpectedly closed.");
reject(err);
}
});
});
}, POLL_LOG_DELAY);
});
}).then((statusCode) => {
// Exit with the same status as the Electron process
process.exit(statusCode);
}).catch((error) => {
// Log any failures
console.error("Test harness failure:", error.message);
process.exit(-1);
})