Customize "files" option in Gruntfile
See original GitHub issueHi there,
I wanted to override the “files” parameters of my karma.conf.js inside grunt-karma plugin. My use case is having a list of common files (like all AngularJS files) and adding either underscore or lodash to test that the library is compatible with both third part libraries.
My first idea was something like:
karma: {
options: {
configFile: 'karma.conf.js',
browsers: ['PhantomJS']
},
buildLodash: {
files: [
JASMINE,
JASMINE_ADAPTER,
'http://code.angularjs.org/1.1.4/angular.js',
'http://code.angularjs.org/1.1.4/angular-resource.js',
'http://code.angularjs.org/1.1.4/angular-mocks.js',
'http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.1.1/lodash.js',
'src/*.js',
'test/*.js'
'src/*.js',
'test/*.js'
],
singleRun: true
},
buildUnderscore: {
files: [
JASMINE,
JASMINE_ADAPTER,
'http://code.angularjs.org/1.1.4/angular.js',
'http://code.angularjs.org/1.1.4/angular-resource.js',
'http://code.angularjs.org/1.1.4/angular-mocks.js',
'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore.js',
'src/*.js',
'test/*.js'
],
singleRun: true
}
}
But that didn’t work because JASMINE is not defined… fair enough. Is there a way to define both JASMINE and JASMINE_ADAPTER? I saw there was defined inside grunt-karma/node_modules/karma/lib/config.js
but I have no idea how to import them…
As an alternative, what would think about a way to extend the arrays from the config file rather than only overriding them? Something like filesExtend
, exludeExtend
, reportersExtend
and browersExtend
options which would apply a concat
between the array from the karma.conf.js file and the Gruntfile. It could be extend a second time inside tasks. Example:
karma.conf.js
files = [
JASMINE,
JASMINE_ADAPTER
]
Gruntfile.js
karma: {
options: {
configFile: 'karma.conf.js',
browsers: ['PhantomJS'],
filesExtend: [
'http://code.angularjs.org/1.1.4/angular.js',
'http://code.angularjs.org/1.1.4/angular-resource.js',
'http://code.angularjs.org/1.1.4/angular-mocks.js',
'src/*.js',
'test/*.js'
]
},
buildLodash: {
filesExtend: [
'http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.1.1/lodash.js'
],
singleRun: true
},
buildUnderscore: {
filesExtend: [
'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore.js'
],
singleRun: true
}
}
This would produce the expected result : both builds would have all AngularJS and JASMINE files, and either lodash or underscore depending on the task.
What do you think?
Issue Analytics
- State:
- Created 10 years ago
- Comments:17 (6 by maintainers)
Top GitHub Comments
I have a workaround for this with grunt. Set the files in the default options, then override via grunt.config in your task call:
…
Thanks to @geddski for this: It turns out this pull request isn’t needed. if you wrap “files” in options, everything plays nice. Here is an example:
Thankfully, the global karma options (configFile and browsers) are not blown away when specifying the options object again in each karma runner execution config.