-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(config): Gulp Server Watch for Mocha #1083
feat(config): Gulp Server Watch for Mocha #1083
Conversation
Sounds like a great addition. @ilanbiala is the gulp guy. |
@ilanbiala There were a few things here that I was unsure of; quick review? In particular, I don't have much experience with Glob. I didn't see a real straight forward way of getting an individual test file from the |
var changedTestFiles = []; | ||
|
||
// iterate through server test glob patterns | ||
_.forEach(testAssets.tests.server, function (tests) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilanbiala What do you think of this section overall?
Here, I'm iterating through the glob patterns because, since it's an array, technically a project could have multiple locations/patterns for tests.
The tests
param should probably be renamed to something like patterns
, or locations
@mleanos this shouldn't all be one gulp task in my opinion. Ideally gulp tasks are composed, just like sass, less, watch, etc. which all do one thing and are used in other places to make general utility tasks. I think it would be better to specify this functionality in the general watch task and just pare down the functionality a bit. I see the potential time value of just running the affected file tests, but when other things depend on others, you may still have issues, so I would just run all the tests anyway. |
@ilanbiala Have you taken this for a test drive? I suggest that you do, so you understand the benefits a bit more. As for it being included in the other Watch task, this is a separate task that runs without any other dependencies; it's not linked to any other Gulp task. The way that I use this, is to have it running in a terminal as I'm developing.. anytime I save a server file, the task invokes the existing And the |
@ilanbiala After looking at the gulp.task('test:server:watch', function (done) {
runSequence('test:server', 'watch', done);
}); This is what it would look like added to the existing 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 ? true : false;
// 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 (tests) {
// determine if the changed (watched) file is a server test
_.forEach(glob.sync(tests), 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;
}
plugins.livereload.changed();
});
} |
Still making the watch a little too powerful in my opinion. Also, I don't think adding argv parsing to gulp is a great idea because it seems unnatural in gulp. Is there a better way you can think of? What would creating a separate task for watch changed and not watch changed look like? |
@ilanbiala I don't understand what you mean by "too powerful".. What's the point of Gulp, if not to help manage mundane development tasks? Think of the development workflow that you have to follow to save a file, and then run the tests, and keep repeating that process. And what is unnatural about adding |
Instead of argv parsing for different tasks, Gulp seems to prefer just creating a different task with a different name. Tasks that are alone too powerful do too much in the function and don't compose the functionality from other tasks that should do one specific task well. |
99106c4
to
bb0339c
Compare
@ilanbiala I removed the new Gulp task, and moved the watch into the main Gulp watch task. The optional argument that I'm using Having a separate task that runs just one server test file, and then having one that runs all server tests, would be duplicate code. I think the use of As for your concern over the How would you approach this differently, given these requirements?
I'm open to suggestions. However, this feels like the most straight-forward, and clean, way of satisfying the above requirements. |
nothing special from me |
@ilanbiala I haven't followed this too closely. But the concept of being able to watch test files and either run a single test from a passed in arg or an entire suite of tests is awesome. |
@ilanbiala Any more feedback on this? I've been using this implementation for development, and it's immensely useful. It makes TDD so much faster. I think others will see it as a very useful tool for productivity. |
I have finals until next week, so I can't really spend any time on other stuff until then. Ping me then. |
SGTM. Thanks. |
@ilanbiala Let's get this merged in, so we can keep going on enhancing the Gulp configuration. |
@@ -116,6 +116,7 @@ | |||
"mock-fs": "~3.4.0", | |||
"run-sequence": "^1.1.1", | |||
"should": "^7.0.1", | |||
"supertest": "^1.0.1" | |||
"supertest": "^1.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never mind, just comma change, so this is fine
Last couple fixes, and then I'll merge. |
Adds a Gulp task that watches all server files (including server tests), and upon any changes it will perform the Gulp *test:server* task. Added a watch for server assets, to the main gulp watch config. This will only add the watch when the NODE_ENV is set to "test". Also, includes an **optional** argument for the task that can specify that if the changed file is a test, then it will only run that test file. Example usage: gulp test:server:watch --onlyChanged
bb0339c
to
bf2eeed
Compare
@ilanbiala I made the change to the I left the use of lodash's |
@ilanbiala I noticed, after the fact, that you also pointed out the dependency of |
@mleanos yep, I commented on that before, so it's fine. |
@mleanos This needs a blurb in the documentation, but that's a separate PR to a separate repo. LGTM |
@ilanbiala Can we get this merged? |
feat(config): Gulp Server Watch for Mocha
Sorry about the delay, just merged it in. |
No worries. I jhst have some other work I wanna do with Gulp. Thanks! |
Adds a Gulp task that watches all server files (including server tests),
and upon any changes it will perform the Gulp test:server task.
Also, includes an optional argument for the task that can specify
that if the changed file is a test, then it will only run that test
file.
Example usage: gulp test:server:watch --onlyChanged