Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to exclude file in gruntfile config, but file path prefix is breaking expression

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?

like image 563
tengen Avatar asked Mar 22 '23 20:03

tengen


1 Answers

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'
]
like image 118
tengen Avatar answered Apr 25 '23 01:04

tengen