From 1aec51cfae0cf1279a94d9d34e99d8ba6d550727 Mon Sep 17 00:00:00 2001 From: blagoev Date: Thu, 6 Apr 2017 11:00:29 +0300 Subject: [PATCH 1/3] fix tests not completing on failure --- tests/js/index.js | 2 +- tests/js/user-tests.js | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/js/index.js b/tests/js/index.js index 52f3af1e..5ad9b114 100644 --- a/tests/js/index.js +++ b/tests/js/index.js @@ -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); diff --git a/tests/js/user-tests.js b/tests/js/user-tests.js index 56eba1a2..91c0a250 100644 --- a/tests/js/user-tests.js +++ b/tests/js/user-tests.js @@ -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(); @@ -180,7 +179,6 @@ module.exports = { resolve(); }); }); - }); }, testLoginMissingUsername() { @@ -226,12 +224,11 @@ module.exports = { }, testAll() { - return new Promise((resolve, _reject) => { let all; all = Realm.Sync.User.all; TestCase.assertArrayLength(Object.keys(all), 0); - callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => { + return callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => { failOnError(error); all = Realm.Sync.User.all; @@ -259,14 +256,12 @@ module.exports = { resolve(); }); }); - }); }, testCurrent() { - 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) => { + return callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => { failOnError(error); assertIsSameUser(Realm.Sync.User.current, user1); @@ -283,7 +278,6 @@ module.exports = { resolve(); }); }); - }); }, testManagementRealm() { From 7486ecf029135e22b84c7b3aa02ea9204230e766 Mon Sep 17 00:00:00 2001 From: blagoev Date: Thu, 6 Apr 2017 14:25:40 +0300 Subject: [PATCH 2/3] fix user-tests --- tests/js/user-tests.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/js/user-tests.js b/tests/js/user-tests.js index 91c0a250..7eb1c84b 100644 --- a/tests/js/user-tests.js +++ b/tests/js/user-tests.js @@ -176,7 +176,6 @@ module.exports = { var realm = new Realm({ sync: { user: user, url: 'realm://localhost:9080/~/test' } }); TestCase.assertInstanceOf(realm, Realm); realm.close(); - resolve(); }); }); }, @@ -224,11 +223,12 @@ module.exports = { }, testAll() { + return new Promise((resolve, reject) => { let all; all = Realm.Sync.User.all; TestCase.assertArrayLength(Object.keys(all), 0); - return 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); all = Realm.Sync.User.all; @@ -252,32 +252,35 @@ module.exports = { user1.logout(); all = Realm.Sync.User.all; TestCase.assertArrayLength(Object.keys(all), 0); - resolve(); }); - }); + }).catch(e => reject(e)); + }); }, testCurrent() { - TestCase.assertUndefined(Realm.Sync.User.current); + return new Promise((resolve, reject) => { + TestCase.assertUndefined(Realm.Sync.User.current); - return 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() { From 4c9f88560e084e4aa398e2fc6ab633536af049ee Mon Sep 17 00:00:00 2001 From: blagoev Date: Thu, 6 Apr 2017 18:26:36 +0300 Subject: [PATCH 3/3] fix testCurrent user test --- tests/js/user-tests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/js/user-tests.js b/tests/js/user-tests.js index 7eb1c84b..a0b08cc7 100644 --- a/tests/js/user-tests.js +++ b/tests/js/user-tests.js @@ -279,8 +279,8 @@ module.exports = { resolve(); }); - }); - }).catch(e => reject(e)); + }).catch(e => reject(e)); + }); }, testManagementRealm() {