From eaead7a30cb2a60ad25250940e79b42619261e23 Mon Sep 17 00:00:00 2001 From: Michael Leanos Date: Sun, 10 Apr 2016 16:56:57 -0700 Subject: [PATCH] feat(gulp): test:server:watch task onlyChanged (#1298) Sets the behavior of the test:server:watch Gulp task to only run a single test suite if the modified server file is a test suite. Previously this was acheived through the use of the `onlyChanged` parameter. The parameter has been removed since this is almost certainly the only use case. Also, refactors this Gulp task to be a stand-alone watch task rather than including it in the 'watch' task. Removed the need for using yargs library, and removed the yargs package from the framework. Closes #1297 --- gulpfile.js | 59 ++++++++++++++++++++++++---------------------------- package.json | 3 +-- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 15b885aeb5..181cab3150 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -19,12 +19,14 @@ var _ = require('lodash'), pngquant = require('imagemin-pngquant'), path = require('path'), endOfLine = require('os').EOL, - argv = require('yargs').argv, protractor = require('gulp-protractor').protractor, webdriver_update = require('gulp-protractor').webdriver_update, webdriver_standalone = require('gulp-protractor').webdriver_standalone, KarmaServer = require('karma').Server; +// Local settings +var changedTestFiles = []; + // Set NODE_ENV to 'test' gulp.task('env:test', function () { process.env.NODE_ENV = 'test'; @@ -82,35 +84,31 @@ gulp.task('watch', function () { gulp.watch(defaultAssets.server.gulpConfig, ['eslint']); gulp.watch(defaultAssets.client.views).on('change', plugins.livereload.changed); } +}); - if (process.env.NODE_ENV === 'test') { - // Add Server Test file rules - gulp.watch([testAssets.tests.server, defaultAssets.server.allJS], ['test:server']).on('change', function (file) { - var runOnlyChangedTestFile = !!argv.onlyChanged; - - // check if we should only run a changed test file - if (runOnlyChangedTestFile) { - var changedTestFiles = []; - - // iterate through server test glob patterns - _.forEach(testAssets.tests.server, function (pattern) { - // determine if the changed (watched) file is a server test - _.forEach(glob.sync(pattern), function (f) { - var filePath = path.resolve(f); - - if (filePath === path.resolve(file.path)) { - changedTestFiles.push(f); - } - }); - }); - - // set task argument for tracking changed test files - argv.changedTestFiles = changedTestFiles; - } +// Watch server test files +gulp.task('watch:server:run-tests', function () { + // Start livereload + plugins.livereload.listen(); - plugins.livereload.changed(); + // Add Server Test file rules + gulp.watch([testAssets.tests.server, defaultAssets.server.allJS], ['test:server']).on('change', function (file) { + changedTestFiles = []; + + // iterate through server test glob patterns + _.forEach(testAssets.tests.server, function (pattern) { + // determine if the changed (watched) file is a server test + _.forEach(glob.sync(pattern), function (f) { + var filePath = path.resolve(f); + + if (filePath === path.resolve(file.path)) { + changedTestFiles.push(f); + } + }); }); - } + + plugins.livereload.changed(); + }); }); // CSS linting task @@ -281,7 +279,7 @@ gulp.task('templatecache', function () { gulp.task('mocha', function (done) { // Open mongoose connections var mongoose = require('./config/lib/mongoose.js'); - var testSuites = Array.isArray(argv.changedTestFiles) && argv.changedTestFiles.length ? argv.changedTestFiles : testAssets.tests.server; + var testSuites = changedTestFiles.length ? changedTestFiles : testAssets.tests.server; var error; // Connect mongoose @@ -378,11 +376,8 @@ gulp.task('test:server', function (done) { }); // Watch all server files for changes & run server tests (test:server) task on changes -// optional arguments: -// --onlyChanged - optional argument for specifying that only the tests in a changed Server Test file will be run -// example usage: gulp test:server:watch --onlyChanged gulp.task('test:server:watch', function (done) { - runSequence('test:server', 'watch', done); + runSequence('test:server', 'watch:server:run-tests', done); }); gulp.task('test:client', function (done) { diff --git a/package.json b/package.json index a98fd45c74..90a679b40d 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,6 @@ "node-inspector": "~0.12.7", "run-sequence": "~1.1.5", "should": "~8.2.2", - "supertest": "~1.2.0", - "yargs": "~3.32.0" + "supertest": "~1.2.0" } }