Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
feat(gulp): test:server:watch task onlyChanged (#1298)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mleanos committed Apr 10, 2016
1 parent bc0b4a6 commit eaead7a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
59 changes: 27 additions & 32 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit eaead7a

Please sign in to comment.