2016-02-18 19:59:34 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright 2016 Realm Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2015-10-02 21:57:54 +00:00
|
|
|
|
2015-10-06 07:57:35 +00:00
|
|
|
'use strict';
|
2015-10-02 22:15:25 +00:00
|
|
|
|
2017-09-20 18:06:09 +00:00
|
|
|
const Realm = require('realm');
|
|
|
|
|
|
|
|
// FIXME: sync testing needs to be updated for ROS 2.0
|
|
|
|
global.enableSyncTests = Realm.Sync && false;
|
2016-05-20 22:54:20 +00:00
|
|
|
|
2016-02-15 22:22:40 +00:00
|
|
|
var TESTS = {
|
|
|
|
ListTests: require('./list-tests'),
|
2017-06-29 09:59:10 +00:00
|
|
|
LinkingObjectsTests: require('./linkingobjects-tests'),
|
2016-02-15 22:22:40 +00:00
|
|
|
ObjectTests: require('./object-tests'),
|
|
|
|
RealmTests: require('./realm-tests'),
|
|
|
|
ResultsTests: require('./results-tests'),
|
|
|
|
QueryTests: require('./query-tests'),
|
2017-08-11 08:30:57 +00:00
|
|
|
MigrationTests: require('./migration-tests'),
|
|
|
|
// GarbageCollectionTests: require('./garbage-collection'),
|
2016-02-15 22:22:40 +00:00
|
|
|
};
|
2015-10-15 01:52:55 +00:00
|
|
|
|
2017-03-07 22:24:30 +00:00
|
|
|
// encryption is not supported on windows
|
|
|
|
if (!(typeof process === 'object' && process.platform === 'win32')) {
|
|
|
|
TESTS.EncryptionTests = require('./encryption-tests');
|
|
|
|
}
|
|
|
|
|
2017-06-20 13:40:54 +00:00
|
|
|
// If sync is enabled, run the sync tests
|
2017-09-20 18:06:09 +00:00
|
|
|
if (global.enableSyncTests) {
|
2017-01-31 13:07:29 +00:00
|
|
|
TESTS.UserTests = require('./user-tests');
|
2017-02-01 13:18:59 +00:00
|
|
|
TESTS.SessionTests = require('./session-tests');
|
2017-08-29 13:23:22 +00:00
|
|
|
|
|
|
|
// FIXME: Permission tests currently fail in chrome debugging mode.
|
|
|
|
if (typeof navigator === 'undefined' ||
|
2017-09-20 23:38:22 +00:00
|
|
|
!/Chrome/.test(navigator.userAgent)) { // eslint-disable-line no-undef
|
2017-09-21 12:40:31 +00:00
|
|
|
|
|
|
|
TESTS.PermissionTests = require('./permission-tests');
|
2017-08-29 13:23:22 +00:00
|
|
|
}
|
2017-05-11 20:31:50 +00:00
|
|
|
}
|
2017-01-31 13:07:29 +00:00
|
|
|
|
2017-07-06 09:27:01 +00:00
|
|
|
function node_require(module) { return require(module); }
|
2017-01-31 13:07:29 +00:00
|
|
|
|
|
|
|
// If on node, run the async tests
|
2017-07-07 13:38:13 +00:00
|
|
|
const isNodeProcess = typeof process === 'object' && process + '' === '[object process]';
|
|
|
|
if (isNodeProcess) {
|
2017-09-18 22:07:28 +00:00
|
|
|
TESTS.AsyncTests = node_require('./async-tests');
|
2017-01-31 13:07:29 +00:00
|
|
|
}
|
|
|
|
|
2015-10-15 18:34:24 +00:00
|
|
|
var SPECIAL_METHODS = {
|
|
|
|
beforeEach: true,
|
|
|
|
afterEach: true,
|
|
|
|
};
|
|
|
|
|
2016-02-15 22:22:40 +00:00
|
|
|
exports.getTestNames = function() {
|
|
|
|
var testNames = {};
|
|
|
|
|
|
|
|
for (var suiteName in TESTS) {
|
|
|
|
var testSuite = TESTS[suiteName];
|
|
|
|
|
|
|
|
testNames[suiteName] = Object.keys(testSuite).filter(function(testName) {
|
|
|
|
return !(testName in SPECIAL_METHODS) && typeof testSuite[testName] == 'function';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return testNames;
|
|
|
|
};
|
|
|
|
|
2016-02-15 22:37:19 +00:00
|
|
|
exports.registerTests = function(tests) {
|
|
|
|
for (var suiteName in tests) {
|
|
|
|
TESTS[suiteName] = tests[suiteName];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-06 09:27:01 +00:00
|
|
|
exports.prepare = function(done) {
|
2017-09-20 18:06:09 +00:00
|
|
|
if (!global.enableSyncTests || !isNodeProcess || global.testAdminUserInfo) {
|
2017-07-07 09:16:12 +00:00
|
|
|
done();
|
2017-07-12 00:11:49 +00:00
|
|
|
return;
|
2017-07-07 07:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 17:17:39 +00:00
|
|
|
require('./admin-user-helper')
|
|
|
|
.createAdminUser()
|
|
|
|
.then(userInfo => {
|
|
|
|
global.testAdminUserInfo = userInfo;
|
2017-07-06 09:27:01 +00:00
|
|
|
done();
|
2017-08-31 17:17:39 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error("Error running admin-user-helper", error);
|
|
|
|
done.fail(error);
|
2017-07-06 09:27:01 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-02-15 22:22:40 +00:00
|
|
|
exports.runTest = function(suiteName, testName) {
|
|
|
|
var testSuite = TESTS[suiteName];
|
|
|
|
var testMethod = testSuite && testSuite[testName];
|
|
|
|
|
|
|
|
if (testMethod) {
|
2016-05-20 22:54:20 +00:00
|
|
|
// Start fresh in case of a crash in a previous run.
|
|
|
|
Realm.clearTestState();
|
2017-04-06 08:00:29 +00:00
|
|
|
console.log("Starting test " + testName);
|
2016-02-18 19:19:13 +00:00
|
|
|
var promise;
|
2016-05-20 22:54:20 +00:00
|
|
|
try {
|
2016-02-18 19:19:13 +00:00
|
|
|
promise = testMethod.call(testSuite);
|
|
|
|
|
|
|
|
// If the test returns a promise, then clear state on success or failure.
|
|
|
|
if (promise) {
|
|
|
|
promise.then(
|
|
|
|
function() { Realm.clearTestState(); },
|
|
|
|
function() { Realm.clearTestState(); }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise;
|
2016-05-20 22:54:20 +00:00
|
|
|
} finally {
|
2016-02-18 19:19:13 +00:00
|
|
|
// Synchronously clear state if the test is not async.
|
|
|
|
if (!promise) {
|
|
|
|
Realm.clearTestState();
|
|
|
|
}
|
2016-05-20 22:54:20 +00:00
|
|
|
}
|
2016-02-15 22:22:40 +00:00
|
|
|
} else if (!testSuite || !(testName in SPECIAL_METHODS)) {
|
|
|
|
throw new Error('Missing test: ' + suiteName + '.' + testName);
|
|
|
|
}
|
2017-07-06 09:27:01 +00:00
|
|
|
}
|