4

I am setting up grunt with a karma task that looks for all the unit test files. I need to access all *.js files, and *.spec.js files, but I want to exclude all *.e2e.js files. Based on the node glob documentation, I would expect the following to work (in karma.conf.js):

files: [
  'vendor/angular/angular.js',
  'vendor/angular-mocks/angular-mocks.js',
  'vendor/angular-resource/angular-resource.js',
  'app/**/*.js',
  '!app/**/*.e2e.js'
],

However, when I try to run my grunt test task, it still tries to load these e2e.js tests, which break because each test references protractor, which karma get confused by. According to my console, I'm seeing URL's like this:

userdirectory/repo/!app/mytest.e2e.js

It seems that the full filepath (or at least some of it) is being preappended to the file glob pattern I supply in karma.conf.js. Is grunt doing this after the fact when it loads the karma task?

2
  • Is it not possible to place the e2e tests in a seperate folder? That way they will be easier to exclude, and include in their own configuration file. Nov 1, 2013 at 14:52
  • @LudwigMagnusson Sure you could, but that doesn't help me figure out why this wasn't working.
    – tengen
    Nov 1, 2013 at 17:22

1 Answer 1

7

My problem was that karma does not use the same globber syntax as grunt. According to karma's documentation, you use 'files' to show what you want to include, and exclude to show what you want to exclude:

exclude
Type: Array
Default: []
Description: List of files/patterns to exclude from loaded files.

Here is my fix:

files : [
  // libraries / vendor files needed to test souce code
  'vendor/angular/angular.js',
  'vendor/angular/angular-route.js',
  'vendor/angular/angular-mocks.js',
  'vendor/require/*.js',
  // all souce .js files, as well as all .spec.js test files
  'app/modules/**/*.js'
],
exclude : [
  // exclude all *.e2e.js end to end test files from being included
  // - Karma will break when trying to load protractor
  'app/modules/**/*.e2e.js'
]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.