bash – 从shell脚本运行jest测试 – 有失败导致脚本退出
发布时间:2020-12-16 01:58:31 所属栏目:安全 来源:网络整理
导读:我有一个普通的package.json,使用npm test命令运行 jest个测试. package.json的相关部分如下所示: { "scripts": { "test": "jest","jest": { "scriptPreprocessor": "../shared/preprocessor.js" }} shell脚本如下所示: script_dir="$(cd "$(dirname "${BA
我有一个普通的package.json,使用npm test命令运行
jest个测试. package.json的相关部分如下所示:
{ "scripts": { "test": "jest","jest": { "scriptPreprocessor": "../shared/preprocessor.js" } } shell脚本如下所示: script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" parent_dir="$script_dir/.." echo echo "Running all tests..." find "$parent_dir" -name package.json -maxdepth 2 -execdir npm test ; 现在,当一个jest测试失败时,bash脚本不会以失败状态退出.我希望它能够与Jenkins一起创建CI循环.开玩笑测试失败的示例如下: FAIL js/components/__tests__/ExperienceCampaign-tests.js (13.19s) ● ExperienceCampaign ? listening to ExperienceCampaignStore ? it starts listening when the component is mounted - Expected: true toBe: false at Spec.<anonymous> (/Users/jonathan/experience-studio/campaign/js/components/__tests__/ExperienceCampaign-tests.js:54:26) at Timer.listOnTimeout [as ontimeout] (timers.js:112:15) 1 test failed,0 tests passed (1 total) Run time: 13.748s npm ERR! Test failed. See above for more details. npm ERR! not ok code 0 任何帮助表示赞赏. 解决方法
jest有一个–forceExit标志,可用于…强制退出:D.
只需将其添加到您的脚本中. 您可能在测试中做了一些异步操作,并没有及时返回回调.可能想仔细看看. { "scripts": { "test": "jest --forceExit","jest": { "scriptPreprocessor": "../shared/preprocessor.js" } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |