When using karma for code coverage testing, remove main.js
// require all src files except main.js for coverage.
// you can also change this to match only the subset of files that
// you want coverage for.
const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/)
srcContext.keys().forEach(srcContext)
Later I added a style folder, which contains scss files, and I also want to remove this folder too
ss = ["./main.js","./style","./maaa.js","./style/sss.scss"]
ss.forEach(function(s){
console.log(s)
console.log(/^\.\/(?!main(\.js)?$)/.test(s))
console.log(/^\.\/(?!style.*)/.test(s))
console.log(/^\.\/(?!main(\.js)?$) | ^\.\/(?!style.*)/.test(s))
})
./main.js
false
true
false
./style
true
false
false
./maaa.js
true
true
false
./style/sss.scss
true
false
false
The two separate regular expressions seem to be correct, but using | together does not achieve the expected effect. There is really no other way. Please help me.
Remove the extra spaces in the middle and enclose | in parentheses on both sides.
Just enclose the body of the regular expression with "[]"
For example: