I am using Karma to test my JavaScript and get coverage reports. I am using the Istanbul coverage report, which is the default. Here is my preprocessors parameter:
preprocessors: {
'framework/**/*.js':'coverage',
'framework/*.js':'coverage',
'!framework/node/**/*.js':'coverage',
'!framework/test/**/*.js':'coverage',
'framework-lib/**/*.js':'coverage',
'!framework-lib/tool-data-api/tool-data-api.js':'coverage'
}
As you can see, I am trying to use the "!" as a negate command, which usually works with Node. However, it is not working here and none of my directories are being excluded.
Is there any way to do what I am trying to accomplish?
Ignore Code Coverage You can prevent some files from being taken into account for code coverage by unit tests. To do so, go to Project Settings > General Settings > Analysis Scope > Code Coverage and set the Coverage Exclusions property. See the Patterns section for more details on the syntax.
Under the hood, this script is using Jest to run all of the tests in the new app. Conveniently for you, Istanbul can be used to provide a coverage report by simply adding the --coverage flag onto the end of the test command like this: react-scripts test --coverage .
According to https://karma-runner.github.io/0.12/config/configuration-file.html:
**/*.js: All files with a "js" extension in all subdirectories
**/!(jquery).js: Same as previous, but excludes "jquery.js"
**/(foo|bar).js: In all subdirectories, all "foo.js" or "bar.js" files
So, based on this, I tried the following:
preprocessors: {
'framework/**/!(node|test)/*.js': 'coverage',
'framework-lib/**/!(tool-data-api).js': 'coverage'
}
Which seems to have accomplished what you are looking for.
As a note to others who come here looking for how to target all files EXCEPT .spec.js files, try:
'**/!(*spec).js'
Which seems to work for me.
In the Karma used minimatch.js lib for mathing files. So you need rewrite you rules. For instance to exclude folder node node it should has
preprocessors: {
'framework/*[!node]/*.js':'coverage',
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With