Excluding files from preprocessor
See original GitHub issueIn my current code base I keep all files (including tests) for a module/component in the same folder, e.g.
The problem is that I want test coverage for the module. Before I moved the specs into the module folder I used the following preprocessor:
preprocessors = {
'**/resources/javascript/**/*.js': 'coverage'
};
Naturally that donโt work anymore since it also includes all my tests (thereby increasing my code coverage metrics by quite a bit). As all the tests are named *Spec.js
it should be quite simple to exclude them, but I canโt seem to find a way given how the preprocessors are currently specified.
Excluding stuff when globbing appears to be quite difficult. Would it be possible to give the preprocessor an array of files instead? That would enable me to do the exclusion logic myself. Any thoughts on how this can be solved?
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:17 (5 by maintainers)
Top GitHub Comments
Hereโs a complex example that combines a number of techniques found in various threads on the topic.
Imagine we have the following extermely contrived folder structure:
And weโd like to preprocess all files that end with
.js
insrc/
and its subdirectories, except those undersrc/vendor/
andsrc/test/
or any file in any folder containing.test
. Phew!So, we create a pattern that uses brace expansion to become two patterns, including a negation for the
.test
string and a.js
to match only JavaScript files:This results in:
Hereโs a test for this pattern:
It works, but itโs not pretty to look at. I hope this helps someone.
I always found it odd how some people instinctively separate implementation and tests into src and test directories, or other split out assets. They are usually closely related and you end up with parallel hierarchies. Then you need IDE support to relate them again on the assumption that test and source is called the same which is pushes you towards writing a test for each class / function which leads to box ticking rather than thinking about the problem at hand. Tools should get out of the way and let you structure a project in a way that works for the problem and project at hand.