2017-02-19 21:06:38 -03:00
|
|
|
/*
|
2021-04-08 21:12:56 +02:00
|
|
|
* Magic Mirror Global Setup Test Suite
|
2017-02-19 21:06:38 -03:00
|
|
|
*
|
|
|
|
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
|
|
|
* MIT Licensed.
|
2020-05-11 22:22:32 +02:00
|
|
|
*/
|
2017-02-19 21:06:38 -03:00
|
|
|
const Application = require("spectron").Application;
|
2017-07-24 22:08:12 +02:00
|
|
|
const assert = require("assert");
|
|
|
|
const path = require("path");
|
2021-06-12 20:03:20 +02:00
|
|
|
const EventEmitter = require("events");
|
2017-02-19 21:06:38 -03:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
exports.getElectronPath = function () {
|
2021-02-05 22:41:23 +01:00
|
|
|
let electronPath = path.join(__dirname, "..", "..", "node_modules", ".bin", "electron");
|
2017-07-24 22:08:12 +02:00
|
|
|
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
|
2020-05-11 22:22:32 +02:00
|
|
|
exports.setupTimeout = function (test) {
|
2017-07-24 22:08:12 +02:00
|
|
|
if (process.env.CI) {
|
2021-06-08 00:47:40 +02:00
|
|
|
jest.setTimeout(30000);
|
2017-07-24 22:08:12 +02:00
|
|
|
} else {
|
2021-06-08 00:47:40 +02:00
|
|
|
jest.setTimeout(10000);
|
2017-07-24 22:08:12 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
exports.startApplication = function (options) {
|
2021-06-12 20:03:20 +02:00
|
|
|
const emitter = new EventEmitter();
|
|
|
|
emitter.setMaxListeners(100);
|
|
|
|
|
2017-07-24 22:08:12 +02:00
|
|
|
options.path = exports.getElectronPath();
|
|
|
|
if (process.env.CI) {
|
|
|
|
options.startTimeout = 30000;
|
|
|
|
}
|
|
|
|
|
2021-02-05 22:41:23 +01:00
|
|
|
const app = new Application(options);
|
2020-05-11 22:22:32 +02:00
|
|
|
return app.start().then(function () {
|
2021-02-05 22:41:23 +01:00
|
|
|
assert.strictEqual(app.isRunning(), true);
|
2017-07-24 22:08:12 +02:00
|
|
|
return app;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
exports.stopApplication = function (app) {
|
2017-07-24 22:08:12 +02:00
|
|
|
if (!app || !app.isRunning()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
return app.stop().then(function () {
|
2021-02-05 22:41:23 +01:00
|
|
|
assert.strictEqual(app.isRunning(), false);
|
2017-07-24 22:08:12 +02:00
|
|
|
});
|
|
|
|
};
|