From 18328c0c4265ca21fc2d920a55cf743bf1ac5053 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 6 Nov 2015 21:27:38 -0600 Subject: [PATCH 01/15] Add lodash.deepDefaults as a dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 480959e118..ba6d1d5edf 100644 --- a/package.json +++ b/package.json @@ -121,13 +121,14 @@ "karma-ng-html2js-preprocessor": "~0.1.0", "karma-phantomjs-launcher": "~0.1.0", "karma-requirejs": "~0.2.0", - "requirejs": "~2.1", "karma-script-launcher": "~0.1.0", "lcov-result-merger": "^1.0.2", + "lodash.defaultsdeep": "^3.10.0", "mocha": "^2.3.3", "mongodb": "^2.0.46", "mongoskin": "~0.6.1", "protractor": "~2.0.0", + "requirejs": "~2.1", "rewire": "^2.3.3", "shelljs": "^0.4.0", "sinon": "^1.17.2", From 303b88b6fae88efb095152dcd165e68466832fb4 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 6 Nov 2015 21:28:19 -0600 Subject: [PATCH 02/15] Adjust api tests --- tasks/gulp-tests.js | 6 ++++-- test/helpers/api-integration.helper.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tasks/gulp-tests.js b/tasks/gulp-tests.js index 8264f91321..1fb2242e5f 100644 --- a/tasks/gulp-tests.js +++ b/tasks/gulp-tests.js @@ -297,6 +297,7 @@ gulp.task('test:e2e:safe', ['test:prepare', 'test:prepare:server'], (cb) => { }); gulp.task('test:api-v2', ['test:prepare:server'], (done) => { + process.env.API_VERSION = 'v2'; awaitPort(TEST_SERVER_PORT).then(() => { runMochaTests('./test/api/v2/**/*.js', server, done) }); @@ -329,15 +330,16 @@ gulp.task('test:api-v3', ['test:api-v3:unit', 'test:api-v3:integration']); gulp.task('test:api-v3:watch', ['test:api-v3:unit:watch', 'test:api-v3:integration:watch']); -gulp.task('test:api-v3:unit', ['test:prepare:server'], (done) => { +gulp.task('test:api-v3:unit', (done) => { runMochaTests('./test/api/v3/unit/**/*.js', null, done) }); -gulp.task('test:api-v3:unit:watch', ['test:prepare:server'], () => { +gulp.task('test:api-v3:unit:watch', () => { gulp.watch(['website/src/**', 'test/api/v3/unit/**'], ['test:api-v3:unit']); }); gulp.task('test:api-v3:integration', ['test:prepare:server'], (done) => { + process.env.API_VERSION = 'v3'; awaitPort(TEST_SERVER_PORT).then(() => { runMochaTests('./test/api/v3/unit/**/*.js', server, done) }); diff --git a/test/helpers/api-integration.helper.js b/test/helpers/api-integration.helper.js index b2b0ac99c6..1ddaa75b0d 100644 --- a/test/helpers/api-integration.helper.js +++ b/test/helpers/api-integration.helper.js @@ -208,9 +208,10 @@ export function resetHabiticaDB() { } function _requestMaker(user, method, additionalSets) { + const API_V = process.env.API_VERSION || 'v2' return (route, send, query) => { return new Promise((resolve, reject) => { - let request = superagent[method](`http://localhost:${API_TEST_SERVER_PORT}/api/v2${route}`) + let request = superagent[method](`http://localhost:${API_TEST_SERVER_PORT}/api/${API_V}${route}`) .accept('application/json'); if (user && user._id && user.apiToken) { From 6e344ce04b1eb8c7a386e608deb76c59462a7f72 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 6 Nov 2015 21:28:31 -0600 Subject: [PATCH 03/15] Add sandbox as a global --- test/helpers/globals.helper.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/helpers/globals.helper.js b/test/helpers/globals.helper.js index 74a9ae6045..32ec18f79e 100644 --- a/test/helpers/globals.helper.js +++ b/test/helpers/globals.helper.js @@ -8,3 +8,5 @@ global.sinon = require("sinon"); chai.use(require("sinon-chai")) chai.use(require("chai-as-promised")); global.expect = chai.expect + +global.sandbox = sinon.sandbox.create(); From 94dbb25fa61b94ad04196b9c0841e534b430ee31 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 6 Nov 2015 21:28:47 -0600 Subject: [PATCH 04/15] Add unit helper --- test/helpers/api-unit.helper.js | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/helpers/api-unit.helper.js diff --git a/test/helpers/api-unit.helper.js b/test/helpers/api-unit.helper.js new file mode 100644 index 0000000000..3bcf4be4b9 --- /dev/null +++ b/test/helpers/api-unit.helper.js @@ -0,0 +1,41 @@ +// @TODO: remove when lodash can be upgraded +import defaults from 'lodash.defaultsdeep'; +import { model as User } from '../../website/src/models/user' +import { model as Group } from '../../website/src/models/group' +import i18n from '../../common/script/src/i18n'; +require('coffee-script'); +i18n.translations = require('../../website/src/libs/i18n.js').translations; + +afterEach(() => { + sandbox.restore(); +}); + +export function generateUser(options={}) { + return new User(options)._doc; +} + +export function generateGroup(options={}) { + return new Group(options)._doc; +} + +export function generateRes(options={}) { + let defaultRes = { + send: sandbox.stub(), + json: sandbox.stub(), + locals: { + user: generateUser(options.localsUser), + group: generateGroup(options.localsGroup), + }, + }; + + return defaults(options, defaultRes); +} + +export function generateReq(options={}) { + let defaultReq = { + body: {}, + query: {}, + }; + + return defaults(options, defaultReq); +} From e657a30320f8101c7e4a3cef3c4f71d95441abcb Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 08:32:02 -0600 Subject: [PATCH 05/15] Add next generator for easier controller testing. --- test/helpers/api-unit.helper.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/helpers/api-unit.helper.js b/test/helpers/api-unit.helper.js index 3bcf4be4b9..5aa2816677 100644 --- a/test/helpers/api-unit.helper.js +++ b/test/helpers/api-unit.helper.js @@ -39,3 +39,7 @@ export function generateReq(options={}) { return defaults(options, defaultReq); } + +export function generateNext(func) { + return func || sandbox.stub(); +} From 1eadceea3d5ce88e01c05e1199b28a119732c09e Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 09:25:43 -0600 Subject: [PATCH 06/15] Add status to default res --- test/helpers/api-unit.helper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/helpers/api-unit.helper.js b/test/helpers/api-unit.helper.js index 5aa2816677..30bdab8fc3 100644 --- a/test/helpers/api-unit.helper.js +++ b/test/helpers/api-unit.helper.js @@ -21,6 +21,7 @@ export function generateGroup(options={}) { export function generateRes(options={}) { let defaultRes = { send: sandbox.stub(), + status: sandbox.stub().returnsThis(), json: sandbox.stub(), locals: { user: generateUser(options.localsUser), From b323c3b5e97d5388d81a50ca88a072cc68dcb660 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 09:26:13 -0600 Subject: [PATCH 07/15] Use res and req generators in error handler test --- .../v3/unit/middlewares/errorHandler.test.js | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/test/api/v3/unit/middlewares/errorHandler.test.js b/test/api/v3/unit/middlewares/errorHandler.test.js index 39e72b2e45..7ce86127e5 100644 --- a/test/api/v3/unit/middlewares/errorHandler.test.js +++ b/test/api/v3/unit/middlewares/errorHandler.test.js @@ -1,33 +1,29 @@ +import { + generateRes, + generateReq, + generateNext, +} from '../../../../helpers/api-unit.helper'; + import errorHandler from '../../../../../website/src/middlewares/api-v3/errorHandler'; import { BadRequest } from '../../../../../website/src/libs/api-v3/errors'; import logger from '../../../../../website/src/libs/api-v3/logger'; describe('errorHandler', () => { - let res, req; + let res, req, next; beforeEach(() => { - res = { - status: sinon.stub().returnsThis(), - json: sinon.stub(), - }; - req = { - originalUrl: 'foo', - headers: {}, - body: {}, - }; + res = generateRes(); + req = generateReq(); + next = generateNext(); - sinon.stub(logger, 'error'); - }); - - afterEach(() => { - logger.error.restore(); + sandbox.stub(logger, 'error'); }); it('sends internal server error if error is not a CustomError', () => { let error = new Error(); - errorHandler(error, req, res); + errorHandler(error, req, res, next); expect(res.status).to.be.calledOnce; expect(res.json).to.be.calledOnce; @@ -42,7 +38,7 @@ describe('errorHandler', () => { it('sends CustomError', () => { let error = new BadRequest(); - errorHandler(error, req, res); + errorHandler(error, req, res, next); expect(res.status).to.be.calledOnce; expect(res.json).to.be.calledOnce; @@ -57,7 +53,7 @@ describe('errorHandler', () => { it('logs error', () => { let error = new BadRequest(); - errorHandler(error, req, res); + errorHandler(error, req, res, next); expect(logger.error).to.be.calledOnce; expect(logger.error).to.be.calledWith(error.stack, { @@ -68,7 +64,6 @@ describe('errorHandler', () => { }); it('does not send error if error is not defined', () => { - let next = sinon.stub(); errorHandler(null, req, res, next); expect(next).to.be.calledOnce; From 3559be0f83d2be36012393998fbd396ed4672f35 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 09:42:57 -0600 Subject: [PATCH 08/15] Use toObject instead of _doc --- test/helpers/api-unit.helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/helpers/api-unit.helper.js b/test/helpers/api-unit.helper.js index 30bdab8fc3..6e561df076 100644 --- a/test/helpers/api-unit.helper.js +++ b/test/helpers/api-unit.helper.js @@ -11,11 +11,11 @@ afterEach(() => { }); export function generateUser(options={}) { - return new User(options)._doc; + return new User(options).toObject(); } export function generateGroup(options={}) { - return new Group(options)._doc; + return new Group(options).toObject(); } export function generateRes(options={}) { From 88f8a2a3754e6ab72dc4a9b99c8882663059fd96 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 19:09:51 -0600 Subject: [PATCH 09/15] Swap out gulp-clean for rimraf --- package.json | 2 +- tasks/gulp-sprites.js | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a3fc0957cc..5334ea64c5 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "grunt-hashres": "~0.4.1", "grunt-karma": "~0.6.2", "gulp": "^3.9.0", - "gulp-clean": "^0.3.1", "gulp-eslint": "^1.0.0", "gulp-grunt": "^0.5.2", "gulp-imagemin": "^2.3.0", @@ -122,6 +121,7 @@ "mongoskin": "~0.6.1", "protractor": "~2.0.0", "rewire": "^2.3.3", + "rimraf": "^2.4.3", "shelljs": "^0.4.0", "sinon": "^1.17.2", "sinon-chai": "^2.8.0", diff --git a/tasks/gulp-sprites.js b/tasks/gulp-sprites.js index a5777af9ce..18c289f47c 100644 --- a/tasks/gulp-sprites.js +++ b/tasks/gulp-sprites.js @@ -1,7 +1,7 @@ import gulp from 'gulp'; import imagemin from 'gulp-imagemin'; import spritesmith from 'gulp.spritesmith'; -import clean from 'gulp-clean'; +import clean from 'rimraf'; import sizeOf from 'image-size'; import mergeStream from 'merge-stream'; import {basename} from 'path'; @@ -25,10 +25,7 @@ gulp.task('sprites:largeSprites', () => { }); gulp.task('sprites:clean', (done) => { - gulp.src(`${DIST_PATH}spritesmith*`) - .pipe(clean()); - - done(); + clean(`${DIST_PATH}spritesmith*`, done); }); gulp.task('sprites:checkCompiledDimensions', ['sprites:main', 'sprites:largeSprites'], () => { From 05ae419d7eca762078a37779e96431f18911ee92 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 19:56:09 -0600 Subject: [PATCH 10/15] Update karma dependencies and remove unused packages. --- package.json | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 5334ea64c5..fef3d58251 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "grunt-contrib-uglify": "~0.6.0", "grunt-contrib-watch": "~0.6.1", "grunt-hashres": "~0.4.1", - "grunt-karma": "~0.6.2", + "grunt-karma": "~0.12.1", "gulp": "^3.9.0", "gulp-eslint": "^1.0.0", "gulp-grunt": "^0.5.2", @@ -101,20 +101,12 @@ "event-stream": "^3.2.2", "expect.js": "~0.2.0", "istanbul": "^0.3.14", - "karma": "~0.10.2", - "karma-chai-plugins": "~0.1.0", - "karma-chrome-launcher": "~0.1.0", - "karma-coffee-preprocessor": "~0.1.0", - "karma-coverage": "^0.3.1", - "karma-firefox-launcher": "~0.1.0", - "karma-html2js-preprocessor": "~0.1.0", - "karma-jasmine": "~0.1.3", + "karma": "~0.13.15", + "karma-chai-plugins": "~0.6.0", + "karma-coverage": "^0.5.3", "karma-mocha": "^0.2.0", "karma-mocha-reporter": "^1.1.1", - "karma-ng-html2js-preprocessor": "~0.1.0", - "karma-phantomjs-launcher": "~0.1.0", - "karma-requirejs": "~0.2.0", - "karma-script-launcher": "~0.1.0", + "karma-phantomjs-launcher": "~0.2.1", "lcov-result-merger": "^1.0.2", "mocha": "^2.3.3", "mongodb": "^2.0.46", From b6a1414e1c923625ce0940ba18e0bcbad916ec88 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 20:09:36 -0600 Subject: [PATCH 11/15] Update npm to v2 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bdbbc2c781..a92e4b8468 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - '0.10' before_install: + - "npm install -g npm@2" - "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10" - "echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list" - "sudo apt-get update" @@ -12,4 +13,4 @@ before_script: - "until nc -z localhost 27017; do echo Waiting for MongoDB; sleep 1; done" - "export DISPLAY=:99" after_script: - - "./node_modules/.bin/lcov-result-merger 'coverage/**/*.info' | ./node_modules/coveralls/bin/coveralls.js" \ No newline at end of file + - "./node_modules/.bin/lcov-result-merger 'coverage/**/*.info' | ./node_modules/coveralls/bin/coveralls.js" From f137e0d41da824a0f076be5a4d1950424670c3b6 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 20:16:32 -0600 Subject: [PATCH 12/15] Add gulp to travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a92e4b8468..a5ff61b605 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ node_js: - '0.10' before_install: - "npm install -g npm@2" + - "npm install -g gulp" - "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10" - "echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list" - "sudo apt-get update" From a6c7e3b885b82f8023c39f0719998978ab8b68d9 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 20:31:28 -0600 Subject: [PATCH 13/15] Update protractor dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fef3d58251..c6047b400d 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "mocha": "^2.3.3", "mongodb": "^2.0.46", "mongoskin": "~0.6.1", - "protractor": "~2.0.0", + "protractor": "~2.5.1", "rewire": "^2.3.3", "rimraf": "^2.4.3", "shelljs": "^0.4.0", From 598d25dc48e5374b81cf8ad2f3b9d92a58cffdac Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 20:56:56 -0600 Subject: [PATCH 14/15] Update browserify package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c6047b400d..edacdb51bd 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "babel": "^5.5.4", "gulp-babel": "^5.2.1", "bower": "~1.3.12", - "browserify": "~3.30.2", + "browserify": "~12.0.1", "coffee-script": "1.6.x", "coffeeify": "0.6.0", "connect-ratelimit": "0.0.7", From 22f76e94793ed87e23d7f9655c0ff93919a41de5 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 7 Nov 2015 21:06:59 -0600 Subject: [PATCH 15/15] Use npm 3 for travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8419a792f3..5d18669e31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: node_js node_js: - '4.2' before_install: - - "npm install -g npm@2" + - "npm install -g npm@3" - "npm install -g gulp" - "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10" - "echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list"