Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make forbid-only as default on CI #3987

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/cli/run.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Docs] https://mochajs.org/#-forbid-only should be updated to mention this, too. Folks will want to know if the default value isn't always falsy.

Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ exports.builder = yargs =>
requiresArg: true
},
'forbid-only': {
default: process.env.CI,
description: 'Fail if exclusive test(s) encountered',
group: GROUPS.RULES
},
Expand Down
4 changes: 2 additions & 2 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function test(testName, mochaParams) {
if (process.env.CI) {
// suppress coverage summaries in CI to reduce noise
coverageCommand += ' --reporter=json';
if (!/^only-/.test(testName)) {
mochaParams += ' --forbid-only';
if (/^only-/.test(testName)) {
mochaParams += ' --no-forbid-only';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question] 🤔 Is --no-forbid-only necessary? My interpretation of #3030 (comment) was that the issue can be resolved with just the change to forbid-only's default value.

}
}
// this may _actually_ be supported in the future
Expand Down
75 changes: 42 additions & 33 deletions test/integration/only.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,61 @@ var assert = require('assert');
describe('.only()', function() {
describe('bdd', function() {
it('should run only tests that marked as `only`', function(done) {
run('options/only/bdd.fixture.js', ['--ui', 'bdd'], function(err, res) {
if (err) {
done(err);
return;
run(
'options/only/bdd.fixture.js',
['--ui', 'bdd', '--no-forbid-only'],
function(err, res) {
if (err) {
done(err);
return;
}
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 11);
assert.strictEqual(res.stats.failures, 0);
assert.strictEqual(res.code, 0);
done();
}
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 11);
assert.strictEqual(res.stats.failures, 0);
assert.strictEqual(res.code, 0);
done();
});
);
});
});

describe('tdd', function() {
it('should run only tests that marked as `only`', function(done) {
run('options/only/tdd.fixture.js', ['--ui', 'tdd'], function(err, res) {
if (err) {
done(err);
return;
run(
'options/only/tdd.fixture.js',
['--ui', 'tdd', '--no-forbid-only'],
function(err, res) {
if (err) {
done(err);
return;
}
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 8);
assert.strictEqual(res.stats.failures, 0);
assert.strictEqual(res.code, 0);
done();
}
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 8);
assert.strictEqual(res.stats.failures, 0);
assert.strictEqual(res.code, 0);
done();
});
);
});
});

describe('qunit', function() {
it('should run only tests that marked as `only`', function(done) {
run('options/only/qunit.fixture.js', ['--ui', 'qunit'], function(
err,
res
) {
if (err) {
done(err);
return;
run(
'options/only/qunit.fixture.js',
['--ui', 'qunit', '--no-forbid-only'],
function(err, res) {
if (err) {
done(err);
return;
}
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 5);
assert.strictEqual(res.stats.failures, 0);
assert.strictEqual(res.code, 0);
done();
}
assert.strictEqual(res.stats.pending, 0);
assert.strictEqual(res.stats.passes, 5);
assert.strictEqual(res.stats.failures, 0);
assert.strictEqual(res.code, 0);
done();
});
);
});
});
});
5 changes: 4 additions & 1 deletion test/integration/options/delay.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ describe('--delay', function() {

it('should execute exclusive tests only', function(done) {
var fixture = path.join('options', 'delay-only');
runMochaJSON(fixture, args, function(err, res) {
runMochaJSON(fixture, args.concat(['--no-forbid-only']), function(
err,
res
) {
if (err) {
return done(err);
}
Expand Down
10 changes: 8 additions & 2 deletions test/integration/regression.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ describe('regressions', function() {
});

it('issue-2406: should run nested describe.only suites', function(done) {
runJSON('regression/issue-2406.fixture.js', [], function(err, res) {
runJSON('regression/issue-2406.fixture.js', ['--no-forbid-only'], function(
err,
res
) {
if (err) {
done(err);
return;
Expand All @@ -64,7 +67,10 @@ describe('regressions', function() {
});

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