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

Passing a glob to gulp-karma watches individual files and does not catch newly added files #3

Closed
lazd opened this issue Jan 6, 2014 · 8 comments

Comments

@lazd
Copy link
Owner

lazd commented Jan 6, 2014

If you pass a glob, say tests/**/*.js, then add files to tests/, they are not included in subsequent test runs as the globs are resolved before being passed to Karma's watch mechanism.

@chrisabrams
Copy link

:(

@lazd
Copy link
Owner Author

lazd commented Jan 7, 2014

@chrisabrams, I'll be at you soon with a workaround to turn that frown upside down.

@dashed
Copy link

dashed commented Jan 9, 2014

Man. I want this so bad.

@koblass
Copy link

koblass commented Jan 9, 2014

Why not use the gulp.watch method instead and use the action "run" ? my guess is that it should work

@lazd
Copy link
Owner Author

lazd commented Jan 9, 2014

The problem lies in the fact that gulp.src will send a stream of individual File objects, not the actual globs. Karma is doing the actual watching in this case.

@koblass, that would involve an additional task for starting the Karma server, and it was getting a bit ugly when I tried that route before. Will reconsider it, but it's looking like this will end up gulp-friendly and avoid using gulp's src and watch methods completely.

@dashed
Copy link

dashed commented Jan 9, 2014

@lazd This may be related to floatdrop/gulp-watch#16 (comment)

@j0hnsmith
Copy link

+1

@lazd
Copy link
Owner Author

lazd commented Jan 25, 2014

Here's what I've found: I can't get the runner to recognize new files if the server has already been started. In order to make it happen, the server needs to be started/killed on every test run.

The following is currently possible:

var gulp = require('gulp');
var karma = require('gulp-karma');

// Include order
// Could be globs instead
var includeOrder = [
  'client/scripts/todo/todo.js',
  'client/scripts/todo/todo.polyfills.js',
  'client/scripts/todo/todo.util.js',
  'client/scripts/todo/todo.App.js'
];

// Add the tests to the include order
// Uses a glob to catch all tests
var testIncludeOrder = includeOrder.concat(['test/client/*.js']);

// Run tests once
gulp.task('test', function() {
  // The glob is evaluated again, so new files are picked up
  return gulp.src(testIncludeOrder)
    .pipe(karma({
      configFile: 'karma.conf.js',
      action: 'run'
    }));
});

gulp.task('default', function() {
  // Run on start
  gulp.run('test');

  // Run on change
  // This watches on the glob, not the individual files
  gulp.watch(testIncludeOrder, function() {
    return gulp.run('test');
  });
});

This is less than ideal. I'll keep looking for a workaround and will investigate into whether Karma can be patched to fix this, but for now, the above workaround does get the job done.

@j0hnsmith
Copy link

Idea, probably not a good one: you can set autoWatch : false in karma.conf.js so each time the gulp watch sees a change it invokes karma with a new list of files (from the glob). I haven't tried but this should work however each time karma starts it opens up browsers, which may take a second or two so this might not be very practical.

Just read the previous commend by @lazd, this is more or less the same suggestion.

@lazd
Copy link
Owner Author

lazd commented Oct 1, 2015

gulp-karma is deprecated (#43). Please use Karma directly: https://github.com/karma-runner/gulp-karma

@lazd lazd closed this as completed Oct 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants