From 0f4da275b268aee1f0adc97533bcc2b9c6213c7f Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Sat, 31 Dec 2016 13:47:57 +0200 Subject: [PATCH] feat(ava): initial project setup for ava test runner project setup for ava test runner includes the use of `gulp-ava` to integrate with a gulp task, updating the package.json to be able to fire up gulp with `--harmony` flag to support code use of async/await and other ES6/7 features. To currently support the existing tests in MEAN.JS 1 code the test asset has been added as *.test.js files (and not *.tests.js in plural) which also complies with Ava globbing --- server/config/assets/default.js | 1 + server/gulpfile.js | 24 +++++++++++++++++++ .../tasks.server.routes.sanity.test.js} | 0 server/package.json | 4 +++- server/test.js | 12 ---------- server/yarn.lock | 16 +++++++++++++ 6 files changed, 44 insertions(+), 13 deletions(-) rename server/modules/tasks/{tests/tasks.server.routes.sanity.tests.js => test/tasks.server.routes.sanity.test.js} (100%) delete mode 100644 server/test.js diff --git a/server/config/assets/default.js b/server/config/assets/default.js index 0d92754b6..0569981d9 100644 --- a/server/config/assets/default.js +++ b/server/config/assets/default.js @@ -13,6 +13,7 @@ module.exports = { config: ['modules/*/server/config/*.js'], policies: 'modules/*/server/policies/*.js', tests: ['modules/*/tests/server/**/*.js'], + test: ['modules/*/test/server/**/*.js'], views: ['modules/*/server/views/*.html'] } }; diff --git a/server/gulpfile.js b/server/gulpfile.js index 1a87d44fe..989b3fe4c 100644 --- a/server/gulpfile.js +++ b/server/gulpfile.js @@ -190,6 +190,30 @@ gulp.task('test', function (done) { runSequence('env:test', 'test:server', done); }); +gulp.task('server:bootstrap', function(done) { + const app = require('./config/lib/app'); + app.start().then(function() { + done(); + }); +}); + +gulp.task('ava:test:integration', function() { + gulp.src(defaultAssets.server.test) + // gulp-ava needs filepaths so you can't have any plugins before it + .pipe(plugins.ava({verbose: true})) + .on('error', function(err) { + console.log(err.message); + process.exit(1); + }) + .on('end', function() { + process.exit(0); + }); +}); + +gulp.task('test:integration', function(done) { + runSequence('env:test', 'server:bootstrap', 'ava:test:integration', done); +}); + gulp.task('test:server', function (done) { runSequence('env:test', 'lint', ['copyLocalEnvConfig', 'makeUploadsDir'], 'mocha', done); }); diff --git a/server/modules/tasks/tests/tasks.server.routes.sanity.tests.js b/server/modules/tasks/test/tasks.server.routes.sanity.test.js similarity index 100% rename from server/modules/tasks/tests/tasks.server.routes.sanity.tests.js rename to server/modules/tasks/test/tasks.server.routes.sanity.test.js diff --git a/server/package.json b/server/package.json index c67933f36..a6aeb94b6 100644 --- a/server/package.json +++ b/server/package.json @@ -21,8 +21,9 @@ "start": "gulp", "start:prod": "gulp prod", "start:debug": "gulp debug", - "gulp": "gulp", + "gulp": "node --harmony node_modules/.bin/gulp", "test": "gulp test", + "ava": "NODE_ENV=development node --harmony server.js & sleep 5 && ava", "test:server": "gulp test:server", "test:server:watch": "gulp test:server:watch", "test:coverage": "gulp test:coverage", @@ -45,6 +46,7 @@ "file-stream-rotator": "~0.0.6", "generate-password": "~1.2.0", "glob": "~7.1.0", + "gulp-ava": "^0.15.0", "helmet": "~2.3.0", "jasmine-core": "~2.5.0", "lodash": "~4.16.2", diff --git a/server/test.js b/server/test.js deleted file mode 100644 index e44bf389a..000000000 --- a/server/test.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -/** - * Module dependencies. - */ - -var path = require('path'); -var app = require(path.resolve('./config/lib/app')); - -app.init(function () { - console.log('Initialized test automation'); -}); diff --git a/server/yarn.lock b/server/yarn.lock index a41b3dbcb..8c95ba239 100644 --- a/server/yarn.lock +++ b/server/yarn.lock @@ -1603,6 +1603,12 @@ d@^0.1.1, d@~0.1.1: dependencies: es5-ext "~0.10.2" +dargs@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/dargs/-/dargs-4.1.0.tgz#03a9dbb4b5c2f139bf14ae53f0b8a2a6a86f4e17" + dependencies: + number-is-nan "^1.0.0" + dashdash@^1.12.0: version "1.14.1" resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" @@ -2745,6 +2751,16 @@ growl@1.9.2: version "1.9.2" resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" +gulp-ava@^0.15.0: + version "0.15.0" + resolved "https://registry.yarnpkg.com/gulp-ava/-/gulp-ava-0.15.0.tgz#8dc59e4a95d603a2ee1dfaad2993ea8d6cb510c2" + dependencies: + ava "^0.17.0" + dargs "^4.1.0" + gulp-util "^3.0.6" + resolve-cwd "^1.0.0" + through2 "^2.0.0" + gulp-concat@~2.6.0: version "2.6.1" resolved "https://registry.yarnpkg.com/gulp-concat/-/gulp-concat-2.6.1.tgz#633d16c95d88504628ad02665663cee5a4793353"