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.
代言2017-06-12 09:30:45
Remove the extra spaces in the middle and enclose | in parentheses on both sides.
我想大声告诉你2017-06-12 09:30:45
Just enclose the body of the regular expression with "[]"
For example:
console.log(/^[\.\/(?!main(\.js)?$)|^\.\/(?!style.*)]/.test(s))