Merge pull request #961 from realm/fix-tests

fix tests not completing on failure
This commit is contained in:
blagoev 2017-04-06 22:56:05 +03:00 committed by GitHub
commit 2ca08161f8
2 changed files with 20 additions and 23 deletions

View File

@ -80,7 +80,7 @@ exports.runTest = function(suiteName, testName) {
if (testMethod) {
// Start fresh in case of a crash in a previous run.
Realm.clearTestState();
console.log("Starting test " + testName);
var promise;
try {
promise = testMethod.call(testSuite);

View File

@ -162,10 +162,9 @@ module.exports = {
},
testLogin() {
return new Promise((resolve, _reject) => {
var username = uuid();
// Create user, logout the new user, then login
callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', username, 'password', callback), (error, user) => {
return callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', username, 'password', callback), (error, user) => {
failOnError(error);
user.logout();
@ -177,10 +176,8 @@ module.exports = {
var realm = new Realm({ sync: { user: user, url: 'realm://localhost:9080/~/test' } });
TestCase.assertInstanceOf(realm, Realm);
realm.close();
resolve();
});
});
});
},
testLoginMissingUsername() {
@ -226,7 +223,7 @@ module.exports = {
},
testAll() {
return new Promise((resolve, _reject) => {
return new Promise((resolve, reject) => {
let all;
all = Realm.Sync.User.all;
TestCase.assertArrayLength(Object.keys(all), 0);
@ -255,35 +252,35 @@ module.exports = {
user1.logout();
all = Realm.Sync.User.all;
TestCase.assertArrayLength(Object.keys(all), 0);
resolve();
});
});
}).catch(e => reject(e));
});
},
testCurrent() {
return new Promise((resolve, _reject) => {
TestCase.assertUndefined(Realm.Sync.User.current);
return new Promise((resolve, reject) => {
TestCase.assertUndefined(Realm.Sync.User.current);
callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => {
failOnError(error);
assertIsSameUser(Realm.Sync.User.current, user1);
Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user2) => {
callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => {
failOnError(error);
TestCase.assertThrows(() => Realm.Sync.User.current, 'We expect Realm.Sync.User.current to throw if > 1 user.');
user2.logout();
assertIsSameUser(Realm.Sync.User.current, user1);
user1.logout();
TestCase.assertUndefined(Realm.Sync.User.current);
Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user2) => {
failOnError(error);
TestCase.assertThrows(() => Realm.Sync.User.current, 'We expect Realm.Sync.User.current to throw if > 1 user.');
user2.logout();
resolve();
});
assertIsSameUser(Realm.Sync.User.current, user1);
user1.logout();
TestCase.assertUndefined(Realm.Sync.User.current);
resolve();
});
}).catch(e => reject(e));
});
});
},
testManagementRealm() {