Reputation: 846
I'm using a code for requiring all src files except main.js for coverage. What I need is to add one more file to ignore, or ignore all files that have this extension.
const srcContext = require.context('../../src/renderer', true, /^\.\/(?!main(\.js)?$)/)
This is what I'm using, I need to also exclude _icons.scss or exclude all .scss from coverage. I tried implementing some new regex but it does not work as expected
Thanks!
Upvotes: 3
Views: 309
Reputation: 626728
You may use the following updated pattern:
/^\.\/(?!(?:main(\.js)?|.*\.scss)$)/
^^^ ^^^^^^^^^^
The main point here is to add an alternative to the part that matches the file names after ./
.
Full pattern details:
^
- start of string\.\/
- a literal ./
substring(?!(?:main(\.js)?|.*\.scss)$)
- a negative lookahead that will fail the match if the following patterns match:
(?:main(\.js)?|.*\.scss)
- either main
or main.js
substrings (at the end of the string)|
- or.*\.scss
- any 0+ chars other than line break chars (.*
) up to the last .scss
substring that is at...$
- the end of the string.Upvotes: 1