realm-js/tests/electron/runner.js

53 lines
1.5 KiB
JavaScript

"use strict";
const assert = require("assert");
const path = require("path");
const Application = require("spectron").Application;
const ELECTRON_PATH = path.resolve(__dirname, "node_modules/.bin/electron");
const MAIN_PATH = path.resolve(__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("Starting an Electron process.");
app.start().then(() => {
// 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);
})