【发布时间】:2020-04-23 21:47:56
【问题描述】:
我有 jest 和 jest-puppeteer 设置来运行测试。运行测试很简单,使用:
jest test.test --config="path/to/config.json"
但是当我把它放到 package.json 中时:
...
"scripts": {
"test:jest": "jest test.test --config=\"path/to/config.json\""
},
...
然后运行:
npm run test:jest
测试正常运行,但最后出现以下错误:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@1.0.0 jest:temp: `jest test.test --config="path/to/config.json"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@1.0.0 jest:temp script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/obihill/.npm/_logs/2020-04-23T12_18_23_546Z-debug.log
在做了一些研究后,我发现这是因为某些测试可能会失败。果然,我设置所有测试通过,错误不再出现。
我遇到的问题是我需要运行此测试,然后依次运行第二个测试:
npm run test:jest && npm run test:postjest
但由于测试失败和生成的ELIFECYCLE 代码,第二个命令永远不会运行。经过一番研究,我找到了a way to suppress the errors。所以现在我运行以下命令:
npm run test:jest --silent && npm run test:postjest
并且没有错误,但test:postjest 永远不会运行。所有测试都必须通过 test:jest 才能运行第二个命令。
有没有办法覆盖此行为并使npm run test:postjest 无论如何按顺序运行?
【问题讨论】:
标签: node.js unit-testing npm jestjs