【问题标题】:How to run mocha tests with reporter?如何与记者一起进行摩卡测试?
【发布时间】:2019-03-29 10:54:19
【问题描述】:

当我运行 npm test 时,它会输出:

 mocha ./tests/ --recursive --reporter mocha-junit-reporter

所有测试都运行良好。但是当我尝试调用 mocha ./tests/flickr/mytest --reporter junit-reporter 时,我得到了:

 Unknown "reporter": junit-reporter

如何正确传递?

【问题讨论】:

    标签: javascript npm mocha.js


    【解决方案1】:

    来自mocha-junit-reporterreadme

    # install the package
    npm install mocha-junit-reporter --save-dev
    
    # run the test with reporter
    mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=./path_to_your/file.xml
    

    【讨论】:

    • @callback 怎么了?控制台输出是什么?
    【解决方案2】:

    我在您的命令中发现了两个问题:

    mocha ./tests/flickr/mytest --reporter junit-reporter
    

    第一个问题是mocha,上面是来自全局节点模块的 mocha 命令。但是,在执行npm test 时,它实际上是针对我们node_modules 文件夹中的本地mocha 命令。

    第二个问题是记者的名字应该是mocha-junit-reporter而不是junit-reporter

    解决方案

    解决方法是针对本地mocha

    ./node_modules/.bin/mocha ./tests/flickr/mytest --reporter mocha-junit-reporter
    

    这是优选的解决方案。

    另一种解决方案是为全局节点模块安装mocha-junit-reporter,如下所示:

    npm install -g mocha-junit-reporter
    mocha ./tests/flickr/mytest --reporter mocha-junit-reporter
    

    这不太可取,因为与本地节点模块中的版本相比,您可以在全局中定位不同版本的 mocha 和 mocha-junit-reporter。

    干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-10
      相关资源
      最近更新 更多