如何在玩笑的报道中忽略玩笑生成的快照?

时间:2019-09-19 16:56:27

标签: javascript reactjs unit-testing testing jestjs

我正在为笑话设置一些新配置,但忽略了诸如*.stories.js之类的某些文件,但是当我使用*.js.snap*.snap时,笑话无法正常工作。< / p>

我正在使用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 |                   |
----------|----------|----------|----------|----------|-------------------|

1 个答案:

答案 0 :(得分:0)

我解决了确实在package.json内添加了配置

  "jest": {
    "collectCoverageFrom": [
      "!<rootDir>/src/**/*.stories.js",
      "src/**/*.{js,jsx}",
      "!<rootDir>/node_modules/"
    ]
  },