如何在 jest 的覆盖范围内忽略由 jest 生成的快照?
How ignore snapshot generated by jest on jest's coverage?
我正在为 jest 设置一些新配置,我忽略了一些文件,例如 *.stories.js
,但是当我使用 *.js.snap
或 *.snap
时,jest 无法正常工作.
我正在使用 react-scripts,同样使用 jest
例如,如果我只忽略 *.stories.js
,如下命令所示:
react-scripts test --coverage --collectCoverageFrom=!src/**/*.stories.js
------------------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------------------------------------------|----------|----------|----------|----------|-------------------|
All files | 92.98 | 90 | 96.43 | 94.34 | |
components/atoms/grid | 100 | 100 | 100 | 100 | |
Grid.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 0 | 0 | 0 | |
components/atoms/grid/__snapshots__ | 0 | 100 | 100 | 0 | |
Grid.test.js.snap | 0 | 100 | 100 | 0 | 1 |
components/atoms/grid/components | 100 | 100 | 100 | 100 | |
Cell.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 0 | 0 | 0 | |
components/atoms/grid/components/__snapshots__ | 0 | 100 | 100 | 0 | |
Cell.test.js.snap | 0 | 100 | 100 | 0 | 1 |
components/atoms/grid/helpers | 0 | 0 | 0 | 0 | |
calcOffset.js | 0 | 0 | 0 | 0 | |
index.js | 0 | 0 | 0 | 0 | |
components/atoms/text | 100 | 100 | 100 | 100 | |
Text.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 0 | 0 | 0 | |
components/atoms/text/__snapshots__ | 0 | 100 | 100 | 0 | |
Text.test.js.snap | 0 | 100 | 100 | 0 | 1 |
helpers | 100 | 100 | 100 | 100 | |
breakpoints.js | 100 | 100 | 100 | 100 | |
calcPercent.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 0 | 0 | 0 | |
provider | 100 | 50 | 100 | 100 | |
style.js | 100 | 50 | 100 | 100 | 9 |
theme | 87.5 | 100 | 50 | 100 | |
GlobalStyle.js | 100 | 100 | 100 | 100 | |
colors.js | 100 | 100 | 100 | 100 | |
index.js | 83.33 | 100 | 50 | 100 | |
------------------------------------------------|----------|----------|----------|----------|-------------------|
但是如果我添加 *.js.snap
找不到其他文件 snap
react-scripts test --coverage --collectCoverageFrom=!src/**/*.stories.js --collectCoverageFrom=!src/**/*.js.snap
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
我解决了确实在里面添加了配置package.json
"jest": {
"collectCoverageFrom": [
"!<rootDir>/src/**/*.stories.js",
"src/**/*.{js,jsx}",
"!<rootDir>/node_modules/"
]
},
我正在为 jest 设置一些新配置,我忽略了一些文件,例如 *.stories.js
,但是当我使用 *.js.snap
或 *.snap
时,jest 无法正常工作.
我正在使用 react-scripts,同样使用 jest
例如,如果我只忽略 *.stories.js
,如下命令所示:
react-scripts test --coverage --collectCoverageFrom=!src/**/*.stories.js
------------------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------------------------------------------|----------|----------|----------|----------|-------------------|
All files | 92.98 | 90 | 96.43 | 94.34 | |
components/atoms/grid | 100 | 100 | 100 | 100 | |
Grid.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 0 | 0 | 0 | |
components/atoms/grid/__snapshots__ | 0 | 100 | 100 | 0 | |
Grid.test.js.snap | 0 | 100 | 100 | 0 | 1 |
components/atoms/grid/components | 100 | 100 | 100 | 100 | |
Cell.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 0 | 0 | 0 | |
components/atoms/grid/components/__snapshots__ | 0 | 100 | 100 | 0 | |
Cell.test.js.snap | 0 | 100 | 100 | 0 | 1 |
components/atoms/grid/helpers | 0 | 0 | 0 | 0 | |
calcOffset.js | 0 | 0 | 0 | 0 | |
index.js | 0 | 0 | 0 | 0 | |
components/atoms/text | 100 | 100 | 100 | 100 | |
Text.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 0 | 0 | 0 | |
components/atoms/text/__snapshots__ | 0 | 100 | 100 | 0 | |
Text.test.js.snap | 0 | 100 | 100 | 0 | 1 |
helpers | 100 | 100 | 100 | 100 | |
breakpoints.js | 100 | 100 | 100 | 100 | |
calcPercent.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 0 | 0 | 0 | |
provider | 100 | 50 | 100 | 100 | |
style.js | 100 | 50 | 100 | 100 | 9 |
theme | 87.5 | 100 | 50 | 100 | |
GlobalStyle.js | 100 | 100 | 100 | 100 | |
colors.js | 100 | 100 | 100 | 100 | |
index.js | 83.33 | 100 | 50 | 100 | |
------------------------------------------------|----------|----------|----------|----------|-------------------|
但是如果我添加 *.js.snap
找不到其他文件 snap
react-scripts test --coverage --collectCoverageFrom=!src/**/*.stories.js --collectCoverageFrom=!src/**/*.js.snap
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
我解决了确实在里面添加了配置package.json
"jest": {
"collectCoverageFrom": [
"!<rootDir>/src/**/*.stories.js",
"src/**/*.{js,jsx}",
"!<rootDir>/node_modules/"
]
},