-
Notifications
You must be signed in to change notification settings - Fork 36
Use a gulp watch #21
Comments
I've had trouble passing a new list of files to an already running Karma server. See my comment here #3 (comment) for a detailed description and an example that uses gulp's watch mechanism (but doesn't leave the server running). Maybe this is fixed in Karma 0.12, I haven't had time to look into it. @mikehaas763, can you investigate and send a pull request with a solution if one exists? |
@lazd I think I will! |
I like the idea of using one watcher. Makes sense. @mikehaas763 have you had a chance to investigate? |
I did investigate a bit and found that it needs to spawn a child process in the bg just like grunt-karma does. |
@mikehaas763 and @demisx, with a few downright filthy hacks, I've put together a branch that repurposes However, it is no longer a gulp plugin because it doesn't deal with streams of files. In fact, it has nothing to do with gulp except for that fact that it's probably the only sane way I've seen to use Karma and gulp together. I've created a test repository that employs the helper branch to test a silly little todo app: The promise-based implementation of the helper is very digestible: var gulp = require('gulp');
// Create a gulp+karma helper with a set of default options
// In this case, the options all come from the config file
var karma = require('gulp-karma')({
configFile: 'karma.conf.js'
});
// Run tests once
gulp.task('test', function() {
// Override configuration for CI, etc
return karma.once({
reporters: ['coverage']
});
});
// WATCH OPTION 1: gulp.watch style
gulp.task('gulp-watch', function() {
// Start a server, then, once it's ready, run tests
karma.start().then(karma.run);
// Watch for changes with gulp and run tests accordingly
gulp.watch(['client/scripts/todo/*.js', 'test/client/*.js'], function() {
karma.run();
});
});
// WATCH OPTION 2: Karma autoWatch style
gulp.task('karma-watch', function() {
// Start a karma server, run tests, then watch with karma
return karma.start({
autoWatch: true
});
}); This is great, but this issue karma-runner/karma#1037 is the reason for the aforementioned downright filthy hacks -- Karma does't lend itself to being programmatically controlled in this fashion. Once that issue is addressed in a robust way, this kind of "gulp helper" will likely be the best way to use gulp with Karma. But wait! Why do we need a gulp plugin for Karma again? Why didn't I just use Karma's public API like @vojtajina suggested? It. just. won't. die. See karma-runner/karma#1035 . Also, it's nice to avoid repeating yourself and passing the configuration around. And promises are fun. |
@lazd I think the direction you are taking with the library is great, since the clash between karma and gulp has caused nothing but trouble for me so far. However, I have an idea on how you could make the helper more of proper gulp-plugin: let the gulp.src point to the karma configuraiton file.
What do you think? |
+1 for @allansson idea to keep this plugin idiomatic to gulp and streams. |
@mmoulton it would be even more idiomatic to gulp if it didn't exist. Please checkout the helper branch and the associated Karma issues and give your feedback on that. |
Just checked out that branch, option 2 looks really nice. |
For example I have a CI task that runs protractor and karma tasks at the same time, with karma failing and protractor succeeding, the task will return 0 (https://travis-ci.org/Cookingenius/Plate/builds/23863259) but it's doing that for the current version too so nevermind ! I think you should push it as 0.1 as it's much better than the current one. |
Looks like a gulp bug. You can clearly see that it reports the error to
|
@lazd Are you planning to publish that branch to npm? |
@Keats, I won't be publishing this until the referenced Karma issue is closed. You can use this branch in your package.json until then, however. See https://www.npmjs.org/doc/json.html#Git-URLs-as-Dependencies |
Any progress on this one? |
@JRajan see karma-runner/karma#1037 for progress. |
|
Hi. I know you have just depended on using karma's builtin file-watching with this plugin thus far to keep it easy. I'm interested in getting it to use one of the gulp watch only plugins though. Either the built-in gulp.watch or the gulp-watch plugin.
A few reasons why I think this is important:
I haven't even looked in to what this would take. In any case, would you be open to it?
The text was updated successfully, but these errors were encountered: