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) { if (testMethod) {
// Start fresh in case of a crash in a previous run. // Start fresh in case of a crash in a previous run.
Realm.clearTestState(); Realm.clearTestState();
console.log("Starting test " + testName);
var promise; var promise;
try { try {
promise = testMethod.call(testSuite); promise = testMethod.call(testSuite);

View File

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