2016-07-23 41 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謝謝先生! –