我在lint-staged
插件方面遇到了一个奇怪的问题。它之前工作正常。
所以问题是当我运行npm run test
它时会生成覆盖率报告。
"test": "cross-env CI=true react-scripts test --coverage",
但是当我使用husky
pre-commit 运行相同的命令并且lint-staged
它不起作用时。当我检查控制台时,我发现它正在针对已修改的文件运行。
> portal@0.1.0 test /Users/carlos/Desktop/portal
> cross-env CI=true react-scripts test --coverage "/Users/carlos/Desktop/portal/src/container/Auth/Login.page.js"
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/carlos/Desktop/portal
44 files checked.
testMatch: /Users/carlos/Desktop/portal/src/**/__tests__/**/*.{js,jsx,ts,tsx}, /Users/carlos/Desktop/portal/src/**/*.{spec,test}.{js,jsx,ts,tsx} - 6 matches
testPathIgnorePatterns: /node_modules/ - 44 matches
testRegex: - 0 matches
Pattern: /Users/carlos/Desktop/portal/src/container/Auth/Login.page.js - 0 matches
npm ERR! code ELIFECYCLE
npm ERR! errno 1
有明显区别
当我跑
npm run test
它运行
cross-env CI=true react-scripts test --coverage
当npm run test
被 husky 和 lint-staged 调用时
它被称为
cross-env CI=true react-scripts test --coverage "/Users/carlos/Desktop/portal/src/container/Auth/Login.page.js"
之后附加了文件路径--covrage
这是我的包 JSON 配置。
"jest": {
"collectCoverageFrom": [
"src/**/*.js"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
},
"eslintConfig": {
"extends": "react-app"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"prettier --write",
"eslint src/ --fix",
"npm run test",
"git add"
]
}
注意:当我使用 lint-staged 时,只有当我使用pre-commit:npm run test
它工作正常时才会发生这种情况。