Allow Node tests to be asynchronous

This commit is contained in:
Scott Kyle 2016-04-26 00:10:21 -07:00
parent 723b50f649
commit b42f5ab285

View File

@ -50,28 +50,27 @@ function runTests() {
}
};
for (let suiteName in testNames) {
console.log('Starting ' + suiteName);
return Object.keys(testNames).reduce((suitePromiseChain, suiteName) => {
return suitePromiseChain.then(() => {
console.log('Starting ' + suiteName);
for (let testName of testNames[suiteName]) {
RealmTests.runTest(suiteName, 'beforeEach');
try {
RealmTests.runTest(suiteName, testName);
console.log('+ ' + testName);
}
catch (e) {
console.warn('- ' + testName);
console.error(e.message, e.stack);
passed = false;
}
finally {
RealmTests.runTest(suiteName, 'afterEach');
}
}
}
return passed;
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);
}
if (require.main == module) {
@ -79,7 +78,15 @@ if (require.main == module) {
mockery.warnOnUnregistered(false);
mockery.registerMock('realm', require('..'));
if (!runTests()) {
process.exit(1);
}
runTests().then(
(passed) => {
if (!passed) {
process.exit(1);
}
},
(err) => {
console.error(err);
process.exit(1);
}
);
}