Skip to content

Commit

Permalink
Merge pull request #20 from mmoulton/develop
Browse files Browse the repository at this point in the history
Release v0.1.1
  • Loading branch information
mmoulton committed Dec 6, 2013
2 parents 65e4aa7 + e85e190 commit 577b145
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 14 additions & 3 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
var grunt = require('grunt'),
path = require('path'),
fs = require('fs'),
mkdirp = require('mkdirp'),
coveralls = require('./coveralls');

var BOOL_OPTIONS = [
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <mike@meltmedia.com> (http://meltmedia.com)",
"contributors": [
"Gregg Caines <gregg@caines.ca> (https://github.com/cainus/node-coveralls)",
Expand Down Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 577b145

Please sign in to comment.