Commit 2d2768e3 authored by Eric Eastwood's avatar Eric Eastwood

Update to Mocha@5.x for better debugging, `--inspect`

I upgraded so we have access to the Node inspector args, `--inspect`, `--inspect-brk`, https://nodejs.org/en/docs/guides/debugging-getting-started/

This worked previously because Mocha would force exit but this changed in Mocha v4, https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit
parent 1deddf96
# 19.13.0 - *upcoming*
Developer facing:
- Update to Mocha@5.x for better debugging, `--inspect` (node inspector devtools), https://gitlab.com/gitlab-org/gitter/webapp/merge_requests/1212
# 19.12.0 - 2018-7-23
- Update `@gitterhq/services@1.21.0` (integrations), https://gitlab.com/gitlab-org/gitter/webapp/merge_requests/1078
......
......@@ -131,7 +131,7 @@ function spawnMochaProcess(moduleName, options, files) { // eslint-disable-line
'output/coverage-reports/' + moduleName,
'--reporter',
'lcov',
'./node_modules/.bin/mocha'
'./node_modules/.bin/mocha',
];
mkdirp.sync('output/coverage-reports/' + moduleName);
......@@ -140,6 +140,9 @@ function spawnMochaProcess(moduleName, options, files) { // eslint-disable-line
args = [];
}
// This is needed because Mocha no longer force exits, https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit
args.push('--exit');
if (testSuite === 'docker') {
env.HOME = '/tmp'; // Needs to be writeable inside docker for `nyc`
env.NODE_ENV = 'test-docker';
......
......@@ -38,12 +38,11 @@ var fakeEngine = {
describe('presenceService', function () {
function cleanup(done) {
function cleanup() {
return presenceService.collectGarbage(fakeEngine)
.then(function () {
return presenceService.validateUsers();
})
.nodeify(done);
});
}
beforeEach(cleanup);
......
......@@ -10,18 +10,17 @@ describe('push-notification-filter', function() {
});
describe('findUsersInRoomAcceptingNotifications', function() {
it('should not filter users who have received no notifications', function(done) {
it('should not filter users who have received no notifications', function() {
var userId1 = 'TEST_USER1_' + Date.now();
var troupeId = 'TEST_TROUPE1_' + Date.now();
return pushNotificationFilter.findUsersInRoomAcceptingNotifications(troupeId, [userId1])
.then(function(result) {
assert.deepEqual(result, [userId1]); // Notify
})
.nodeify(done);
});
});
it('should filter users who have received notifications', function(done) {
it('should filter users who have received notifications', function() {
var userId1 = 'TEST_USER1_' + Date.now();
var troupeId = 'TEST_TROUPE1_' + Date.now();
var MAX_LOCK_VALUE = 2;
......@@ -68,13 +67,12 @@ describe('push-notification-filter', function() {
})
.then(function(result) {
assert.deepEqual(result, [userId1]);
})
.nodeify(done);
});
});
});
describe('Notification Locking', function() {
it('should lock user troupe pairs so that users dont get too many notifications', function(done) {
it('should lock user troupe pairs so that users dont get too many notifications', function() {
var userId = 'TEST_USER1_' + Date.now();
var troupeId = 'TEST_TROUPE1_' + Date.now();
var startTime = Date.now();
......@@ -121,12 +119,10 @@ describe('push-notification-filter', function() {
})
.then(function(st) {
assert.equal(st, startTime);
})
.nodeify(done);
});
});
it('should handle notification resets', function(done) {
it('should handle notification resets', function() {
var userId = 'TEST_USER1_' + Date.now();
var troupeId = 'TEST_TROUPE1_' + Date.now();
var startTime = Date.now();
......@@ -154,13 +150,12 @@ describe('push-notification-filter', function() {
})
.then(function(st) {
assert.equal(st, 0);
})
.nodeify(done);
});
});
});
it('should set the expiry correctly on the redis keys', function(done) {
it('should set the expiry correctly on the redis keys', function() {
var userId = 'TEST_USER1_' + Date.now();
var troupeId = 'TEST_TROUPE1_' + Date.now();
var startTime = Date.now();
......@@ -195,8 +190,7 @@ describe('push-notification-filter', function() {
assert.strictEqual(exists, 0);
return pushNotificationFilter.canUnlockForNotification(userId, troupeId, 1);
})
.nodeify(done);
});
});
});
......@@ -17,14 +17,14 @@ describe('recent-room-core', function() {
troupe4: { users: ['user1'] }
});
it('should rearrange the order of favourites correctly',function(done) {
it('should rearrange the order of favourites correctly',function() {
this.timeout(10000);
function getFavs() {
return recentRoomCore.findFavouriteTroupesForUser(fixture.user1.id);
}
recentRoomCore.updateFavourite(fixture.user1.id, fixture.troupe1.id, 1)
return recentRoomCore.updateFavourite(fixture.user1.id, fixture.troupe1.id, 1)
.then(getFavs)
.then(function(favs) {
assert.equal(favs[fixture.troupe1.id], 1);
......@@ -81,9 +81,7 @@ describe('recent-room-core', function() {
assert.equal(favs[fixture.troupe3.id], 2);
assert.equal(favs[fixture.troupe2.id], 3);
assert.equal(favs[fixture.troupe1.id], 4);
})
.nodeify(done);
});
});
});
......@@ -94,9 +92,9 @@ describe('recent-room-core', function() {
troupe1: { users: ['user1'] }
});
it('should add a troupe to favourites',function(done) {
it('should add a troupe to favourites',function() {
function fav(val, callback) {
function fav(val) {
return recentRoomCore.updateFavourite(fixture.user1.id, fixture.troupe1.id, val)
.then(function() {
return recentRoomCore.findFavouriteTroupesForUser(fixture.user1.id);
......@@ -104,20 +102,13 @@ describe('recent-room-core', function() {
.then(function(favs) {
var isInTroupe = !!favs[fixture.troupe1.id];
assert(isInTroupe === val, 'Troupe should ' + (val? '': 'not ') + 'be a favourite');
})
.nodeify(callback);
}
fav(true, function() {
fav(true, function() {
fav(false, function() {
fav(false, function() {
done();
});
});
});
});
}
return fav(true)
.then(() => fav(true))
.then(() => fav(false))
.then(() => fav(true));
});
});
......@@ -129,16 +120,15 @@ describe('recent-room-core', function() {
troupe1: { users: ['user1'] }
});
it('should handle default values', function(done) {
it('should handle default values', function() {
return recentRoomCore.findLastAccessTimesForUsersInRoom(fixture.troupe1.id, [fixture.user1.id, fixture.user2._id])
.then(function(result) {
assert(result[fixture.user1.id]);
assert(result[fixture.user2.id]);
})
.nodeify(done);
});
});
it('should handle non default values', function(done) {
it('should handle non default values', function() {
return Promise.all([
recentRoomCore.saveUserTroupeLastAccess(fixture.user1.id, fixture.troupe1.id),
recentRoomCore.saveUserTroupeLastAccess(fixture.user2.id, fixture.troupe1.id)
......@@ -154,8 +144,7 @@ describe('recent-room-core', function() {
assert(d2 >= 0);
assert(d2 < 5000);
})
.nodeify(done);
});
});
});
......
......@@ -20,14 +20,14 @@ describe('recent-room-service', function() {
troupe4: { users: ['user1'] }
});
it('should rearrange the order of favourites correctly',function(done) {
it('should rearrange the order of favourites correctly',function() {
this.timeout(10000);
function getFavs() {
return recentRoomCore.findFavouriteTroupesForUser(fixture.user1.id);
}
recentRoomService.updateFavourite(fixture.user1.id, fixture.troupe1.id, 1)
return recentRoomService.updateFavourite(fixture.user1.id, fixture.troupe1.id, 1)
.then(getFavs)
.then(function(favs) {
assert.equal(favs[fixture.troupe1.id], 1);
......@@ -84,9 +84,7 @@ describe('recent-room-service', function() {
assert.equal(favs[fixture.troupe3.id], 2);
assert.equal(favs[fixture.troupe2.id], 3);
assert.equal(favs[fixture.troupe1.id], 4);
})
.nodeify(done);
});
});
});
......@@ -97,29 +95,23 @@ describe('recent-room-service', function() {
troupe1: { users: ['user1'] }
});
it('should add a troupe to favourites',function(done) {
it('should add a troupe to favourites',function() {
function fav(val, callback) {
function fav(val) {
return recentRoomService.updateFavourite(fixture.user1.id, fixture.troupe1.id, val)
.then(function() {
return recentRoomService.findFavouriteTroupesForUser(fixture.user1.id);
return recentRoomCore.findFavouriteTroupesForUser(fixture.user1.id);
})
.then(function(favs) {
var isInTroupe = !!favs[fixture.troupe1.id];
assert(isInTroupe === val, 'Troupe should ' + (val? '': 'not ') + 'be a favourite');
})
.nodeify(callback);
});
}
fav(true, function() {
fav(true, function() {
fav(false, function() {
fav(false, function() {
done();
});
});
});
});
return fav(true)
.then(() => fav(true))
.then(() => fav(false))
.then(() => fav(true));
});
......@@ -131,7 +123,7 @@ describe('recent-room-service', function() {
troupe1: { users: ['user1'] }
});
it('should record the time each troupe was last accessed by a user', function(done) {
it('should record the time each troupe was last accessed by a user', function() {
return recentRoomService.saveLastVisitedTroupeforUserId(fixture.user1.id, fixture.troupe1.id)
.then(function() {
return persistenceService.User.findById(fixture.user1.id).exec();
......@@ -154,8 +146,7 @@ describe('recent-room-service', function() {
.then(function(times) {
assert(times[troupeId] > after, 'The last access time for this troupe has not changed. Before it was ' + after + ' now it is ' + times[troupeId]);
});
})
.nodeify(done);
});
});
......@@ -171,8 +162,7 @@ describe('recent-room-service', function() {
troupeOneToOne: { oneToOne: true, users: ['user1', 'user2'] },
});
it('#01 should return null when a user has no troupes',function(done) {
it('#01 should return null when a user has no troupes',function() {
return recentRoomService.saveLastVisitedTroupeforUserId(fixture.userNoTroupes.id, fixture.troupe1.id)
.then(function() {
fixture.userNoTroupes.lastTroupe = fixture.troupe1.id;
......@@ -180,32 +170,28 @@ describe('recent-room-service', function() {
})
.then(function(url) {
assert(url === null, 'Expected the url to be null');
})
.nodeify(done);
});
});
it('#02 should return return the users last troupe when they have one',function(done) {
it('#02 should return return the users last troupe when they have one',function() {
return recentRoomService.saveLastVisitedTroupeforUserId(fixture.user1.id, fixture.troupe1.id)
.then(function() {
return recentRoomService.findInitialRoomUrlForUser(fixture.user1);
})
.then(function(url) {
assert.strictEqual(url, '/' + fixture.troupe1.uri);
})
.nodeify(done);
});
});
it('#03 should return the users something when the user has troupes, but no last troupe',function(done) {
it('#03 should return the users something when the user has troupes, but no last troupe',function() {
return recentRoomService.findInitialRoomUrlForUser(fixture.user1)
.then(function(url) {
assert(url !== null, 'Expected the troupe not to be null');
})
.nodeify(done);
});
});
it('#04 should return one to one rooms',function(done) {
it('#04 should return one to one rooms',function() {
return recentRoomService.saveLastVisitedTroupeforUserId(fixture.user1.id, fixture.troupeOneToOne.id)
.then(function() {
return recentRoomService.findInitialRoomUrlForUser(fixture.user1);
......@@ -213,8 +199,7 @@ describe('recent-room-service', function() {
.then(function(url) {
assert.strictEqual(url, '/' + fixture.user2.username);
})
.nodeify(done);
});
});
});
......
......@@ -52,60 +52,57 @@ describe('room-context-service', function() {
})
it('should generate context for non-members', function(done) {
it('should generate context for non-members', function() {
access = true;
return roomContextService.findContextForUri(fixture.user1, fixture.troupe2.uri, {})
.then(function(roomContext) {
assert(!roomContext.roomMember);
})
.nodeify(done);
.then(function(roomContext) {
assert(!roomContext.roomMember);
});
});
it('should generate context for members', function(done) {
it('should generate context for members', function() {
access = true;
return roomContextService.findContextForUri(fixture.user1, fixture.troupe1.uri, {})
.then(function(roomContext) {
assert(roomContext.roomMember);
})
.nodeify(done);
.then(function(roomContext) {
assert(roomContext.roomMember);
});
});
it('should throw for users without access to the room', function(done) {
it('should throw for users without access to the room', function() {
access = false;
return roomContextService.findContextForUri(fixture.user1, fixture.troupe2.uri, {})
.then(function(/*roomContext*/) {
})
.catch(function(err) {
assert.strictEqual(err.status, 404);
})
.nodeify(done);
.then(function(/*roomContext*/) {
})
.catch(function(err) {
assert.strictEqual(err.status, 404);
});
});
it('should generate context for 1:1', function() {
access = true;
return roomContextService.findContextForUri(fixture.user1, fixture.user2.username, {})
.then(function(roomContext) {
assert(roomContext.roomMember);
});
.then(function(roomContext) {
assert(roomContext.roomMember);
});
});
it('should throw a redirect for 1:1 same user', function() {
return roomContextService.findContextForUri(fixture.user1, fixture.user1.username, {})
.then(function(roomContext) {
assert.strictEqual(roomContext.ownUrl, true);
assert.strictEqual(roomContext.uri, fixture.user1.username);
})
.then(function(roomContext) {
assert.strictEqual(roomContext.ownUrl, true);
assert.strictEqual(roomContext.uri, fixture.user1.username);
});
});
it('should be logged in to see a 1:1', function() {
return roomContextService.findContextForUri(null, fixture.user1.username, {})
.then(function(/*roomContext*/) {
assert.ok(false);
}, function(err) {
assert.strictEqual(err.status, 401);
});
.then(function(/*roomContext*/) {
assert.ok(false);
}, function(err) {
assert.strictEqual(err.status, 401);
});
});
});
......@@ -18,36 +18,32 @@ describe('troupe-uri-mapper', function() {
troupeOneToOne: { oneToOne: true, users: ['user1', 'user2'] },
});
it('#01 should return null when a user has no troupes',function(done) {
it('#01 should return null when a user has no troupes',function() {
return troupeUriMapper.getUrlOfFirstAccessibleRoom([fixture.userNoTroupes.id], fixture.user1.id)
.then(function(url) {
assert(!url);
})
.nodeify(done);
});
});
it('#02 should return the first room that allows access',function(done) {
it('#02 should return the first room that allows access',function() {
return troupeUriMapper.getUrlOfFirstAccessibleRoom([fixture.userNoTroupes.id, fixture.troupe1.id], fixture.user1.id)
.then(function(url) {
assert.strictEqual(url, '/' + fixture.troupe1.uri);
})
.nodeify(done);
});
});
it('#03 should return the one to one rooms',function(done) {
it('#03 should return the one to one rooms',function() {
return troupeUriMapper.getUrlOfFirstAccessibleRoom([fixture.userNoTroupes.id, fixture.troupeOneToOne.id, fixture.troupe1.id], fixture.user1.id)
.then(function(url) {
assert.strictEqual(url, '/' + fixture.user2.username);
})
.nodeify(done);
});
});
it('#04 should return the other user in a one-to-one room',function(done) {
it('#04 should return the other user in a one-to-one room',function() {
return troupeUriMapper.getUrlOfFirstAccessibleRoom([fixture.userNoTroupes.id, fixture.troupeOneToOne.id], fixture.user2.id)
.then(function(url) {
assert.strictEqual(url, '/' + fixture.user1.username);
})
.nodeify(done);
});
});
});
......
......@@ -9,6 +9,6 @@
},
"private": true,
"devDependencies": {
"mocha": "^2.4.5"
"mocha": "^5.2.0"
}
}
{
"env": {
"commonjs": true,
"node": true,
"mocha": true
},
"plugins": [
"mocha"
],
"rules": {
"mocha/no-exclusive-tests": "error"
}
}
{
"env": {
"commonjs": true,
"node": true,
"mocha": true
},
"plugins": [
"mocha"
],
"rules": {
"mocha/no-exclusive-tests": "error"
}
}
......@@ -59,7 +59,7 @@
"jsdom": "^9.4.5",
"jsdom-global": "^2.1.0",
"less-loader": "^2.2.3",
"mocha": "^2.5.3",
"mocha": "^5.2.0",
"plop": "^1.5.0",
"postcss-less": "^0.14.0",
"postcss-loader": "^1.3.3",
......
......@@ -13,7 +13,7 @@ describe("User Settings Service", function() {
user2: { }
});
it('should be able to set user settings', function(done) {
it('should be able to set user settings', function() {
var userId = fixture.user1.id;
return userSettingsService.setUserSettings(userId, 'test', { value1: 1, value2: true, value3: 'string' })
......@@ -24,11 +24,10 @@ describe("User Settings Service", function() {
assert.equal(settings.value1, 1);
assert.equal(settings.value2, true);
assert.equal(settings.value3, 'string');
})
.nodeify(done);
});
});
it('should be able to set multiple keys', function(done) {
it('should be able to set multiple keys', function() {
var userId = fixture.user1.id;
return userSettingsService.setUserSettings(userId, 'test', { value1: 1, value2: true, value3: 'string' })
......@@ -58,8 +57,7 @@ describe("User Settings Service", function() {
assert(settings.test.value1);
assert(settings.test2);
assert(settings.test2.human);
})
.nodeify(done);
});
});
it('should be able to get multiple keys', function() {
......@@ -90,7 +88,7 @@ describe("User Settings Service", function() {
});
});
it('should be able to fetch keys for multiple usertroupes', function(done) {
it('should be able to fetch keys for multiple usertroupes', function() {
var user1Id = fixture.user1.id;
var user2Id = fixture.user2.id;
......@@ -105,8 +103,7 @@ describe("User Settings Service", function() {
assert.equal(Object.keys(results).length, 2);
assert.equal(results[user1Id].bob, 1);
assert.equal(results[user2Id].bob, 2);
})
.nodeify(done);
});
});
......
......@@ -37,16 +37,15 @@ describe("User Service", function() {
});
it('should create new users', function(done) {
it('should create new users', function() {
return persistence.User.findOneAndRemove({ githubId: - 1})
.exec()
.then(function() {
return userService.findOrCreateUserForGithubId({ githubId: -1, username: '__test__gitter_007' });
})
.nodeify(done);
});
});
it('should destroy tokens for users', function(done) {
it('should destroy tokens for users', function() {
return userService.findOrCreateUserForGithubId({
githubId: -Date.now(),
username: fixture2.generateUsername(),
......@@ -68,8 +67,7 @@ describe("User Service", function() {
assert(!user.githubToken);
assert(!user.githubUserToken);
assert.deepEqual(user.githubScopes, {});
})
.nodeify(done);
});
});
......
......@@ -11,6 +11,6 @@
"test": "mocha test/"
},
"devDependencies": {
"mocha": "^2.5.3"
"mocha": "^5.2.0"
}
}
This diff is collapsed.
......@@ -242,7 +242,6 @@
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.4.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-spawn-mocha": "^2.0.1",
"gulp-tar": "^1.5.0",
"gulp-uglify": "^3.0.0",
"gulp-using": "^0.1.1",
......@@ -263,8 +262,8 @@
"lorem-ipsum": "^1.0.1",
"memoize-promise": "^0.2.2",
"mkdirp": "^0.5.1",
"mocha": "^2.5.3",
"mocha-multi": "^0.9.0",
"mocha": "^5.2.0",
"mocha-multi": "^1.0.1",
"mutantjs": "^0.2.0",
"nanoscroller": "^0.8.7",
"node-spritesheet": "github:trevorah/node-spritesheet",
......@@ -318,7 +317,8 @@
"dev": "gulp watch",
"dev-template": "concurrently --raw \"npm run start -- --watch server --watch shared --watch modules --watch public --ignore public/**/!(*.hbs)\" \"gulp watch\"",
"test": "gulp test:test",
"mocha": "mocha",
"mocha": "mocha --exit",
"nyc": "nyc",
"nodeselektor": "ns",
"task-css": "gulp css:compile",
"task-fasttest": "gulp test:test --test-fast",
......
......@@ -39,7 +39,7 @@ var notificationSerializerStub = {
describe('push notification generator service', function() {
it('should send a notification', function(done) {
it('should send a notification', function() {
var mockSendUserNotification = mockito.mockFunction();
mockito.when(mockSendUserNotification)().then(function() { return Promise.resolve(); });
......@@ -55,11 +55,10 @@ describe('push notification generator service', function() {
return service.sendUserTroupeNotification('userId1234', '1234567890', 1)
.then(function() {
mockito.verify(mockSendUserNotification, once)();
})
.nodeify(done);
});
});
it('should serialize troupes and chats correctly', function(done) {
it('should serialize troupes and chats correctly', function() {
var mockSendUserNotification = function(notificationType, userId, options) {
assert.strictEqual(notificationType, 'new_chat');
assert.equal(userId, 'userId1234');
......@@ -81,8 +80,7 @@ describe('push notification generator service', function() {
'../../serializers/notification-serializer': notificationSerializerStub
});
return service.sendUserTroupeNotification('userId1234', '1234567890', 1)
.nodeify(done);
return service.sendUserTroupeNotification('userId1234', '1234567890', 1);