Skip to content

Commit a856d6e

Browse files
committed
feat!: change the default of --forbid-only to check for process.env.CI.
Fixes #5299
1 parent 65a91b5 commit a856d6e

File tree

8 files changed

+18
-14
lines changed

8 files changed

+18
-14
lines changed

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,12 @@ Enforce a rule that tests may not be exclusive (use of e.g., `describe.only()` o
947947

948948
`--forbid-only` causes Mocha to fail when an exclusive ("only'd") test or suite is encountered, and it will abort further test execution.
949949

950+
Defaults:
951+
952+
1. Before v12: false
953+
2. After v12: false, unless an environment variable called `CI` is set. Many popular
954+
CI providers, like github actions or gitlab, do this automatically.
955+
950956
### `--forbid-pending`
951957

952958
Enforce a rule that tests may not be skipped (use of e.g., `describe.skip()`, `it.skip()`, or `this.skip()` anywhere is disallowed).

lib/cli/run.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ exports.builder = yargs =>
123123
},
124124
'forbid-only': {
125125
description: 'Fail if exclusive test(s) encountered',
126-
group: GROUPS.RULES
126+
group: GROUPS.RULES,
127+
default: !!process.env.CI,
127128
},
128129
'forbid-pending': {
129130
description: 'Fail if pending test(s) encountered',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"test-browser": "run-s clean build test-browser:*",
7272
"test-coverage-clean": "rimraf .nyc_output coverage",
7373
"test-coverage-generate": "nyc report --reporter=lcov --reporter=text",
74-
"test-node-run-only": "nyc --no-clean --reporter=json node bin/mocha.js",
74+
"test-node-run-only": "nyc --no-clean --reporter=json node bin/mocha.js --no-forbid-only",
7575
"test-node-run": "nyc --no-clean --reporter=json node bin/mocha.js --forbid-only",
7676
"test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/**/*.spec.js\"",
7777
"test-node:integration:watch": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/options/watch.spec.js\"",

test/integration/common-js-require.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const {runMochaAsync} = require('./helpers');
55
describe('common js require', () => {
66
it('should be able to run a test where all mocha exports are used', async () => {
77
const result = await runMochaAsync('common-js-require.fixture.js', [
8-
'--delay'
8+
'--delay',
9+
'--no-forbid-only'
910
]);
1011
expect(result.output, 'to contain', 'running before');
1112
expect(result.output, 'to contain', 'running suiteSetup');

test/integration/only.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var assert = require('node:assert');
66
describe('.only()', function () {
77
describe('bdd', function () {
88
it('should run only tests that marked as `only`', function (done) {
9-
run('options/only/bdd.fixture.js', ['--ui', 'bdd'], function (err, res) {
9+
run('options/only/bdd.fixture.js', ['--ui', 'bdd', '--no-forbid-only'], function (err, res) {
1010
if (err) {
1111
done(err);
1212
return;
@@ -22,7 +22,7 @@ describe('.only()', function () {
2222

2323
describe('tdd', function () {
2424
it('should run only tests that marked as `only`', function (done) {
25-
run('options/only/tdd.fixture.js', ['--ui', 'tdd'], function (err, res) {
25+
run('options/only/tdd.fixture.js', ['--ui', 'tdd', '--no-forbid-only'], function (err, res) {
2626
if (err) {
2727
done(err);
2828
return;
@@ -40,7 +40,7 @@ describe('.only()', function () {
4040
it('should run only tests that marked as `only`', function (done) {
4141
run(
4242
'options/only/qunit.fixture.js',
43-
['--ui', 'qunit'],
43+
['--ui', 'qunit', '--no-forbid-only'],
4444
function (err, res) {
4545
if (err) {
4646
done(err);

test/integration/options/delay.spec.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ var helpers = require('../helpers');
55
var runMochaJSON = helpers.runMochaJSON;
66

77
describe('--delay', function () {
8-
var args = [];
9-
10-
before(function () {
11-
args = ['--delay'];
12-
});
8+
var args = ['--delay', '--no-forbid-only'];
139

1410
it('should run the generated test suite', function (done) {
1511
var fixture = path.join('options', 'delay');

test/integration/options/dryRun.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var helpers = require('../helpers');
55
var runMochaJSON = helpers.runMochaJSON;
66

77
describe('--dry-run', function () {
8-
var args = ['--dry-run'];
8+
var args = ['--dry-run', '--no-forbid-only'];
99

1010
it('should only report, but not execute any test', function (done) {
1111
var fixture = path.join('options/dry-run', 'dry-run');

test/integration/regression.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('regressions', function () {
5151
});
5252

5353
it('issue-2406: should run nested describe.only suites', function (done) {
54-
runJSON('regression/issue-2406.fixture.js', [], function (err, res) {
54+
runJSON('regression/issue-2406.fixture.js', ['--no-forbid-only'], function (err, res) {
5555
if (err) {
5656
done(err);
5757
return;
@@ -64,7 +64,7 @@ describe('regressions', function () {
6464
});
6565

6666
it('issue-2417: should not recurse infinitely with .only suites nested within each other', function (done) {
67-
runJSON('regression/issue-2417.fixture.js', [], function (err, res) {
67+
runJSON('regression/issue-2417.fixture.js', ['--no-forbid-only'], function (err, res) {
6868
if (err) {
6969
done(err);
7070
return;

0 commit comments

Comments
 (0)