Jak*_*kub 12 xunit mocha.js node.js gruntjs
我正在使用grunt-mocha-test来运行我们的mocha测试.我希望能够运行测试并生成xunit报告并获得覆盖率(使用blanket.js).我的gruntfile中有以下部分:
mochaTest: {
'unit-jenkins': {
options: {
reporter: 'XUnit',
require: paths.test + '/blanket',
captureFile: paths.tmp + '/xunit.xml'
},
src: [paths.test + '/unit/**/*.js'],
},
'integration-jenkins': {
options: {
reporter: 'XUnit',
require: paths.test + '/blanket',
captureFile: paths.tmp + '/xunit.xml'
},
src: [paths.test + '/integration/**/*.js']
},
coverage: {
options: {
reporter: 'html-cov',
quiet: true,
captureFile: paths.tmp + '/coverage.html'
},
src: [paths.test + '/**/*.js']
}
},
Run Code Online (Sandbox Code Playgroud)
和
grunt.registerTask('test-jenkins', [
'mochaTest:unit-jenkins', // run unit tests
'mochaTest:integration-jenkins', // run unit tests
]);
Run Code Online (Sandbox Code Playgroud)
当我运行grunt test-jenkins时,我可以在控制台上看到测试输出和xunit输出.此外,创建了xunit文件,但它包含测试输出和xunit输出,例如:
[14:30:17.164Z] TRACE App: HTTP Response /versions
HTTP/1.1 200 OK
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 46
ETag: "-1409762768"
Date: Mon, 17 Feb 2014 14:30:17 GMT
Connection: close
<testsuite name="Mocha Tests" tests="1" failures="0" errors="0" skipped="0" timestamp="Mon, 17 Feb 2014 14:30:17 GMT" time="0.029">
<testcase classname="Application" name="should contain description of API versions" time="0.028"/>
</testsuite>
Run Code Online (Sandbox Code Playgroud)
如何配置grunt-mocha-test以使xunit输出文件仅包含xunit输出?
小智 6
我和Selenium有同样的问题.我通过以下任务解决了这个问题:
var outputFile = process.env.MOCHA_OUTPUT_FILE || 'xunit_results.xml';
grunt.registerTask('cleanXunitFile', 'Remove Selenium/WebDriver output from xunit file', function() {
if (grunt.file.exists('./' + outputFile)) {
var file = grunt.file.read('./' + outputFile);
if (file.indexOf("<testsuite")) {
grunt.file.write('./' + outputFile, file.substring(file.indexOf("<testsuite")));
}
}
else {
grunt.log.error("'cleanXunitFile' task was specified but file " + outputFile + " does not exist.");
}
});
Run Code Online (Sandbox Code Playgroud)
我可以在控制台上看到测试输出和 xunit 输出。此外,创建了 xunit 文件,但是它由测试输出和 xunit 输出组成
恐怕这是摩卡的一个已知错误。
有一个待处理的拉取请求试图解决这些问题,请参阅 https://github.com/visionmedia/mocha/pull/1218