【问题标题】:mocha error : invalide usage of console logs detectedmocha 错误:检测到控制台日志的无效使用
【发布时间】:2019-08-24 20:16:40
【问题描述】:

我所有的测试都成功通过了。 但最后我收到了这条消息:

  32 passing (7s)
=== ATTENTION - INVALID USAGE OF CONSOLE LOGS DETECTED ===
[------------all logs here------------]
npm ERR! code ELIFECYCLE
npm ERR! errno 10
npm ERR! MyProject@1.0.0 test: 'lb-mocha --opts tests/mocha.opts'
npm ERR! Exit status 10
npm ERR!
npm ERR! Failed at the MyProject@1.0.0 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

你知道为什么它不工作吗?

【问题讨论】:

    标签: node.js typescript mocha.js loopback


    【解决方案1】:

    我发现了我的错误。

    --allow-console-logs 不是 mocha cli 选项。这是一个“lb-mocha”cli 选项,这意味着它只依赖于环回。这就是为什么它没有被 mocha.opts 文件中的 mocha 解释。解决办法是把这个参数从 mocha 选项文件中提取到package.json 中的 test commande 行,见下图:

    //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
    

    我希望它能拯救你的一天。

    【讨论】:

      猜你喜欢
      • 2015-10-05
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 2016-01-31
      • 2018-10-28
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多