-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add option to forbid empty test suites #4123
Closed
+176
−0
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/integration/fixtures/options/forbid-empty-suite/dynamically-added-test.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
describe('suite with dynamically added test', function() { | ||
const suite = this; | ||
before(function() { | ||
suite.suites[1].addTest(it('added test', function() {})); | ||
}); | ||
|
||
describe('A', function() { | ||
it('existing test', () => {}); | ||
}); | ||
|
||
describe('B', function() {}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
test/integration/fixtures/options/forbid-empty-suite/empty-nested-suite.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
describe('parent suite', function() { | ||
describe('suite with test', function() { | ||
it('it nested', function() {}); | ||
}); | ||
describe('empty suite', function() {}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
test/integration/fixtures/options/forbid-empty-suite/empty-suite.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
describe('forbid empty suite - empty', function() {}); |
1 change: 1 addition & 0 deletions
1
test/integration/fixtures/options/forbid-empty-suite/empty.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'use strict'; |
7 changes: 7 additions & 0 deletions
7
test/integration/fixtures/options/forbid-empty-suite/nested-suite.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
describe('parent suite', function() { | ||
describe('suite with test', function() { | ||
it('it nested', function() {}); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/integration/fixtures/options/forbid-empty-suite/passed.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
describe('forbid empty suite - not empty', function() { | ||
it('test1', function() {}); | ||
it('test2', function() {}); | ||
it('test3', function() {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict'; | ||
|
||
var path = require('path').posix; | ||
var helpers = require('../helpers'); | ||
var runMocha = helpers.runMocha; | ||
var runMochaJSON = helpers.runMochaJSON; | ||
|
||
describe('--forbid-empty-suite', function() { | ||
var args = []; | ||
var emptySuiteErrorMessage = 'Empty suite forbidden'; | ||
|
||
before(function() { | ||
args = ['--forbid-empty-suite']; | ||
}); | ||
|
||
it('should succeed if there are tests', function(done) { | ||
var fixture = path.join('options', 'forbid-empty-suite', 'passed'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
expect(res, 'to have passed'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should succeed if there is an inner suite with tests', function(done) { | ||
var fixture = path.join('options', 'forbid-empty-suite', 'nested-suite'); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
expect(res, 'to have passed'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should succeed if there are dynamically added tests', function(done) { | ||
var fixture = path.join( | ||
'options', | ||
'forbid-empty-suite', | ||
'dynamically-added-test' | ||
); | ||
runMochaJSON(fixture, args, function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
expect(res, 'to have passed'); | ||
done(); | ||
}); | ||
}); | ||
|
||
var forbidEmptySuiteFailureTests = { | ||
'should fail if there are no test suites': 'empty', | ||
'should fail if there are no tests': 'empty-suite', | ||
'should fail if there is an inner suite with no tests': 'empty-nested-suite' | ||
}; | ||
|
||
Object.keys(forbidEmptySuiteFailureTests).forEach(function(title) { | ||
it(title, function(done) { | ||
var fixture = path.join( | ||
'options', | ||
'forbid-empty-suite', | ||
forbidEmptySuiteFailureTests[title] | ||
); | ||
var spawnOpts = {stdio: 'pipe'}; | ||
runMocha( | ||
fixture, | ||
args, | ||
function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
expect(res, 'to satisfy', { | ||
code: 1, | ||
output: new RegExp(emptySuiteErrorMessage) | ||
}); | ||
done(); | ||
}, | ||
spawnOpts | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suite
does not extendRunnable
(as doesTest
andHook
), so you can'tfail
aSuite
.The reporter output is weird, if the test file contains only an empty suite.
Maybe a dummy test?