【问题标题】:Grunt provide html report for mocha testGrunt 为 mocha 测试提供 html 报告
【发布时间】:2016-07-24 01:14:19
【问题描述】:

我使用 grunt 运行我的 mocha 测试,我在控制台中看到了测试结果,这没问题,问题是这个任务正在生成报告,但是当你运行这个 HTML 报告时,你只会看到运行在文本中的日志。 ..我想查看测试聚合,并且 mocha 单元测试运行正常,我在这里缺少什么?

mochaTest: {
    test: {
        options: {
            reporter: 'spec',
            colors: true,
            summery: true,
            captureFile: 'results.html', // Optionally capture the reporter output to a file
            quiet: false, // Optionally suppress output to standard out (defaults to false)
            clearRequireCache: true // Optionally clear the require cache before running tests (defaults to false)
        },
        src: ['test/*spec.js'],
        excludes: ['plugins']
    },
    'travis-cov': {
        options: {
            reporter: 'travis-cov'
        }
    }
},

我使用包 grunt.loadNpmTasks('grunt-mocha-test');

https://github.com/pghalliday/grunt-mocha-test

我想要这样的报告或我可以使用的任何其他漂亮的 html 报告...

【问题讨论】:

  • 您可以使用mochawesome。把你的记者换成mochawesome
  • @IsmailRBOUH - 看起来不错,但您能举例说明如何在 GRUNT 中使用它吗?
  • 只需 npm install --save-dev mochawesome 然后将 reporter: 'spec', 更改为 reporter: 'mochawesome',grunt-mocha-test 将完成剩下的工作!
  • @IsmailRBOUH - 谢谢,我安装了软件包并使用 mochaTest 运行 grunt:{ test: { options: { 记者:'mochawesome',没有任何改变,我还想念别的吗?
  • @IsmailRBOUH - 对不起我的错 :) 请添加它作为答案,我会关闭它,非常感谢!

标签: javascript node.js gruntjs mocha.js


【解决方案1】:

您可以使用 Mochawesome 是一个自定义报告器,用于 Javascript 测试框架 mocha。它会生成一个漂亮的 HTML/CSS 报告,帮助可视化您的测试套件:

首先,你需要安装插件:

npm install --save-dev mochawesome

然后你改变你的grunt-mocha-testreporter

mochaTest: {
    test: {
        options: {
            reporter: 'mochawesome', //You need to change this !
            colors: true,
            summery: true,
            captureFile: 'results.html',
            quiet: false,
            clearRequireCache: true
        },
        src: ['test/*spec.js'],
        excludes: ['plugins']
    },
    'travis-cov': {
        options: {
            reporter: 'travis-cov'
        }
    }
},

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-05
  • 1970-01-01
相关资源
最近更新 更多