Skip to content

Commit

Permalink
add --production option
Browse files Browse the repository at this point in the history
  • Loading branch information
charlierudolph committed Jan 31, 2017
1 parent 503627c commit 03ea260
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ program
.option('--trace-deprecation', 'show stack traces on deprecations')
.option('--use_strict', 'enforce strict mode')
.option('--watch-extensions <ext>,...', 'additional extensions to monitor with --watch', list, [])
.option('--delay', 'wait for async suite definition');
.option('--delay', 'wait for async suite definition')
.option('--production', 'causes only, pending, and skipped tests to fail the suite');

program._name = 'mocha';

Expand Down Expand Up @@ -323,6 +324,10 @@ if (program.retries) {
mocha.suite.retries(program.retries);
}

// --production

if (program.production) mocha.productionMode();

// custom compiler support

var extensions = ['js'];
Expand Down
10 changes: 10 additions & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ Mocha.prototype.delay = function delay () {
return this;
};

/**
* Fail skipped, pending, duplicate title and tests marked only
* @returns {Mocha}
*/
Mocha.prototype.productionMode = function() {
this.options.productionMode = true;
return this;
};

/**
* Run tests and invoke `fn()` when complete.
*
Expand All @@ -504,6 +513,7 @@ Mocha.prototype.run = function (fn) {
runner.hasOnly = options.hasOnly;
runner.asyncOnly = options.asyncOnly;
runner.allowUncaught = options.allowUncaught;
runner.productionMode = options.productionMode;
if (options.grep) {
runner.grep(options.grep, options.invert);
}
Expand Down
10 changes: 9 additions & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,17 @@ Runner.prototype.run = function (fn) {

// callback
this.on('end', function () {
var failures = self.failures;
if (self.productionMode) {
if (self.hasOnly) {
failures += self.stats.tests
} else {
failures += self.stats.pending
}
}
debug('end');
process.removeListener('uncaughtException', uncaught);
fn(self.failures);
fn(failures);
});

// uncaught exception
Expand Down
5 changes: 5 additions & 0 deletions test/integration/fixtures/options/production/only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('production mode - only', function() {
it('test1', function() {});
it.only('stest2', function() {});
it('test3', function() {});
});
5 changes: 5 additions & 0 deletions test/integration/fixtures/options/production/pending.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('production mode - pending', function() {
it('test1', function() {});
it('test2');
it('test3', function() {});
});
5 changes: 5 additions & 0 deletions test/integration/fixtures/options/production/skipped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('production mode - skipped', function() {
it('test1', function() {});
it.skip('test2', function() {});
it('test3', function() {});
});
30 changes: 30 additions & 0 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,34 @@ describe('options', function () {
});
});
});

describe('--production', function() {
before(function() {
args = ['--production'];
});

it('fails skipped tests', function(done) {
run('options/production/skipped.js', args, function(err, res) {
assert(!err);
assert.equal(res.code, 1)
done();
});
});

it('fails pending tests', function(done) {
run('options/production/pending.js', args, function(err, res) {
assert(!err);
assert.equal(res.code, 1)
done();
});
});

it('fails tests marked only', function(done) {
run('options/production/only.js', args, function(err, res) {
assert(!err);
assert.equal(res.code, 1)
done();
});
});
});
});

0 comments on commit 03ea260

Please sign in to comment.