From 1cc21a9ca99330644d121087198dbcfed8be0e94 Mon Sep 17 00:00:00 2001 From: "Ian W. Remmel" Date: Thu, 3 Dec 2015 18:56:15 -0800 Subject: [PATCH 1/2] make sure the xunit output dir exists before trying to write to it Fixes #1994 --- lib/reporters/xunit.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js index d9f58b9f05..cf3411e6c1 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) { From d09c035f7e6304b37fef2ebc9e1cd2783bf39562 Mon Sep 17 00:00:00 2001 From: "Ian W. Remmel" Date: Wed, 9 Dec 2015 09:20:48 -0800 Subject: [PATCH 2/2] fix lint errors --- lib/reporters/xunit.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js index cf3411e6c1..7c16302c63 100644 --- a/lib/reporters/xunit.js +++ b/lib/reporters/xunit.js @@ -8,6 +8,7 @@ var inherits = utils.inherits; var fs = require('fs'); var escape = utils.escape; var mkdirp = require('mkdirp'); +var path = require('path'); /** * Save timer references to avoid Sinon interfering (see GH-237). @@ -41,11 +42,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'); - } - mkdirp.sync(path.dirname(options.reporterOptions.output)); - 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) {