首页 > 解决方案 > 如何使用“spec”和“mocha-multi-reporters”将失败的测试结果输出到控制台

问题描述

当我使用 ' spec ' 作为报告器和 ' mocha-multi-reporters ' 作为 gulp 的服务器端测试的一部分时,我遇到了输出测试失败原因的问题。

例如,当我将 mocha 报告器设置为标准格式的“ spec ”时,如下所示:

.pipe(plugins.mocha({
        reporter: 'spec',
        timeout: 10000
      }))

我得到以下控制台输出:

Search
1) should be able to get empty search-result list
2) should be able to get search-result list with one element


0 passing (458ms)
2 failing

  1) Search GET should be able to get empty search-result list:
     AssertionError: expected Array [] to have property length of 1 (got 0)

  2) Search GET should be able to get search-result list with 2 elements:
     AssertionError: expected Array [] to have property length of 2 (got 0)

但是,当我将“ spec ”设置为“ mocha-multi-reporters ”的一部分时,如下所示:

.pipe(plugins.mocha({
        reporter: 'mocha-multi-reporters',
        reporterOptions: { "reporterEnabled": "spec" },
        timeout: 10000
      }))

我的控制台输出不显示失败的前 2 个原因,而是添加了一个额外的失败,并且只记录那个:

Search
1) should be able to get empty search-result list
2) should be able to get search-result list with one element

0 passing (528ms)
2 failing

  3) "after each" hook
error:  message=3 tests failed., showStack=false, showProperties=true, plugin=gulp-mocha, toString=function () { [native code] }

我已经尝试查看许多在线资源,以了解为什么会出现这种情况,但没有运气。有人知道为什么会这样吗?我现在使用mocha-multi-reporters的原因是我们也可以使用mocha-allure-reporter作为测试失败日志记录的一部分。


作为参考,我正在使用以下插件版本:

标签: javascriptnode.jsexpressgulpmocha.js

解决方案


推荐阅读