[英]Exclude files from test
I'm using a code for requiring all src files except main.js for coverage. 我正在使用代码来要求除main.js之外的所有src文件以进行覆盖。 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. 这是我使用的是什么,我也需要排除_icons.scss或覆盖排除所有.scss。 I tried implementing some new regex but it does not work as expected
我尝试实现一些新的正则表达式,但它没有按预期工作
Thanks! 谢谢!
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)$)
- 如果以下模式匹配,将导致匹配失败的负前瞻:
(?:main(\\.js)?|.*\\.scss)
- either main
or main.js
substrings (at the end of the string) (?:main(\\.js)?|.*\\.scss)
- main
或main.js
子串(在字符串的末尾) |
- or .*\\.scss
- any 0+ chars other than line break chars ( .*
) up to the last .scss
substring that is at... .*\\.scss
- 除了换行符( .*
)之外的任何0+字符,直到最后一个.scss
子字符串... $
- the end of the string. $
- 字符串的结尾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.