karma.conf.js使用以下设置时,unit test会不停地跑。
autoWatch: false,
singleRun: true,
想只跑一次,发现命令行参数不起效果。
npm run ng test --watch=false --code-coverage
原来需要加--,这是npm传递参数给script的方法。
npm run ng test -- --watch=false --code-coverage
npm help run查看详细说明。
As of npm@2.0.0, you can use custom arguments when executing scripts. The special option – is used by getopt to delimit the end of the options. npm will pass all the arguments after the – directly to your script:
npm run test – --grep=“pattern”
The arguments will only be passed to the script specified after npm run and not to any pre or post script.
不过不应该整天打这么长的命令行,复杂的命令都应该放到script里。
package.json
"test": "ng test --watch=false --code-coverage",
然后npm test就可以。
Karma单元测试配置
本文解决Karma单元测试中unittest持续运行的问题,通过正确配置karma.conf.js文件,使用autoWatch:false与singleRun:true参数,并将命令行参数修改为npm run ngtest -- --watch=false --code-coverage,实现unittest仅执行一次。
1870

被折叠的 条评论
为什么被折叠?



