Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
charlierudolph committed Feb 1, 2017
1 parent 073b0d9 commit c2a84e6
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 31 deletions.
11 changes: 8 additions & 3 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ program
.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('--production', 'causes only, pending, and skipped tests to fail the suite');
.option('--forbid-only', 'causes test marked with only to fail the suite')
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite');

program._name = 'mocha';

Expand Down Expand Up @@ -324,9 +325,13 @@ if (program.retries) {
mocha.suite.retries(program.retries);
}

// --production
// --forbid-only

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

// --forbid-pending

if (program.forbidPending) mocha.forbidPending();

// custom compiler support

Expand Down
18 changes: 14 additions & 4 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,20 @@ Mocha.prototype.delay = function delay () {
};

/**
* Pending tests and test marked only or skip fail the suite
* Tests marked only fail the suite
* @returns {Mocha}
*/
Mocha.prototype.productionMode = function () {
this.options.productionMode = true;
Mocha.prototype.forbidOnly = function () {
this.options.forbidOnly = true;
return this;
};

/**
* Pending tests and tests marked skip fail the suite
* @returns {Mocha}
*/
Mocha.prototype.forbidPending = function () {
this.options.forbidPending = true;
return this;
};

Expand All @@ -513,7 +522,8 @@ Mocha.prototype.run = function (fn) {
runner.hasOnly = options.hasOnly;
runner.asyncOnly = options.asyncOnly;
runner.allowUncaught = options.allowUncaught;
runner.productionMode = options.productionMode;
runner.forbidOnly = options.forbidOnly;
runner.forbidPending = options.forbidPending;
if (options.grep) {
runner.grep(options.grep, options.invert);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,14 @@ Runner.prototype.run = function (fn) {
// callback
this.on('end', function () {
var failures = self.failures;
if (self.productionMode) {
if (self.forbidOnly) {
if (self.hasOnly) {
failures += self.stats.tests;
} else {
failures += self.stats.pending;
}
}
if (self.forbidPending) {
failures += self.stats.pending;
}
debug('end');
process.removeListener('uncaughtException', uncaught);
fn(failures);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('production mode - only', function () {
describe('forbid only - test marked with only', function () {
it('test1', function () {});
it.only('test2', function () {});
it('test3', function () {});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('production mode - passed', function () {
describe('forbid only - all test pass', function () {
it('test1', function () {});
it('test2', function () {});
it('test3', function () {});
Expand Down
5 changes: 5 additions & 0 deletions test/integration/fixtures/options/forbid-pending/passed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('forbid pending - all test pass', function () {
it('test1', function () {});
it('test2', function () {});
it('test3', function () {});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('production mode - pending', function () {
describe('forbid pending - test without function', function () {
it('test1', function () {});
it('test2');
it('test3', function () {});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('production mode - skipped', function () {
describe('forbid pending - test marked with skip', function () {
it('test1', function () {});
it.skip('test2', function () {});
it('test3', function () {});
Expand Down
5 changes: 0 additions & 5 deletions test/integration/fixtures/options/production/failed.js

This file was deleted.

30 changes: 18 additions & 12 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,45 +181,51 @@ describe('options', function () {
});
});

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

it('succeeds if there are only passed tests', function (done) {
run('options/production/passed.js', args, function (err, res) {
run('options/forbid-only/passed.js', args, function (err, res) {
assert(!err);
assert.equal(res.code, 0);
done();
});
});

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

describe.only('--forbid-pending', function () {
before(function () {
args = ['--forbid-pending'];
});

it('fails if there are skipped tests', function (done) {
run('options/production/skipped.js', args, function (err, res) {
it('succeeds if there are only passed tests', function (done) {
run('options/forbid-pending/passed.js', args, function (err, res) {
assert(!err);
assert.equal(res.code, 1);
assert.equal(res.code, 0);
done();
});
});

it('fails if there are pending tests', function (done) {
run('options/production/pending.js', args, function (err, res) {
it('fails if there are tests marked skip', function (done) {
run('options/forbid-pending/skip.js', args, function (err, res) {
assert(!err);
assert.equal(res.code, 1);
done();
});
});

it('fails if there are tests marked only', function (done) {
run('options/production/only.js', args, function (err, res) {
it('fails if there are pending tests', function (done) {
run('options/forbid-pending/pending.js', args, function (err, res) {
assert(!err);
assert.equal(res.code, 1);
done();
Expand Down

0 comments on commit c2a84e6

Please sign in to comment.