我的所有测试都成功通过。但最后我有这样的信息:
32 passing (7s)
=== ATTENTION - INVALID USAGE OF CONSOLE LOGS DETECTED ===
[------------all logs here------------]
npm ERR! code ELIFECYCLE
npm ERR! errno 10
npm ERR! [email protected] test: 'lb-mocha --opts tests/mocha.opts'
npm ERR! Exit status 10
npm ERR!
npm ERR! Failed at the [email protected] test 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! C:\Users\XXX\AppData\Roaming\npm-cache\_logs\2019-04-03T09_57_58_382Z-debug.log
这是我的mocha.opts:
--allow-console-logs
--recursive
--require ts-node/register
tests/**/*.ts
--exit
你知道它为什么不起作用吗?
我发现了自己的错误。
--allow-console-logs
不是摩卡cli选项。这是一个“lb-mocha”cli选项,这意味着它只依赖于环回。这就是为什么在mocha.opts
文件中没有被mocha解释的原因。解决方案是将此参数从mocha选项文件提取到package.json
中的测试命令行,如下所示:
//package.json//
{
...
"script": {
...
"test": "lb-mocha --allow-console-logs --opts tests/mocha.opts"
...
}
...
}
不要忘记从mocha.opts
文件中删除参数:
//mocha.opts//
--recursive
--require ts-node/register
tests/**/*.ts
--exit
我希望它能挽救你的一天。