Skip to content

armgit / mocha

Public Imported from GitHub
0

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

make sure the xunit output dir exists before trying to write to it

Ian W. Remmel1cc21a9ca993
diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js
index d9f58b9f..cf3411e6 100644
--- a/lib/reporters/xunit.js
+++ b/lib/reporters/xunit.js
@@ -7,6 +7,7 @@ var utils = require('../utils');
var inherits = utils.inherits;
var fs = require('fs');
var escape = utils.escape;
+var mkdirp = require('mkdirp');
/**
* Save timer references to avoid Sinon interfering (see GH-237).
@@ -40,10 +41,11 @@ function XUnit(runner, options) {
var self = this;
if (options.reporterOptions && options.reporterOptions.output) {
- if (!fs.createWriteStream) {
- throw new Error('file output not supported in browser');
- }
- self.fileStream = fs.createWriteStream(options.reporterOptions.output);
+ if (! fs.createWriteStream) {
+ throw new Error('file output not supported in browser');
+ }
+ mkdirp.sync(path.dirname(options.reporterOptions.output));
+ self.fileStream = fs.createWriteStream(options.reporterOptions.output);
}
runner.on('pending', function(test) {