From 8073ef1757b19261d921a4a8e88ba73d92262be2 Mon Sep 17 00:00:00 2001 From: Mike Moulton Date: Fri, 6 Dec 2013 11:18:57 -0700 Subject: [PATCH 1/2] Making directory if it does not yet exist. Resolves #19 --- lib/mocha.js | 17 ++++++++++++++--- package.json | 3 ++- test/mocha.js | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/mocha.js b/lib/mocha.js index 83a9155..5fb8d1f 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -8,6 +8,7 @@ var grunt = require('grunt'), path = require('path'), fs = require('fs'), + mkdirp = require('mkdirp'), coveralls = require('./coveralls'); var BOOL_OPTIONS = [ @@ -153,9 +154,19 @@ function mocha(options, callback) { // Save report to disk } else if (options.output) { - var filename = path.resolve(options.output); - fs.writeFile(filename, String(result), 'utf8', function (err) { - callback(err); + var filename = path.resolve(options.output), + dir = path.dirname(filename); + + fs.stat(dir, function (err) { + + if (err) { + mkdirp.sync(dir); + } + + fs.writeFile(filename, String(result), 'utf8', function (err) { + callback(err); + }); + }); // Send report to stdout diff --git a/package.json b/package.json index e40246f..05a6e95 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "blanket": "1.1.5", "lcov-parse": "0.0.5", "request": "2.27.0", - "mocha-lcov-reporter": "0.0.1" + "mocha-lcov-reporter": "0.0.1", + "mkdirp": "0.3.5" }, "peerDependencies": { "grunt": "0.4.x" diff --git a/test/mocha.js b/test/mocha.js index 17d899b..cd794dc 100644 --- a/test/mocha.js +++ b/test/mocha.js @@ -143,6 +143,25 @@ describe('Unit Tests', function () { }); }); + it('should test coverage output when directory does not exist', function (done) { + + mocha({ + files: [__dirname + '/fixture/pass.js'], + quiet: true, + reporter: 'json-cov', + output: 'test/new/out.json' + }, function (error) { + should.not.exist(error); + var filename = path.resolve('test/new/out.json'), + dir = path.dirname(filename); + var jsonOutput = JSON.parse(fs.readFileSync(filename)); + fs.unlinkSync(filename); + fs.rmdirSync(dir); + jsonOutput.coverage.should.equals(100); + done(); + }); + }); + it('should test coveralls integration', function (done) { mocha({ From e85e190316f6c4b19542944b4bb58ee89d92c258 Mon Sep 17 00:00:00 2001 From: Mike Moulton Date: Fri, 6 Dec 2013 11:20:40 -0700 Subject: [PATCH 2/2] Release v0.1.1 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 715cfde..27e845d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,3 +35,7 @@ * mocha 0.14.x * blanket 1.1.5 * Changed search location for `mocha` (resolved #17) + +### 0.1.1 (Dec 6, 2013) + +* Will now create any missing directories when writing output to a file (resolved #19) diff --git a/package.json b/package.json index 05a6e95..61d86e0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-mocha-cov", "description": "Run Mocha server-side tests in Grunt with code coverage support and optional integration to coveralls.io.", - "version": "0.1.0", + "version": "0.1.1", "author": "Mike Moulton (http://meltmedia.com)", "contributors": [ "Gregg Caines (https://github.com/cainus/node-coveralls)",