mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-10 22:36:01 +00:00
Moved Garbage Collection tests to the electron folder
This commit is contained in:
parent
b37fc3f2b0
commit
ee92ba156c
@ -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
|
||||
};
|
||||
|
||||
|
@ -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");
|
52
tests/electron/spec/0-test-harness.js
Normal file
52
tests/electron/spec/0-test-harness.js
Normal file
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
9
tests/electron/spec/3-unit-tests.js
Normal file
9
tests/electron/spec/3-unit-tests.js
Normal file
@ -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");
|
||||
});
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user