2016-04-19 08:38:46 +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.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/* eslint-env es6, node */
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2016-04-14 19:39:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-13 23:30:57 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2016-04-14 19:39:17 +00:00
|
|
|
const mockery = require('mockery');
|
|
|
|
|
|
|
|
function runTests() {
|
2016-05-13 23:30:57 +00:00
|
|
|
const Realm = require('realm');
|
2016-04-14 19:39:17 +00:00
|
|
|
const RealmTests = require('./js');
|
2016-04-26 09:04:13 +00:00
|
|
|
|
|
|
|
RealmTests.registerTests({
|
|
|
|
WorkerTests: require('./js/worker-tests'),
|
|
|
|
});
|
|
|
|
|
2016-04-14 19:39:17 +00:00
|
|
|
const testNames = RealmTests.getTestNames();
|
2016-04-19 23:53:49 +00:00
|
|
|
let passed = true;
|
2016-04-14 19:39:17 +00:00
|
|
|
|
2016-05-13 23:30:57 +00:00
|
|
|
// Create this method with appropriate implementation for Node testing.
|
|
|
|
Realm.copyBundledRealmFiles = function() {
|
|
|
|
let sourceDir = path.join(__dirname, 'data');
|
|
|
|
let 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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-26 07:10:21 +00:00
|
|
|
return Object.keys(testNames).reduce((suitePromiseChain, suiteName) => {
|
|
|
|
return suitePromiseChain.then(() => {
|
|
|
|
console.log('Starting ' + suiteName);
|
2016-04-14 19:39:17 +00:00
|
|
|
|
2016-04-26 07:10:21 +00:00
|
|
|
return testNames[suiteName].reduce((testPromiseChain, testName) => {
|
|
|
|
return testPromiseChain.then(() => {
|
|
|
|
return RealmTests.runTest(suiteName, 'beforeEach');
|
|
|
|
}).then(() => {
|
|
|
|
return RealmTests.runTest(suiteName, testName);
|
|
|
|
}).then(() => {
|
|
|
|
console.log('+ ' + testName);
|
|
|
|
}, (err) => {
|
|
|
|
console.warn('- ' + testName);
|
|
|
|
console.warn(err.message || err);
|
|
|
|
passed = false;
|
|
|
|
}).then(() => {
|
|
|
|
return RealmTests.runTest(suiteName, 'afterEach');
|
|
|
|
});
|
|
|
|
}, Promise.resolve());
|
|
|
|
});
|
|
|
|
}, Promise.resolve()).then(() => passed);
|
2016-04-14 19:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main == module) {
|
|
|
|
mockery.enable();
|
|
|
|
mockery.warnOnUnregistered(false);
|
|
|
|
mockery.registerMock('realm', require('..'));
|
|
|
|
|
2016-04-26 07:10:21 +00:00
|
|
|
runTests().then(
|
|
|
|
(passed) => {
|
|
|
|
if (!passed) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
);
|
2016-04-14 19:39:17 +00:00
|
|
|
}
|