Adapted the electron tests to use the shared files more

This commit is contained in:
Kræn Hansen 2017-08-11 11:59:34 +02:00
parent a4f48b5876
commit f0df9a51dd
3 changed files with 6 additions and 58 deletions

View File

@ -1,5 +1,5 @@
{ {
"name": "realm-js-electron-tests", "name": "realm-electron-tests",
"private": true, "private": true,
"description": "Test harness running the Realm JS tests in the Electron renderer process.", "description": "Test harness running the Realm JS tests in the Electron renderer process.",
"main": "index.js", "main": "index.js",
@ -11,10 +11,8 @@
"devDependencies": { "devDependencies": {
"electron": "^1.6.11", "electron": "^1.6.11",
"electron-rebuild": "^1.6.0", "electron-rebuild": "^1.6.0",
"jasmine": "../node_modules/jasmine",
"jasmine-console-reporter": "../node_modules/jasmine-console-reporter",
"realm": "../..", "realm": "../..",
"realm-tests": "../js", "realm-tests": "../shared",
"spectron": "^3.7.2" "spectron": "^3.7.2"
} }
} }

View File

@ -4,8 +4,8 @@ const assert = require("assert");
const path = require("path"); const path = require("path");
const Application = require("spectron").Application; const Application = require("spectron").Application;
const ELECTRON_PATH = path.join(__dirname, "node_modules", ".bin", "electron"); const ELECTRON_PATH = path.resolve(__dirname, "node_modules/.bin/electron");
const MAIN_PATH = path.join(__dirname, "app", "main.js"); const MAIN_PATH = path.resolve(__dirname, "app/main.js");
const POLL_LOG_DELAY = 500; const POLL_LOG_DELAY = 500;
const filterOption = process.argv[2] || null; const filterOption = process.argv[2] || null;
@ -17,10 +17,9 @@ const app = new Application({
args: [ MAIN_PATH ].concat(process.argv.slice(2)) 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(() => { app.start().then(() => {
console.log("The following messages are logs from the Electron process:");
// Keep reading the log, until Jasmine prints "ALL DONE" // Keep reading the log, until Jasmine prints "ALL DONE"
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const timeout = setInterval(() => { const timeout = setInterval(() => {

View File

@ -5,7 +5,6 @@ const path = require("path");
const fs = require("fs"); const fs = require("fs");
const Realm = require("realm"); const Realm = require("realm");
const RealmTests = require("realm-tests");
describe("Test harness", () => { describe("Test harness", () => {
if(global.options && global.options.runIn === "main") { 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. require("realm-tests/spec/unit_tests");
// 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'));
});
}