Kræn Hansen e4e1431c55 Running js tests in Electron renderer process (#1196)
* First take on running the tests inside an Electron render process

* Making progress

* Making it possible to override the location of the admin token

* Ignoreing the realm-object-server files

* Fixing a console.log to return a string instead of a boolean

But it should probably be removed entirely

* Making the downloaded ROS log less

* Adjusting comments in the test.sh

* Checking number of windows to determine an Electron crash

* Added a test that triggers garbage collection of ArrayBuffers

* Enabled the ability to run the tests in Electrons main process

* Run tests first in main process and the render

* Added a README.md that documents how Electron tests can be run

* Added a comment on why the garbage-collection test was added.

* Waiting with reading the admin token, until it is actually used

* Disabling the GarbageCollectionTests for now
2017-08-11 10:30:57 +02:00

96 lines
2.6 KiB
JavaScript

"use strict";
const assert = require("assert");
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") {
it("runs the test in the main process", () => {
assert(process.versions.chrome, "Expected a chrome version");
assert(!global.window, "Expected no window constant");
assert(!global.navigator, "Expected no navigator global");
});
} else {
it("runs the test in the browser process", () => {
assert(process.versions.chrome, "Expected a chrome version");
assert(global.window, "Expected a window constant");
const userAgent = global.navigator.userAgent;
assert(userAgent.indexOf("Electron") >= 0, "Expected Electron in the user-agent");
assert(userAgent.indexOf("Chrome") >= 0, "Expected Chrome in the user-agent");
});
}
it("waits for async tests to complete", (done) => {
setTimeout(() => {
done();
}, 1000);
});
it("loads Realm", () => {
assert(Realm);
assert.equal(typeof(Realm), "function");
assert.equal(Realm.name, "Realm");
});
/*
it("fails", (done) => {
assert(false);
});
*/
});
// 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'));
});
}