From 03ea260589b2dcb0b78625c9846d063467896c5b Mon Sep 17 00:00:00 2001 From: Charles Rudolph Date: Mon, 30 Jan 2017 22:09:07 -0800 Subject: [PATCH 01/13] add --production option --- bin/_mocha | 7 ++++- lib/mocha.js | 10 +++++++ lib/runner.js | 10 ++++++- .../fixtures/options/production/only.js | 5 ++++ .../fixtures/options/production/pending.js | 5 ++++ .../fixtures/options/production/skipped.js | 5 ++++ test/integration/options.spec.js | 30 +++++++++++++++++++ 7 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 test/integration/fixtures/options/production/only.js create mode 100644 test/integration/fixtures/options/production/pending.js create mode 100644 test/integration/fixtures/options/production/skipped.js diff --git a/bin/_mocha b/bin/_mocha index 61aac40d3a..6c5e82d53f 100755 --- a/bin/_mocha +++ b/bin/_mocha @@ -107,7 +107,8 @@ program .option('--trace-deprecation', 'show stack traces on deprecations') .option('--use_strict', 'enforce strict mode') .option('--watch-extensions ,...', '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'; @@ -323,6 +324,10 @@ if (program.retries) { mocha.suite.retries(program.retries); } +// --production + +if (program.production) mocha.productionMode(); + // custom compiler support var extensions = ['js']; diff --git a/lib/mocha.js b/lib/mocha.js index 8bacf27b17..cd5e1dfb6a 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -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. * @@ -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); } diff --git a/lib/runner.js b/lib/runner.js index 1d3dd959da..e810cc9928 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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 diff --git a/test/integration/fixtures/options/production/only.js b/test/integration/fixtures/options/production/only.js new file mode 100644 index 0000000000..9ac9ca516c --- /dev/null +++ b/test/integration/fixtures/options/production/only.js @@ -0,0 +1,5 @@ +describe('production mode - only', function() { + it('test1', function() {}); + it.only('stest2', function() {}); + it('test3', function() {}); +}); diff --git a/test/integration/fixtures/options/production/pending.js b/test/integration/fixtures/options/production/pending.js new file mode 100644 index 0000000000..5d5d6105d4 --- /dev/null +++ b/test/integration/fixtures/options/production/pending.js @@ -0,0 +1,5 @@ +describe('production mode - pending', function() { + it('test1', function() {}); + it('test2'); + it('test3', function() {}); +}); diff --git a/test/integration/fixtures/options/production/skipped.js b/test/integration/fixtures/options/production/skipped.js new file mode 100644 index 0000000000..8b7dc3d757 --- /dev/null +++ b/test/integration/fixtures/options/production/skipped.js @@ -0,0 +1,5 @@ +describe('production mode - skipped', function() { + it('test1', function() {}); + it.skip('test2', function() {}); + it('test3', function() {}); +}); diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index 7c7a3cc75e..cf47c5c83f 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -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(); + }); + }); + }); }); From ac790188c88073e993247ed637340a94f8655c01 Mon Sep 17 00:00:00 2001 From: Charles Rudolph Date: Mon, 30 Jan 2017 22:14:05 -0800 Subject: [PATCH 02/13] update comment --- lib/mocha.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mocha.js b/lib/mocha.js index cd5e1dfb6a..c59b6d659a 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -484,7 +484,7 @@ Mocha.prototype.delay = function delay () { }; /** - * Fail skipped, pending, duplicate title and tests marked only + * Pending tests and test marked only or skip fail the suite * @returns {Mocha} */ Mocha.prototype.productionMode = function() { From 4945fb0e3fccf440697c5e52fb3760e11f83df7e Mon Sep 17 00:00:00 2001 From: Charles Rudolph Date: Mon, 30 Jan 2017 22:31:39 -0800 Subject: [PATCH 03/13] fix lint --- lib/mocha.js | 8 +++---- lib/runner.js | 4 ++-- .../fixtures/options/production/only.js | 8 +++---- .../fixtures/options/production/pending.js | 6 ++--- .../fixtures/options/production/skipped.js | 8 +++---- test/integration/options.spec.js | 22 +++++++++---------- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/mocha.js b/lib/mocha.js index c59b6d659a..c37f3c5dc8 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -487,10 +487,10 @@ Mocha.prototype.delay = function delay () { * Pending tests and test marked only or skip fail the suite * @returns {Mocha} */ - Mocha.prototype.productionMode = function() { - this.options.productionMode = true; - return this; - }; +Mocha.prototype.productionMode = function () { + this.options.productionMode = true; + return this; +}; /** * Run tests and invoke `fn()` when complete. diff --git a/lib/runner.js b/lib/runner.js index e810cc9928..47c2e2b2e3 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -824,9 +824,9 @@ Runner.prototype.run = function (fn) { var failures = self.failures; if (self.productionMode) { if (self.hasOnly) { - failures += self.stats.tests + failures += self.stats.tests; } else { - failures += self.stats.pending + failures += self.stats.pending; } } debug('end'); diff --git a/test/integration/fixtures/options/production/only.js b/test/integration/fixtures/options/production/only.js index 9ac9ca516c..23ba6bb70b 100644 --- a/test/integration/fixtures/options/production/only.js +++ b/test/integration/fixtures/options/production/only.js @@ -1,5 +1,5 @@ -describe('production mode - only', function() { - it('test1', function() {}); - it.only('stest2', function() {}); - it('test3', function() {}); +describe('production mode - only', function () { + it('test1', function () {}); + it.only('stest2', function () {}); + it('test3', function () {}); }); diff --git a/test/integration/fixtures/options/production/pending.js b/test/integration/fixtures/options/production/pending.js index 5d5d6105d4..41989cfc8f 100644 --- a/test/integration/fixtures/options/production/pending.js +++ b/test/integration/fixtures/options/production/pending.js @@ -1,5 +1,5 @@ -describe('production mode - pending', function() { - it('test1', function() {}); +describe('production mode - pending', function () { + it('test1', function () {}); it('test2'); - it('test3', function() {}); + it('test3', function () {}); }); diff --git a/test/integration/fixtures/options/production/skipped.js b/test/integration/fixtures/options/production/skipped.js index 8b7dc3d757..aafc510eaf 100644 --- a/test/integration/fixtures/options/production/skipped.js +++ b/test/integration/fixtures/options/production/skipped.js @@ -1,5 +1,5 @@ -describe('production mode - skipped', function() { - it('test1', function() {}); - it.skip('test2', function() {}); - it('test3', function() {}); +describe('production mode - skipped', function () { + it('test1', function () {}); + it.skip('test2', function () {}); + it('test3', function () {}); }); diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index cf47c5c83f..275842cdc7 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -181,31 +181,31 @@ describe('options', function () { }); }); - describe('--production', function() { - before(function() { + describe('--production', function () { + before(function () { args = ['--production']; }); - it('fails skipped tests', function(done) { - run('options/production/skipped.js', args, function(err, res) { + it('fails skipped tests', function (done) { + run('options/production/skipped.js', args, function (err, res) { assert(!err); - assert.equal(res.code, 1) + assert.equal(res.code, 1); done(); }); }); - it('fails pending tests', function(done) { - run('options/production/pending.js', args, function(err, res) { + it('fails pending tests', function (done) { + run('options/production/pending.js', args, function (err, res) { assert(!err); - assert.equal(res.code, 1) + assert.equal(res.code, 1); done(); }); }); - it('fails tests marked only', function(done) { - run('options/production/only.js', args, function(err, res) { + it('fails tests marked only', function (done) { + run('options/production/only.js', args, function (err, res) { assert(!err); - assert.equal(res.code, 1) + assert.equal(res.code, 1); done(); }); }); From 7d6962dbdb77278adb27d8da687edc2de54f5117 Mon Sep 17 00:00:00 2001 From: Charles Rudolph Date: Tue, 31 Jan 2017 08:10:01 -0800 Subject: [PATCH 04/13] add tests --- .../fixtures/options/production/failed.js | 5 ++++ .../fixtures/options/production/only.js | 2 +- .../fixtures/options/production/passed.js | 5 ++++ test/integration/options.spec.js | 24 +++++++++++++++---- 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 test/integration/fixtures/options/production/failed.js create mode 100644 test/integration/fixtures/options/production/passed.js diff --git a/test/integration/fixtures/options/production/failed.js b/test/integration/fixtures/options/production/failed.js new file mode 100644 index 0000000000..d354d1e562 --- /dev/null +++ b/test/integration/fixtures/options/production/failed.js @@ -0,0 +1,5 @@ +describe('production mode - failed', function () { + it('test1', function () {}); + it('test2', function () { throw new Error('fail'); }); + it('test3', function () {}); +}); diff --git a/test/integration/fixtures/options/production/only.js b/test/integration/fixtures/options/production/only.js index 23ba6bb70b..cece90bb33 100644 --- a/test/integration/fixtures/options/production/only.js +++ b/test/integration/fixtures/options/production/only.js @@ -1,5 +1,5 @@ describe('production mode - only', function () { it('test1', function () {}); - it.only('stest2', function () {}); + it.only('test2', function () {}); it('test3', function () {}); }); diff --git a/test/integration/fixtures/options/production/passed.js b/test/integration/fixtures/options/production/passed.js new file mode 100644 index 0000000000..3024da6610 --- /dev/null +++ b/test/integration/fixtures/options/production/passed.js @@ -0,0 +1,5 @@ +describe('production mode - passed', function () { + it('test1', function () {}); + it('test2', function () {}); + it('test3', function () {}); +}); diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index 275842cdc7..9473e94913 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -181,12 +181,28 @@ describe('options', function () { }); }); - describe('--production', function () { + describe.only('--production', function () { before(function () { args = ['--production']; }); - it('fails skipped tests', function (done) { + it('succeeds if there are only passed tests', function (done) { + run('options/production/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) { + assert(!err); + assert.equal(res.code, 1); + done(); + }); + }); + + it('fails if there are skipped tests', function (done) { run('options/production/skipped.js', args, function (err, res) { assert(!err); assert.equal(res.code, 1); @@ -194,7 +210,7 @@ describe('options', function () { }); }); - it('fails pending tests', function (done) { + it('fails if there are pending tests', function (done) { run('options/production/pending.js', args, function (err, res) { assert(!err); assert.equal(res.code, 1); @@ -202,7 +218,7 @@ describe('options', function () { }); }); - it('fails tests marked only', function (done) { + it('fails if there are tests marked only', function (done) { run('options/production/only.js', args, function (err, res) { assert(!err); assert.equal(res.code, 1); From 073b0d975a319f1269186377910bde24e844e432 Mon Sep 17 00:00:00 2001 From: Charles Rudolph Date: Tue, 31 Jan 2017 08:35:44 -0800 Subject: [PATCH 05/13] remove only --- test/integration/options.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index 9473e94913..ae43815135 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -181,7 +181,7 @@ describe('options', function () { }); }); - describe.only('--production', function () { + describe('--production', function () { before(function () { args = ['--production']; }); From c2a84e6cbe7a7c321675054550b68a0d6e98755d Mon Sep 17 00:00:00 2001 From: charlierudolph Date: Wed, 1 Feb 2017 09:15:22 -0800 Subject: [PATCH 06/13] update --- bin/_mocha | 11 +++++-- lib/mocha.js | 18 ++++++++--- lib/runner.js | 7 +++-- .../{production => forbid-only}/only.js | 2 +- .../{production => forbid-only}/passed.js | 2 +- .../fixtures/options/forbid-pending/passed.js | 5 ++++ .../{production => forbid-pending}/pending.js | 2 +- .../skipped.js => forbid-pending/skip.js} | 2 +- .../fixtures/options/production/failed.js | 5 ---- test/integration/options.spec.js | 30 +++++++++++-------- 10 files changed, 53 insertions(+), 31 deletions(-) rename test/integration/fixtures/options/{production => forbid-only}/only.js (62%) rename test/integration/fixtures/options/{production => forbid-only}/passed.js (64%) create mode 100644 test/integration/fixtures/options/forbid-pending/passed.js rename test/integration/fixtures/options/{production => forbid-pending}/pending.js (55%) rename test/integration/fixtures/options/{production/skipped.js => forbid-pending/skip.js} (61%) delete mode 100644 test/integration/fixtures/options/production/failed.js diff --git a/bin/_mocha b/bin/_mocha index 6c5e82d53f..2568aada83 100755 --- a/bin/_mocha +++ b/bin/_mocha @@ -108,7 +108,8 @@ program .option('--use_strict', 'enforce strict mode') .option('--watch-extensions ,...', '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'; @@ -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 diff --git a/lib/mocha.js b/lib/mocha.js index c37f3c5dc8..bfc0238d46 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -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; }; @@ -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); } diff --git a/lib/runner.js b/lib/runner.js index 47c2e2b2e3..366b41081a 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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); diff --git a/test/integration/fixtures/options/production/only.js b/test/integration/fixtures/options/forbid-only/only.js similarity index 62% rename from test/integration/fixtures/options/production/only.js rename to test/integration/fixtures/options/forbid-only/only.js index cece90bb33..59892a4c8f 100644 --- a/test/integration/fixtures/options/production/only.js +++ b/test/integration/fixtures/options/forbid-only/only.js @@ -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 () {}); diff --git a/test/integration/fixtures/options/production/passed.js b/test/integration/fixtures/options/forbid-only/passed.js similarity index 64% rename from test/integration/fixtures/options/production/passed.js rename to test/integration/fixtures/options/forbid-only/passed.js index 3024da6610..454f4bc845 100644 --- a/test/integration/fixtures/options/production/passed.js +++ b/test/integration/fixtures/options/forbid-only/passed.js @@ -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 () {}); diff --git a/test/integration/fixtures/options/forbid-pending/passed.js b/test/integration/fixtures/options/forbid-pending/passed.js new file mode 100644 index 0000000000..ecbbb0339f --- /dev/null +++ b/test/integration/fixtures/options/forbid-pending/passed.js @@ -0,0 +1,5 @@ +describe('forbid pending - all test pass', function () { + it('test1', function () {}); + it('test2', function () {}); + it('test3', function () {}); +}); diff --git a/test/integration/fixtures/options/production/pending.js b/test/integration/fixtures/options/forbid-pending/pending.js similarity index 55% rename from test/integration/fixtures/options/production/pending.js rename to test/integration/fixtures/options/forbid-pending/pending.js index 41989cfc8f..6762e6f5cc 100644 --- a/test/integration/fixtures/options/production/pending.js +++ b/test/integration/fixtures/options/forbid-pending/pending.js @@ -1,4 +1,4 @@ -describe('production mode - pending', function () { +describe('forbid pending - test without function', function () { it('test1', function () {}); it('test2'); it('test3', function () {}); diff --git a/test/integration/fixtures/options/production/skipped.js b/test/integration/fixtures/options/forbid-pending/skip.js similarity index 61% rename from test/integration/fixtures/options/production/skipped.js rename to test/integration/fixtures/options/forbid-pending/skip.js index aafc510eaf..d428239222 100644 --- a/test/integration/fixtures/options/production/skipped.js +++ b/test/integration/fixtures/options/forbid-pending/skip.js @@ -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 () {}); diff --git a/test/integration/fixtures/options/production/failed.js b/test/integration/fixtures/options/production/failed.js deleted file mode 100644 index d354d1e562..0000000000 --- a/test/integration/fixtures/options/production/failed.js +++ /dev/null @@ -1,5 +0,0 @@ -describe('production mode - failed', function () { - it('test1', function () {}); - it('test2', function () { throw new Error('fail'); }); - it('test3', function () {}); -}); diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index ae43815135..4499972f96 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -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(); From 6780cac59bd008e3945de47aa4059c76eb2ba2f1 Mon Sep 17 00:00:00 2001 From: charlierudolph Date: Wed, 1 Feb 2017 09:16:17 -0800 Subject: [PATCH 07/13] simplify --- lib/runner.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index 366b41081a..a6c72d1519 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -822,10 +822,8 @@ Runner.prototype.run = function (fn) { // callback this.on('end', function () { var failures = self.failures; - if (self.forbidOnly) { - if (self.hasOnly) { - failures += self.stats.tests; - } + if (self.forbidOnly and self.hasOnly) { + failures += self.stats.tests; } if (self.forbidPending) { failures += self.stats.pending; From 6d0ce830752972a6599c343a6a42218f3bd195bd Mon Sep 17 00:00:00 2001 From: charlierudolph Date: Wed, 1 Feb 2017 09:21:34 -0800 Subject: [PATCH 08/13] remove onlys --- test/integration/options.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index 4499972f96..325fbada8f 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -181,7 +181,7 @@ describe('options', function () { }); }); - describe.only('--forbid-only', function () { + describe('--forbid-only', function () { before(function () { args = ['--forbid-only']; }); @@ -203,7 +203,7 @@ describe('options', function () { }); }); - describe.only('--forbid-pending', function () { + describe('--forbid-pending', function () { before(function () { args = ['--forbid-pending']; }); From e9e56ebf858fc6e5b5eb8e7632bf542cc30fbccc Mon Sep 17 00:00:00 2001 From: charlierudolph Date: Wed, 1 Feb 2017 09:23:06 -0800 Subject: [PATCH 09/13] fix and --- lib/runner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runner.js b/lib/runner.js index a6c72d1519..77208c7a0e 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -822,7 +822,7 @@ Runner.prototype.run = function (fn) { // callback this.on('end', function () { var failures = self.failures; - if (self.forbidOnly and self.hasOnly) { + if (self.forbidOnly && self.hasOnly) { failures += self.stats.tests; } if (self.forbidPending) { From f7852dae01318b5dd3421752586722ba9f271016 Mon Sep 17 00:00:00 2001 From: Charles Rudolph Date: Wed, 17 May 2017 09:05:00 -0700 Subject: [PATCH 10/13] update self.failures --- lib/runner.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index 04406490fc..039065a2e0 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -820,16 +820,15 @@ Runner.prototype.run = function (fn) { // callback this.on('end', function () { - var failures = self.failures; if (self.forbidOnly && self.hasOnly) { - failures += self.stats.tests; + self.failures += self.stats.tests; } if (self.forbidPending) { - failures += self.stats.pending; + self.failures += self.stats.pending; } debug('end'); process.removeListener('uncaughtException', uncaught); - fn(failures); + fn(self.failures); }); // uncaught exception From 164934ae56e4b389edc76ec664f0f6b1d0cb4280 Mon Sep 17 00:00:00 2001 From: Charles Rudolph Date: Wed, 17 May 2017 09:05:55 -0700 Subject: [PATCH 11/13] update test description --- test/integration/fixtures/options/forbid-only/passed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/fixtures/options/forbid-only/passed.js b/test/integration/fixtures/options/forbid-only/passed.js index 454f4bc845..e50e2aa865 100644 --- a/test/integration/fixtures/options/forbid-only/passed.js +++ b/test/integration/fixtures/options/forbid-only/passed.js @@ -1,4 +1,4 @@ -describe('forbid only - all test pass', function () { +describe('forbid only - `.only` is not used', function () { it('test1', function () {}); it('test2', function () {}); it('test3', function () {}); From 6ad192be864949101163c508d8dbcf2c918c3f30 Mon Sep 17 00:00:00 2001 From: David da Silva Date: Wed, 17 May 2017 18:34:08 +0200 Subject: [PATCH 12/13] Remove breaking semicolon --- bin/_mocha | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/_mocha b/bin/_mocha index d946dc8357..8bf13bf6a1 100755 --- a/bin/_mocha +++ b/bin/_mocha @@ -111,7 +111,7 @@ program .option('--use_strict', 'enforce strict mode') .option('--watch-extensions ,...', 'additional extensions to monitor with --watch', list, []) .option('--delay', 'wait for async suite definition') - .option('--allow-uncaught', 'enable uncaught errors to propagate'); + .option('--allow-uncaught', 'enable uncaught errors to propagate') .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'); From 43ce4d7060751a895b7075f291b6ecbccdbba09c Mon Sep 17 00:00:00 2001 From: Charles Rudolph Date: Wed, 17 May 2017 14:30:47 -0700 Subject: [PATCH 13/13] fix lint --- test/integration/fixtures/options/forbid-only/only.js | 2 ++ test/integration/fixtures/options/forbid-only/passed.js | 2 ++ test/integration/fixtures/options/forbid-pending/passed.js | 2 ++ test/integration/fixtures/options/forbid-pending/pending.js | 2 ++ test/integration/fixtures/options/forbid-pending/skip.js | 2 ++ 5 files changed, 10 insertions(+) diff --git a/test/integration/fixtures/options/forbid-only/only.js b/test/integration/fixtures/options/forbid-only/only.js index 59892a4c8f..c09e804126 100644 --- a/test/integration/fixtures/options/forbid-only/only.js +++ b/test/integration/fixtures/options/forbid-only/only.js @@ -1,3 +1,5 @@ +'use strict'; + describe('forbid only - test marked with only', function () { it('test1', function () {}); it.only('test2', function () {}); diff --git a/test/integration/fixtures/options/forbid-only/passed.js b/test/integration/fixtures/options/forbid-only/passed.js index e50e2aa865..6c4d4ac1d4 100644 --- a/test/integration/fixtures/options/forbid-only/passed.js +++ b/test/integration/fixtures/options/forbid-only/passed.js @@ -1,3 +1,5 @@ +'use strict'; + describe('forbid only - `.only` is not used', function () { it('test1', function () {}); it('test2', function () {}); diff --git a/test/integration/fixtures/options/forbid-pending/passed.js b/test/integration/fixtures/options/forbid-pending/passed.js index ecbbb0339f..cd12668f4d 100644 --- a/test/integration/fixtures/options/forbid-pending/passed.js +++ b/test/integration/fixtures/options/forbid-pending/passed.js @@ -1,3 +1,5 @@ +'use strict'; + describe('forbid pending - all test pass', function () { it('test1', function () {}); it('test2', function () {}); diff --git a/test/integration/fixtures/options/forbid-pending/pending.js b/test/integration/fixtures/options/forbid-pending/pending.js index 6762e6f5cc..96abd0bf47 100644 --- a/test/integration/fixtures/options/forbid-pending/pending.js +++ b/test/integration/fixtures/options/forbid-pending/pending.js @@ -1,3 +1,5 @@ +'use strict'; + describe('forbid pending - test without function', function () { it('test1', function () {}); it('test2'); diff --git a/test/integration/fixtures/options/forbid-pending/skip.js b/test/integration/fixtures/options/forbid-pending/skip.js index d428239222..c6fd31d303 100644 --- a/test/integration/fixtures/options/forbid-pending/skip.js +++ b/test/integration/fixtures/options/forbid-pending/skip.js @@ -1,3 +1,5 @@ +'use strict'; + describe('forbid pending - test marked with skip', function () { it('test1', function () {}); it.skip('test2', function () {});