Skip to content

Commit bdaaabe

Browse files
committed
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
1 parent b74bf9e commit bdaaabe

File tree

7 files changed

+84
-3
lines changed

7 files changed

+84
-3
lines changed

.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ rules:
4343
no-return-assign: 2
4444
no-self-compare: 2
4545
no-spaced-func: 2
46-
no-sync: 2
4746
no-throw-literal: 2
4847
no-trailing-spaces: 2
4948
no-undef-init: 2

lib/consolify.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ var fs = require('fs');
1111
var through = require('through2');
1212
var consolify = require('consolify');
1313

14-
1514
module.exports = function (b, opts) {
1615
consolify(b, {
1716
bundle: opts.bundle

lib/mochify.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ module.exports = function (_, opts) {
6565
}
6666
}
6767

68+
if (opts.bundle && !opts.consolify) {
69+
console.log('--bundle must be used with --consolify option\n');
70+
process.exit(1);
71+
}
72+
6873
if (opts.invert && !opts.grep) {
6974
console.log('--invert must be used with --grep option\n');
7075
process.exit(1);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"which": "^1.2.1"
7272
},
7373
"devDependencies": {
74-
"eslint": "^1.10.3"
74+
"eslint": "^1.10.3",
75+
"tmp": "0.0.28"
7576
},
7677
"files": [
7778
"bin",

test/api-test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
'use strict';
1010

1111
var assert = require('assert');
12+
var fs = require('fs');
1213
var through = require('through2');
1314
var api = require('./fixture/api');
15+
var sandbox = require('./fixture/sandbox');
1416
var mochify = require('../lib/mochify');
1517

1618

@@ -118,4 +120,43 @@ describe('api', function () {
118120
+ '# fail 0\n', done));
119121
});
120122

123+
it('should write a test-runner html document when --consolify is used',
124+
sandbox(function (done, tmpdir) {
125+
mochify('./test/fixture/passes/test/*.js', {
126+
consolify: tmpdir + '/output.html'
127+
}).bundle(function (err) {
128+
if (err) {
129+
return done(err);
130+
}
131+
try {
132+
fs.statSync(tmpdir + '/output.html');
133+
done();
134+
} catch (e) {
135+
done(e);
136+
}
137+
});
138+
})
139+
);
140+
141+
it('should extract the script to an external bundle when --bundle is used'
142+
+ ' with --consolify',
143+
sandbox(function (done, tmpdir) {
144+
mochify('./test/fixture/passes/test/*.js', {
145+
consolify: tmpdir + '/output.html',
146+
bundle: tmpdir + '/bundle.js'
147+
}).bundle(function (err) {
148+
if (err) {
149+
return done(err);
150+
}
151+
try {
152+
fs.statSync(tmpdir + '/output.html');
153+
fs.statSync(tmpdir + '/bundle.js');
154+
done();
155+
} catch (e) {
156+
done(e);
157+
}
158+
});
159+
})
160+
);
161+
121162
});

test/args-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,12 @@ describe('args', function () {
291291
});
292292
});
293293

294+
it('fails with bundle but no consolify option', function (done) {
295+
run('passes', ['--bundle', 'foo.js'], function (code, stdout) {
296+
assert.equal(code, 1);
297+
assert.equal(stdout, '--bundle must be used with --consolify option\n\n');
298+
done();
299+
});
300+
});
301+
294302
});

test/fixture/sandbox.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* mochify.js
3+
*
4+
* Copyright (c) 2014 Maximilian Antoni <[email protected]>
5+
*
6+
* @license MIT
7+
*/
8+
'use strict';
9+
10+
var tmp = require('tmp');
11+
12+
// sandbox creates a temporary directory which will be automatically
13+
// removed after the testcase completes.
14+
function sandbox(testfn) {
15+
return function (done) {
16+
var tmpOpts = {
17+
unsafeCleanup: true
18+
};
19+
tmp.dir(tmpOpts, function (err, tmpdir) {
20+
if (err) {
21+
return done(err);
22+
}
23+
testfn(done, tmpdir);
24+
});
25+
};
26+
}
27+
28+
module.exports = sandbox;

0 commit comments

Comments
 (0)