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

Bug 3840: --forbid-only doesn't recognize it.only when before crashes #4256

Merged
merged 19 commits into from May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c0c1dea
add fixtures that result in it.only combined with --forbid-only bug
arvidOtt Apr 28, 2020
63d6144
adapt forbidonly test cases to cover it.only bug
arvidOtt Apr 28, 2020
2f0f134
check if forbid only option is set prior to marking a test only and t…
arvidOtt Apr 28, 2020
3c8af1b
change name of only test back to previous
arvidOtt Apr 28, 2020
7d6110a
use custom assertion for expecting error in forbidOnly tests
arvidOtt Apr 28, 2020
39e89fe
remove empty line
arvidOtt Apr 28, 2020
11d5fe1
use createUnsupportedError instead of throw new Error
arvidOtt Apr 28, 2020
7015048
use createUnsupportedError instead of throw new Error
arvidOtt Apr 28, 2020
956cef2
remove check if suite hasOnly and forbidOnly option is set as this is…
arvidOtt Apr 28, 2020
4b37e3c
implement markOnly instance method in suite class
arvidOtt May 5, 2020
c2c8dc8
add unit test for suites markOnly method
arvidOtt May 5, 2020
f871782
throw exception if --forbid-only option is set even if suite is not s…
arvidOtt May 5, 2020
336425a
adapt forbidOnly integration tests to check for failure if only suite…
arvidOtt May 5, 2020
cffc71a
fix jsdocs of suite markonly
arvidOtt May 7, 2020
419f584
Revert "fix jsdocs of suite markonly"
arvidOtt May 12, 2020
189b5cf
Revert "adapt forbidOnly integration tests to check for failure if on…
arvidOtt May 12, 2020
053867f
Revert "throw exception if --forbid-only option is set even if suite …
arvidOtt May 12, 2020
0834199
Revert "add unit test for suites markOnly method"
arvidOtt May 12, 2020
3d21897
Revert "implement markOnly instance method in suite class"
arvidOtt May 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/interfaces/common.js
Expand Up @@ -3,6 +3,7 @@
var Suite = require('../suite');
var errors = require('../errors');
var createMissingArgumentError = errors.createMissingArgumentError;
var createUnsupportedError = errors.createUnsupportedError;

/**
* Functions common to more than one interface.
Expand Down Expand Up @@ -126,14 +127,14 @@ module.exports = function(suites, context, mocha) {
suites.unshift(suite);
if (opts.isOnly) {
if (mocha.options.forbidOnly && shouldBeTested(suite)) {
throw new Error('`.only` forbidden');
throw createUnsupportedError('`.only` forbidden');
}

suite.parent.appendOnlySuite(suite);
}
if (suite.pending) {
if (mocha.options.forbidPending && shouldBeTested(suite)) {
throw new Error('Pending test forbidden');
throw createUnsupportedError('Pending test forbidden');
}
}
if (typeof opts.fn === 'function') {
Expand Down Expand Up @@ -165,6 +166,8 @@ module.exports = function(suites, context, mocha) {
* @returns {*}
*/
only: function(mocha, test) {
if (mocha.options.forbidOnly)
throw createUnsupportedError('`.only` forbidden');
test.markOnly();
return test;
},
Expand Down
5 changes: 0 additions & 5 deletions lib/runner.js
Expand Up @@ -522,11 +522,6 @@ Runner.prototype.runTest = function(fn) {
return;
}

var suite = this.parents().reverse()[0] || this.suite;
if (this.forbidOnly && suite.hasOnly()) {
fn(new Error('`.only` forbidden'));
return;
}
if (this.asyncOnly) {
test.asyncOnly = true;
}
Expand Down
@@ -0,0 +1,8 @@
'use strict';

describe('test marked with only and beforeEach has skip', function() {
beforeEach(function() {
this.skip();
});
it.only('only test', function() {});
});
@@ -0,0 +1,8 @@
'use strict';

describe('test marked with only and before has skip', function() {
before(function() {
this.skip();
});
it.only('only test', function() {});
});
70 changes: 50 additions & 20 deletions test/integration/options/forbidOnly.spec.js
Expand Up @@ -26,13 +26,19 @@ describe('--forbid-only', function() {

it('should fail if there are tests marked only', function(done) {
var fixture = path.join('options', 'forbid-only', 'only');
runMochaJSON(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', onlyErrorMessage);
done();
});
var spawnOpts = {stdio: 'pipe'};
runMocha(
fixture,
args,
function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with output', new RegExp(onlyErrorMessage));
done();
},
spawnOpts
);
});

it('should fail if there are tests in suites marked only', function(done) {
Expand All @@ -45,11 +51,7 @@ describe('--forbid-only', function() {
if (err) {
return done(err);
}

expect(res, 'to satisfy', {
code: 1,
output: new RegExp(onlyErrorMessage)
});
expect(res, 'to have failed with output', new RegExp(onlyErrorMessage));
done();
},
spawnOpts
Expand All @@ -66,10 +68,7 @@ describe('--forbid-only', function() {
if (err) {
return done(err);
}
expect(res, 'to satisfy', {
code: 1,
output: new RegExp(onlyErrorMessage)
});
expect(res, 'to have failed with output', new RegExp(onlyErrorMessage));
done();
},
spawnOpts
Expand All @@ -86,10 +85,7 @@ describe('--forbid-only', function() {
if (err) {
return done(err);
}
expect(res, 'to satisfy', {
code: 1,
output: new RegExp(onlyErrorMessage)
});
expect(res, 'to have failed with output', new RegExp(onlyErrorMessage));
done();
},
spawnOpts
Expand Down Expand Up @@ -124,4 +120,38 @@ describe('--forbid-only', function() {
}
);
});

it('should fail even if before has "skip"', function(done) {
var fixture = path.join('options', 'forbid-only', 'only-before');
var spawnOpts = {stdio: 'pipe'};
runMocha(
fixture,
args,
function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with output', new RegExp(onlyErrorMessage));
done();
},
spawnOpts
);
});

it('should fail even if beforeEach has "skip"', function(done) {
var fixture = path.join('options', 'forbid-only', 'only-before-each');
var spawnOpts = {stdio: 'pipe'};
runMocha(
fixture,
args,
function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with output', new RegExp(onlyErrorMessage));
done();
},
spawnOpts
);
});
});