2016-07-23 64 views
1

我使用grunt来运行我的mocha测试,并且在控制台中看到测试结果是OK,问题在于此任务正在生成报告,但是当您运行此HTML报告时,您只会看到在文本中运行的日志...我想要看到测试聚合,和摩卡单元测试运行好,我在这里失踪?Grunt为mocha测试提供html报告

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( '咕噜-摩卡试验');

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

我想这样或者我可以使用任何其他不错的HTML报告报表...

enter image description here

+0

你可以使用[mochawesome](https://github.com/adamgruber/mochawesome)。改变你的记者mochawesome! –

+0

@IsmailRBOUH - 看起来不错,但您能否提供如何在GRUNT中使用它的示例? –

+0

只要'npm install --save-dev mochawesome'然后改变'记者:'spec','给'记者:'mochawesome',','grunt-mocha-test'将会完成剩下的工作! –

回答

1

可以使用Mochawesome是使用自定义的记者与JavaScript测试框架,摩卡。它会产生一个很好的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' 
     } 
    } 
}, 
+0

我有另一个类似的问题,请参阅如果你可以帮助http://stackoverflow.com/questions/38549992/grunt-open-for-two-diffrent-files谢谢先生! –