作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个名为 jest-playground-1 的基本 create-react-app 设置,它的 package.json 文件为
{
"name": "jest-playground-1",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/dom": "^6.10.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.3",
"@testing-library/user-event": "^7.1.2",
"babel-jest": "^24.9.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"jest": {
"coverageReporters": [
"html",
"text"
]
}
}
当我运行 yarn test --coverage
(注意 --coverage
标志根据文档传递给 Jest)时,我希望看到所有我全新项目中的文件。
相反,我看不到任何文件,Jest runner 看起来像
No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
有趣的是,如果我使用 --watchAll
运行它,我会看到我期望的输出:
PASS src/App.test.js
✓ renders learn react link (49ms)
------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------------|----------|----------|----------|----------|-------------------|
All files | 2.44 | 0 | 6.25 | 2.44 | |
App.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 100 | 100 | 0 | 7,12 |
serviceWorker.js | 0 | 0 | 0 | 0 |... 25,132,133,134 |
------------------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 6.591s
Ran all test suites.
Watch Usage
› Press f to run only failed tests.
› Press o to only run tests related to changed files.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
如您所见,当使用 --watchAll
标志运行时,我在项目 App.js、index.js 和 serviceWorker.js 中看到了三个文件
我如何告诉 Jest 默认运行这些而不必传递 --watchAll 标志?
最佳答案
你可以通过 --watch "你的文件扩展名"
"scripts": {
.
.
.
"test": "react-scripts test --coverage --watch .test.js"
.
.
.
关于reactjs - 将 Jest 与 react-scripts 一起使用(通过 yarn 运行),如何在不必传递 watchAll 标志的情况下获得完整的覆盖率报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59289886/
我是一名优秀的程序员,十分优秀!