我想将我的jest配置从我的package.json中移出,我试图使用- config作为建议的这里,但是得到了错误argv.config.match is not a function
。
package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --config jest.config.js",
"eject": "react-scripts eject",
},
cli
hutber@hutber-mac:/var/www/management/node$ npm test -u
> management-fresh@0.1.0 test /var/www/management/node
> react-scripts test --config jest.config.js
Usage: test.js [--config=<pathToConfigFile>] [TestPathPattern]
argv.config.match is not a function
npm ERR! Test failed. See above for more details.
发布于 2020-04-27 21:26:59
对我来说,附加-- --config=jest.config.js
起了作用。
所以,在您的情况下,整个字符串react-scripts test -- --config jest.config.js
。
发布于 2020-08-01 17:30:12
TL;博士
在选项之前添加--
。
"test": "react-scripts test -- --config=jest.config.js",
这里的问题是react-scripts
没有看到传递给它的选项。我们可以通过直接运行它来演示这一点。
./node_modules/.bin/react-scripts test --config=jest.config.js
# argv.config.match is not a function
./node_modules/.bin/react-scripts test -- --config=jest.config.js
# This works.
变体
如何将选项传递给脚本,取决于您使用的、npm、或Yarn的哪个版本。为了完整起见,以下是这些变化的结果:
# This runs, but completely ignores the option.
npm test --config=jest.config.js
# These result in "argv.config.match is not a function," indicating that the
# options were not understood.
npm test -- --config=jest.config.js
yarn test -- --config=jest.config.js
yarn test --config=jest.config.js
创建react应用程序在package.json
中设置测试脚本
"test": "react-scripts test",
您可以像这样设置其他选项。
"test": "react-scripts test -- --config=jest.config.js",
如果您想通过CLI发送选项,这样的操作可能会奏效。
"test": "react-scripts test --",
yarn test --bail
# comes through as
react-scripts test -- --bail
资源
以下是解释不同用法的几个资源。
发布于 2021-09-03 08:25:31
对我来说,在package.json
文件中添加package.json
作为密钥是有效的。将所有必需的配置添加为jest
键而不是jest.config.js中的对象
"jest": {
"collectCoverageFrom": [
"src/**/*.js",
"!**/node_modules/**"
],
"coverageReporters": [
"text-summary",
"lcov",
"cobertura"
],
"testMatch": [
"**/*.test.js"
]
},
https://stackoverflow.com/questions/59878153
复制相似问题