【问题标题】:How to exit Mocha after test execution?测试执行后如何退出 Mocha?
【发布时间】:2021-01-24 14:10:11
【问题描述】:

我希望 mocha 在执行完所有测试后退出,以便伊斯坦布尔可以检查代码覆盖率,我在 package.json 中使用了 --exit,但它似乎不起作用。

我错过了什么吗?

"scripts": {
"test": "istanbul cover node_modules/mocha/bin/_mocha test/Testcases/ --exit" 
 }

所有测试文件都在test/Testcases/文件夹下,mocha在执行完后应该退出

附:我使用的是 windows 操作系统,所以我手动引用 bin 文件。

【问题讨论】:

    标签: node.js mocha.js istanbul


    【解决方案1】:

    使用--exit 应该可以。

    顺便说一句,我用这个,我认为在有或没有覆盖的情况下执行起来更灵活:

    "scripts": {
        "test": "mocha tests --timeout 4000 --reporter mochawesome --exit",
        "coverage": "nyc --reporter=html --reporter=text npm run test"
      }
    

    因此,如果您运行npm run test,您将只获得测试,但使用npm run coverage 也会显示覆盖率。

    请注意,coverage 遵循此模式:

    nyc + arguments + mocha execution

    但只使用一行,这也有效:

    "test": "nyc --reporter=html --reporter=text mocha tests --timeout 4000 --reporter mochawesome --exit"
    

    删除多余的参数:

    "test": "nyc --reporter=html mocha tests --exit"
    

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 2023-03-06
      • 1970-01-01
      相关资源
      最近更新 更多