diff --git a/tests/electron/app/main.js b/tests/electron/app/main.js index 8445c39f..16d3ac24 100644 --- a/tests/electron/app/main.js +++ b/tests/electron/app/main.js @@ -13,7 +13,7 @@ const app = electron.app; // Module to create native browser window. const BrowserWindow = electron.BrowserWindow; -const SPEC_PATH = path.resolve(__dirname, "../spec.js"); +const SPEC_GLOB = path.resolve(__dirname, "../spec/*"); const JASMIN_FILTER_KEY = "--filter"; const MAIN_PROCESS_KEY = "--process"; @@ -41,7 +41,7 @@ app.on("ready", () => { global.options = { filter, - specs: [ SPEC_PATH ], + specs: [ SPEC_GLOB ], runIn }; diff --git a/tests/electron/spec.js b/tests/electron/spec.js deleted file mode 100644 index 868d74af..00000000 --- a/tests/electron/spec.js +++ /dev/null @@ -1,46 +0,0 @@ -"use strict"; - -const assert = require("assert"); -const path = require("path"); -const fs = require("fs"); - -const Realm = require("realm"); - -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); - }); - */ -}); - -require("realm-tests/spec/unit_tests"); diff --git a/tests/electron/spec/0-test-harness.js b/tests/electron/spec/0-test-harness.js new file mode 100644 index 00000000..afeccd3a --- /dev/null +++ b/tests/electron/spec/0-test-harness.js @@ -0,0 +1,52 @@ +"use strict"; + +const Realm = require("realm"); + +describe("Test harness", () => { + it("does have a chrome version", () => { + expect(process.versions.chrome).not.toBeUndefined(); + }); + + if(global.options && global.options.runIn === "main") { + describe("in the main process", () => { + it("does not have a window global", () => { + expect(global.window).toBeUndefined(); + }); + + it("does not have a navigator global", () => { + expect(global.navigator).toBeUndefined(); + }); + }); + } else { + describe("in the render process", () => { + it("does have a window global", () => { + expect(global.window).not.toBeUndefined(); + }); + + const userAgent = global.navigator.userAgent; + it("does have Electron in its userAgent", () => { + expect(userAgent.indexOf("Electron")).not.toBe(-1); + }); + + it("does have Chrome in its userAgent", () => { + expect(userAgent.indexOf("Chrome")).not.toBe(-1); + }); + }); + } + + it("waits for async tests to complete", (done) => { + setTimeout(() => { + done(); + }, 1000); + }); + + describe("loading Realm", () => { + it("exports a function", () => { + expect(typeof(Realm)).toBe("function"); + }); + + it("exports a constructor named Realm", () => { + expect(Realm.name).toBe("Realm"); + }); + }); +}); diff --git a/tests/shared/js/garbage-collection.js b/tests/electron/spec/1-garbage-collection.js similarity index 83% rename from tests/shared/js/garbage-collection.js rename to tests/electron/spec/1-garbage-collection.js index e257b23d..43aae6a5 100644 --- a/tests/shared/js/garbage-collection.js +++ b/tests/electron/spec/1-garbage-collection.js @@ -27,25 +27,25 @@ 'use strict'; const Realm = require('realm'); -const TestCase = require('./asserts'); const NUMBER_OF_OBJECTS = 1000; const BUFFER_LENGTH = 1024; const READ_CYCLES = 10; -module.exports = { - testPropertiesOfData: () => { +describe("Electron garbage collection", () => { + const TestingSchema = { + name: 'Testing', + properties: { + n: 'int', + someData: 'data' + } + }; - const TestingSchema = { - name: 'Testing', - properties: { - n: 'int', - someData: 'data' - } - }; + let realm; + beforeEach(() => { // Create a new realm - const realm = new Realm({schema: [TestingSchema]}); + realm = new Realm({schema: [TestingSchema]}); // Add a bunch of objects, with "data" to it realm.write(() => { for(let i = 0; i < NUMBER_OF_OBJECTS; i++) { @@ -55,7 +55,9 @@ module.exports = { }); } }); + }); + it("should not crash when arrays are freed", () => { for (let readCycle = 0; readCycle < READ_CYCLES; readCycle++) { let allObjects = realm.objects('Testing'); let totalBytes = 0; @@ -64,7 +66,9 @@ module.exports = { // Accessing the byteLength of the objects someData property totalBytes += toBeFreed.byteLength; } + // console.log(`Read a total of ${totalBytes} bytes.`); + expect(totalBytes).toBe(NUMBER_OF_OBJECTS * BUFFER_LENGTH); } - } -}; + }); +}); diff --git a/tests/electron/spec/3-unit-tests.js b/tests/electron/spec/3-unit-tests.js new file mode 100644 index 00000000..eb822f5d --- /dev/null +++ b/tests/electron/spec/3-unit-tests.js @@ -0,0 +1,9 @@ +"use strict"; + +const assert = require("assert"); +const path = require("path"); +const fs = require("fs"); + +describe("Realm JS unit tests", () => { + require("realm-tests/spec/unit_tests"); +}); diff --git a/tests/shared/js/index.js b/tests/shared/js/index.js index db72b82c..fcecb063 100644 --- a/tests/shared/js/index.js +++ b/tests/shared/js/index.js @@ -51,13 +51,6 @@ if (isNodeProcess) { console.log("Skipping the AsyncTests"); } -const isElectronProcess = process && process.versions && !!process.versions.electron; -if (isElectronProcess) { - TESTS.GarbageCollectionTests = require('./garbage-collection'); -} else { - console.log("Skipping the Electron specific GarbageCollectionTests"); -} - var SPECIAL_METHODS = { beforeEach: true, afterEach: true,