From f0df9a51ddbc89a770486fe2dfa762d02563a864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Fri, 11 Aug 2017 11:59:34 +0200 Subject: [PATCH] Adapted the electron tests to use the shared files more --- tests/electron/package.json | 6 ++--- tests/electron/runner.js | 7 +++-- tests/electron/spec.js | 51 +------------------------------------ 3 files changed, 6 insertions(+), 58 deletions(-) diff --git a/tests/electron/package.json b/tests/electron/package.json index 1be4a323..d148f4c0 100644 --- a/tests/electron/package.json +++ b/tests/electron/package.json @@ -1,5 +1,5 @@ { - "name": "realm-js-electron-tests", + "name": "realm-electron-tests", "private": true, "description": "Test harness running the Realm JS tests in the Electron renderer process.", "main": "index.js", @@ -11,10 +11,8 @@ "devDependencies": { "electron": "^1.6.11", "electron-rebuild": "^1.6.0", - "jasmine": "../node_modules/jasmine", - "jasmine-console-reporter": "../node_modules/jasmine-console-reporter", "realm": "../..", - "realm-tests": "../js", + "realm-tests": "../shared", "spectron": "^3.7.2" } } diff --git a/tests/electron/runner.js b/tests/electron/runner.js index ac7ab24e..deb3bec4 100644 --- a/tests/electron/runner.js +++ b/tests/electron/runner.js @@ -4,8 +4,8 @@ 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 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; @@ -17,10 +17,9 @@ const app = new Application({ args: [ MAIN_PATH ].concat(process.argv.slice(2)) }); -console.log("Trying to start an Electron process."); +console.log("Starting 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(() => { diff --git a/tests/electron/spec.js b/tests/electron/spec.js index 5c7be1a9..868d74af 100644 --- a/tests/electron/spec.js +++ b/tests/electron/spec.js @@ -5,7 +5,6 @@ const path = require("path"); const fs = require("fs"); const Realm = require("realm"); -const RealmTests = require("realm-tests"); describe("Test harness", () => { if(global.options && global.options.runIn === "main") { @@ -44,52 +43,4 @@ describe("Test harness", () => { */ }); -// Almost a copy-paste from the ../spec/unit_tests.js - so it might be possible to generalize. - -// Setting the timeout to the same as the ../../spec/unit_tests.js -jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; - -Realm.copyBundledRealmFiles = function() { - const sourceDir = path.join(__dirname, '../data'); - const destinationDir = path.dirname(Realm.defaultPath); - - for (let filename of fs.readdirSync(sourceDir)) { - let src = path.join(sourceDir, filename); - let dest = path.join(destinationDir, filename); - - // If the destination file already exists, then don't overwrite it. - try { - fs.accessSync(dest); - continue; - } catch (e) {} - - fs.writeFileSync(dest, fs.readFileSync(src)); - } -}; - -const tests = RealmTests.getTestNames(); -for (const suiteName in tests) { - describe(suiteName, () => { - - beforeAll(done => RealmTests.prepare(done)); - - beforeEach(() => RealmTests.runTest(suiteName, 'beforeEach')); - - for (const testName of tests[suiteName]) { - it(testName, (done) => { - try { - let result = RealmTests.runTest(suiteName, testName); - if (result instanceof Promise) { - result.then(done, done.fail.bind(done)); - } else { - done(); - } - } catch (e) { - done.fail(e); - } - }); - } - - afterEach(() => RealmTests.runTest(suiteName, 'afterEach')); - }); -} +require("realm-tests/spec/unit_tests");