Skip to content

Commit

Permalink
Resolve relative path to external bundle when passing to consolify
Browse files Browse the repository at this point in the history
Fixes mantoni#140
Add Test Coverage for --bundle and --consolify args

* Fail with a useful error if the user tries to use --bundle wihout --consolify
* Add test-coverage to check that both the consolify'd HTML and extracted bundle are written to disk
  • Loading branch information
jonnyreeves committed Jul 15, 2016
1 parent b74bf9e commit 290fd38
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 3 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ rules:
no-return-assign: 2
no-self-compare: 2
no-spaced-func: 2
no-sync: 2
no-throw-literal: 2
no-trailing-spaces: 2
no-undef-init: 2
Expand Down
1 change: 0 additions & 1 deletion lib/consolify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var fs = require('fs');
var through = require('through2');
var consolify = require('consolify');


module.exports = function (b, opts) {
consolify(b, {
bundle: opts.bundle
Expand Down
5 changes: 5 additions & 0 deletions lib/mochify.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ module.exports = function (_, opts) {
}
}

if (opts.bundle && !opts.consolify) {
console.log('--bundle must be used with --consolify option\n');
process.exit(1);
}

if (opts.invert && !opts.grep) {
console.log('--invert must be used with --grep option\n');
process.exit(1);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"which": "^1.2.1"
},
"devDependencies": {
"eslint": "^1.10.3"
"eslint": "^1.10.3",
"tmp": "0.0.28"
},
"files": [
"bin",
Expand Down
41 changes: 41 additions & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
'use strict';

var assert = require('assert');
var fs = require('fs');
var through = require('through2');
var api = require('./fixture/api');
var sandbox = require('./fixture/sandbox');
var mochify = require('../lib/mochify');


Expand Down Expand Up @@ -118,4 +120,43 @@ describe('api', function () {
+ '# fail 0\n', done));
});

it('should write a test-runner html document when --consolify is used',
sandbox(function (done, tmpdir) {
mochify('./test/fixture/passes/test/*.js', {
consolify: tmpdir + '/output.html'
}).bundle(function (err) {
if (err) {
return done(err);
}
try {
fs.statSync(tmpdir + '/output.html');
done();
} catch (e) {
done(e);
}
});
})
);

it('should extract the script to an external bundle when --bundle is used'
+ ' with --consolify',
sandbox(function (done, tmpdir) {
mochify('./test/fixture/passes/test/*.js', {
consolify: tmpdir + '/output.html',
bundle: tmpdir + '/bundle.js'
}).bundle(function (err) {
if (err) {
return done(err);
}
try {
fs.statSync(tmpdir + '/output.html');
fs.statSync(tmpdir + '/bundle.js');
done();
} catch (e) {
done(e);
}
});
})
);

});
8 changes: 8 additions & 0 deletions test/args-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,12 @@ describe('args', function () {
});
});

it('fails with bundle but no consolify option', function (done) {
run('passes', ['--bundle', 'foo.js'], function (code, stdout) {
assert.equal(code, 1);
assert.equal(stdout, '--bundle must be used with --consolify option\n\n');
done();
});
});

});
28 changes: 28 additions & 0 deletions test/fixture/sandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* mochify.js
*
* Copyright (c) 2014 Maximilian Antoni <[email protected]>
*
* @license MIT
*/
'use strict';

var tmp = require('tmp');

// sandbox creates a temporary directory which will be automatically
// removed after the testcase completes.
function sandbox(testfn) {
return function (done) {
var tmpOpts = {
unsafeCleanup: true
};
tmp.dir(tmpOpts, function (err, tmpdir) {
if (err) {
return done(err);
}
testfn(done, tmpdir);
});
};
}

module.exports = sandbox;

0 comments on commit 290fd38

Please sign in to comment.