-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to forbid empty test suites
- Loading branch information
Showing
13 changed files
with
176 additions
and
0 deletions.
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