mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-22 11:18:15 +00:00
Allow React tests to be async
This commit is contained in:
parent
6d524107e0
commit
723b50f649
@ -63,10 +63,24 @@ exports.runTest = function(suiteName, testName) {
|
||||
// Start fresh in case of a crash in a previous run.
|
||||
Realm.clearTestState();
|
||||
|
||||
var promise;
|
||||
try {
|
||||
testMethod.call(testSuite);
|
||||
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;
|
||||
} finally {
|
||||
Realm.clearTestState();
|
||||
// Synchronously clear state if the test is not async.
|
||||
if (!promise) {
|
||||
Realm.clearTestState();
|
||||
}
|
||||
}
|
||||
} else if (!testSuite || !(testName in SPECIAL_METHODS)) {
|
||||
throw new Error('Missing test: ' + suiteName + '.' + testName);
|
||||
|
@ -48,7 +48,7 @@ async function runTests() {
|
||||
itemTest.att('name', testName);
|
||||
|
||||
try {
|
||||
runTest(suiteName, testName);
|
||||
await runTest(suiteName, testName);
|
||||
}
|
||||
catch (e) {
|
||||
itemTest.ele('error', {'message': ''}, e.message);
|
||||
|
16
tests/react-test-app/tests/index.js
vendored
16
tests/react-test-app/tests/index.js
vendored
@ -27,10 +27,10 @@ RealmTests.registerTests({
|
||||
});
|
||||
|
||||
// Listen for event to run a particular test.
|
||||
NativeAppEventEmitter.addListener('realm-run-test', (test) => {
|
||||
NativeAppEventEmitter.addListener('realm-run-test', async ({suite, name}) => {
|
||||
let error;
|
||||
try {
|
||||
RealmTests.runTest(test.suite, test.name);
|
||||
await RealmTests.runTest(suite, name);
|
||||
} catch (e) {
|
||||
error = '' + e;
|
||||
}
|
||||
@ -50,23 +50,23 @@ export function getTestNames() {
|
||||
return RealmTests.getTestNames();
|
||||
}
|
||||
|
||||
export function runTests() {
|
||||
export async function runTests() {
|
||||
let testNames = getTestNames();
|
||||
|
||||
for (let suiteName in testNames) {
|
||||
console.log('Starting ' + suiteName);
|
||||
|
||||
for (let testName of testNames[suiteName]) {
|
||||
runTest(suiteName, testName);
|
||||
await runTest(suiteName, testName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function runTest(suiteName, testName) {
|
||||
RealmTests.runTest(suiteName, 'beforeEach');
|
||||
export async function runTest(suiteName, testName) {
|
||||
await RealmTests.runTest(suiteName, 'beforeEach');
|
||||
|
||||
try {
|
||||
RealmTests.runTest(suiteName, testName);
|
||||
await RealmTests.runTest(suiteName, testName);
|
||||
console.log('+ ' + testName);
|
||||
}
|
||||
catch (e) {
|
||||
@ -75,6 +75,6 @@ export function runTest(suiteName, testName) {
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
RealmTests.runTest(suiteName, 'afterEach');
|
||||
await RealmTests.runTest(suiteName, 'afterEach');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user