Multi-inject into karma.conf.js using different tags
Closed this issue · 1 comments
Hello,
I'm currently trying to inject multiple files (~500) into our karma.conf.js using gulp-inject. In the applications index.html
file this works like a charm, but in the files
section of the karma.conf.js it does not work as desired. The files
section looks like the following:
files: [
// bower:js
// endinject
// types:js
// endinject
// scripts:js
// endinject
// test-specs:js
// endinject
]
First I'd like to inject all dependencies from the bower.json, then our automatically generated types (based on Beans/POCOs in Java) and then our AngularJS scripts. Last I'd like to inject the test specs themselves. Is this possible? The example in the docs injects all files at once by using the start tag files: [
and end tag ]
. My current workaround is to load all files in separate streams, sort them, merge them and inject the merged stream result. I already thought about populating a JSON file with the different sections and pass that to Karma, but I'm not sure if this will add any benefit... My favourite approach would be to inject the files directly into the karma.conf.js.
Yay, I got it to work by explicitly defining start and end tags myself. Something like
var deps = loadMyDeps();
return gulp.src('./karma.conf.js')
.pipe(inject(deps, {
starttag: '// bower:js',
endtag: '// endinject',
transform: function(filepath, file, i, length) {
return '\n\t\t\t\'' + filepath + '\'' + (i + 1 < length ? ',' : '\n\t\t');
}
}));
did the trick! 💃