MagicMirror/tests/e2e/global-setup.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

/*
2021-04-08 21:12:56 +02:00
* Magic Mirror Global Setup Test Suite
*
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed.
*/
const Application = require("spectron").Application;
const assert = require("assert");
const path = require("path");
const EventEmitter = require("events");
exports.getElectronPath = function () {
2021-02-05 22:41:23 +01:00
let electronPath = path.join(__dirname, "..", "..", "node_modules", ".bin", "electron");
if (process.platform === "win32") {
electronPath += ".cmd";
}
return electronPath;
};
2021-06-11 22:14:57 +02:00
// Set timeout - if this is run as CI Job, increase timeout
exports.setupTimeout = function (test) {
if (process.env.CI) {
2021-06-08 00:47:40 +02:00
jest.setTimeout(30000);
} else {
2021-06-08 00:47:40 +02:00
jest.setTimeout(10000);
}
};
exports.startApplication = function (options) {
const emitter = new EventEmitter();
emitter.setMaxListeners(100);
options.path = exports.getElectronPath();
if (process.env.CI) {
options.startTimeout = 30000;
}
2021-02-05 22:41:23 +01:00
const app = new Application(options);
return app.start().then(function () {
2021-02-05 22:41:23 +01:00
assert.strictEqual(app.isRunning(), true);
return app;
});
};
exports.stopApplication = function (app) {
if (!app || !app.isRunning()) {
return;
}
return app.stop().then(function () {
2021-02-05 22:41:23 +01:00
assert.strictEqual(app.isRunning(), false);
});
};