From e9b5c08700173ff2f13404ee7f8f784b630968fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Fri, 11 Aug 2017 11:57:39 +0200 Subject: [PATCH] Changed the interface to the shared/jasmine --- tests/electron/app/main.js | 21 +++++++++++---------- tests/electron/app/renderer.js | 3 ++- tests/shared/jasmine.js | 31 +++++++++++++++---------------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/tests/electron/app/main.js b/tests/electron/app/main.js index 746299ee..8445c39f 100644 --- a/tests/electron/app/main.js +++ b/tests/electron/app/main.js @@ -3,6 +3,9 @@ // This file is pretty much a copy of https://github.com/electron/electron-quick-start/blob/master/main.js const electron = require("electron"); +const path = require("path"); +const url = require("url"); + // Module to control application life. const app = electron.app; // Increasing memory @@ -10,29 +13,26 @@ const app = electron.app; // Module to create native browser window. const BrowserWindow = electron.BrowserWindow; -const path = require("path"); -const url = require("url"); +const SPEC_PATH = path.resolve(__dirname, "../spec.js"); 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 jasmine = require("realm-tests/jasmine.js") +const filter = jasmine.getFilterFromProcess(); 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; +console.log("The following messages are logs from the Electron process:"); + app.on("ready", () => { // Create the browser window. mainWindow = new BrowserWindow({ @@ -41,22 +41,23 @@ app.on("ready", () => { global.options = { filter, + specs: [ SPEC_PATH ], runIn }; // Load the index.html of the app. mainWindow.loadURL(url.format({ - pathname: path.join(__dirname, "index.html"), + pathname: path.resolve(__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); }); + jasmine.execute(global.options.specs, filter); } else if(runIn === "render") { console.log("Running tests in the render process."); } else { diff --git a/tests/electron/app/renderer.js b/tests/electron/app/renderer.js index 14588078..1e5d29c1 100644 --- a/tests/electron/app/renderer.js +++ b/tests/electron/app/renderer.js @@ -4,9 +4,10 @@ const remote = require("electron").remote; const options = remote.getGlobal("options"); if (options.runIn === "render") { - const jasmine = require("./jasmine.js").execute(options.filter); + const jasmine = require("realm-tests/jasmine.js"); jasmine.onComplete((passed) => { // Add a delay if this happens too fast, to allow the WebDriver to connect first. remote.process.exit(passed ? 0 : -1); }); + jasmine.execute(options.specs, options.filter); } diff --git a/tests/shared/jasmine.js b/tests/shared/jasmine.js index 8767cfa6..8fee13c6 100644 --- a/tests/shared/jasmine.js +++ b/tests/shared/jasmine.js @@ -4,23 +4,22 @@ const Jasmine = require("jasmine"); const JasmineConsoleReporter = require('jasmine-console-reporter'); const path = require("path"); -const SPEC_PATH = path.join(__dirname, "..", "spec.js"); - -const ADMIN_TOKEN_PATH = path.join(__dirname, "..", "..", "..", "object-server-for-testing", "admin_token.base64"); +const ADMIN_TOKEN_PATH = path.resolve(__dirname, "../../../../object-server-for-testing/admin_token.base64"); process.env.ADMIN_TOKEN_PATH = ADMIN_TOKEN_PATH; -// console.log(require.resolve("realm-spec-helpers")); -exports.execute = (filter) => { - const jasmine = new Jasmine(); +const JASMIN_FILTER_KEY = "--filter"; - jasmine.clearReporters(); - jasmine.addReporter(new JasmineConsoleReporter({ - colors: 2, - cleanStack: 3, - verbosity: 4, - activity: false - })); - jasmine.execute([ SPEC_PATH ], filter); +function getFilterFromProcess() { + const filterArg = process.argv.find((arg) => arg.indexOf(JASMIN_FILTER_KEY) === 0); + return filterArg ? filterArg.slice(JASMIN_FILTER_KEY.length + 1) : null; +} - return jasmine; -}; +const jasmine = new Jasmine({ + projectBaseDir: __dirname +}); + +// Load the config file from the default path (${projectBaseDir}/spec/support/jasmine.json). +jasmine.loadConfigFile(); + +module.exports = jasmine; +module.exports.getFilterFromProcess = getFilterFromProcess;