Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fix #1864: xunit missing output with --reporter-options output

Daniel St. Julese950ea6b3601
diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js
index 0694681c..d9f58b9f 100644
--- a/lib/reporters/xunit.js
+++ b/lib/reporters/xunit.js
@@ -77,6 +77,11 @@ function XUnit(runner, options) {
});
}
+/**
+ * Inherit from `Base.prototype`.
+ */
+inherits(XUnit, Base);
+
/**
* Override done to close the stream (if it's a file).
*
@@ -93,11 +98,6 @@ XUnit.prototype.done = function(failures, fn) {
}
};
-/**
- * Inherit from `Base.prototype`.
- */
-inherits(XUnit, Base);
-
/**
* Write out the given line.
*
diff --git a/test/integration/reporters.js b/test/integration/reporters.js
index 477e42f3..c29fccca 100644
--- a/test/integration/reporters.js
+++ b/test/integration/reporters.js
@@ -1,8 +1,12 @@
var assert = require('assert');
+var os = require('os');
+var fs = require('fs');
+var crypto = require('crypto');
+var path = require('path');
var run = require('./helpers').runMocha;
describe('reporters', function() {
- this.timeout(1000);
+ this.timeout(3000);
describe('markdown', function() {
var res;
@@ -28,4 +32,29 @@ describe('reporters', function() {
assert(res.output.indexOf(src) !== -1, 'No assert found');
});
});
+
+ describe('xunit', function() {
+ it('prints test cases with --reporter-options output (issue: 1864)', function(done) {
+ var randomStr = crypto.randomBytes(8).toString('hex');
+ var tmpDir = os.tmpDir().replace(new RegExp(path.sep + '$'), '');
+ var tmpFile = tmpDir + path.sep + 'test-issue-1864-' + randomStr + '.xml';
+
+ var args = ['--reporter=xunit', '--reporter-options', 'output=' + tmpFile];
+ var expectedOutput = [
+ '<testcase classname="suite" name="test1" time="0"/>',
+ '<testcase classname="suite" name="test2" time="0"/>',
+ '</testsuite>'
+ ].join('\n');
+
+ run('passing.js', args, function(err, result) {
+ if (err) return done(err);
+
+ var xml = fs.readFileSync(tmpFile, 'utf8');
+ fs.unlinkSync(tmpFile);
+
+ assert(xml.indexOf(expectedOutput) !== -1, 'Did not output all xml');
+ done(err);
+ });
+ });
+ });
});