-
-
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
Behavior of after/afterEach hooks with --bail flag #3617
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
describe('suite1', function () { | ||
it('should display this spec', function () {}); | ||
|
||
it('should only display this error', function (done) { | ||
throw new Error('this should be displayed'); | ||
}); | ||
|
||
it('should not display this error', function (done) { | ||
throw new Error('this should not be displayed'); | ||
}); | ||
}); | ||
|
||
describe('suite2', function () { | ||
before(function (done) { | ||
throw new Error('this hook should not be displayed'); | ||
}); | ||
|
||
it('should not display this error', function (done) { | ||
throw new Error('this should not be displayed'); | ||
}); | ||
}); |
54 changes: 50 additions & 4 deletions
54
test/integration/fixtures/options/bail-with-after.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 |
---|---|---|
@@ -1,11 +1,57 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('suite1', function () { | ||
it('should only display this error', function () { | ||
throw new Error('this should be displayed'); | ||
var runOrder = []; | ||
before('before suite1', function () { | ||
runOrder.push('before suite1'); | ||
}); | ||
beforeEach('beforeEach suite1', function () { | ||
runOrder.push('beforeEach suite1'); | ||
}); | ||
it('test suite1', function () { | ||
runOrder.push('test suite1'); | ||
}); | ||
|
||
describe('suite1A', function () { | ||
before('before suite1A', function () { | ||
runOrder.push('before suite1A'); | ||
}); | ||
beforeEach('beforeEach suite1A', function () { | ||
runOrder.push('beforeEach suite1A'); | ||
}); | ||
it('test suite1A', function () { | ||
runOrder.push('test suite1A'); | ||
}); | ||
afterEach('afterEach suite1A', function () { | ||
runOrder.push('afterEach suite1A'); | ||
}); | ||
after('after suite1A', function () { | ||
runOrder.push('after suite1A'); | ||
throw new Error('after suite1A error'); | ||
}); | ||
}); | ||
|
||
afterEach('afterEach suite1', function () { | ||
runOrder.push('afterEach suite1'); | ||
}); | ||
after('after suite1', function () { | ||
runOrder.push('after suite1'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'before suite1', 'beforeEach suite1', 'test suite1', | ||
'afterEach suite1', 'before suite1A', 'beforeEach suite1', | ||
'beforeEach suite1A', 'test suite1A', 'afterEach suite1A', | ||
'afterEach suite1', 'after suite1A', 'after suite1' | ||
]); | ||
}); | ||
}); | ||
|
||
after(function () { | ||
throw new Error('this hook should not be displayed'); | ||
describe('suite2', function () { | ||
before('before suite2', function () {}); | ||
beforeEach('beforeEach suite2', function () {}); | ||
it('test suite2', function () { | ||
runOrder.push('test suite2 - should not run'); | ||
}); | ||
afterEach('afterEach suite2', function () {}); | ||
after('after suite2', function () {}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
test/integration/fixtures/options/bail-with-afterEach.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,57 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('suite1', function () { | ||
var runOrder = []; | ||
before('before suite1', function () { | ||
runOrder.push('before suite1'); | ||
}); | ||
beforeEach('beforeEach suite1', function () { | ||
runOrder.push('beforeEach suite1'); | ||
}); | ||
it('test suite1', function () { | ||
runOrder.push('test suite1'); | ||
}); | ||
|
||
describe('suite1A', function () { | ||
before('before suite1A', function () { | ||
runOrder.push('before suite1A'); | ||
}); | ||
beforeEach('beforeEach suite1A', function () { | ||
runOrder.push('beforeEach suite1A'); | ||
}); | ||
it('test suite1A', function () { | ||
runOrder.push('test suite1A'); | ||
}); | ||
afterEach('afterEach suite1A', function () { | ||
runOrder.push('afterEach suite1A'); | ||
throw new Error('afterEach suite1A error'); | ||
}); | ||
after('after suite1A', function () { | ||
runOrder.push('after suite1A'); | ||
}); | ||
}); | ||
|
||
afterEach('afterEach suite1', function () { | ||
runOrder.push('afterEach suite1'); | ||
}); | ||
after('after suite1', function () { | ||
runOrder.push('after suite1'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'before suite1', 'beforeEach suite1', 'test suite1', | ||
'afterEach suite1', 'before suite1A', 'beforeEach suite1', | ||
'beforeEach suite1A', 'test suite1A', 'afterEach suite1A', | ||
'afterEach suite1', 'after suite1A', 'after suite1' | ||
]); | ||
}); | ||
}); | ||
|
||
describe('suite2', function () { | ||
before('before suite2', function () {}); | ||
beforeEach('beforeEach suite2', function () {}); | ||
it('test suite2', function () { | ||
runOrder.push('test suite2 - should not run'); | ||
}); | ||
afterEach('afterEach suite2', function () {}); | ||
after('after suite2', function () {}); | ||
}); |
41 changes: 37 additions & 4 deletions
41
test/integration/fixtures/options/bail-with-before.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 |
---|---|---|
@@ -1,11 +1,44 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('suite1', function () { | ||
before(function () { | ||
throw new Error('this hook should be only displayed'); | ||
var runOrder = []; | ||
before('before suite1', function () { | ||
runOrder.push('before suite1'); | ||
throw new Error('before suite1 error'); | ||
}); | ||
beforeEach('beforeEach suite1', function () { | ||
runOrder.push('beforeEach suite1 - should not run'); | ||
}); | ||
it('test suite1', function () { | ||
runOrder.push('test suite1 - should not run'); | ||
}); | ||
|
||
describe('suite1A', function () { | ||
before('before suite1A', function () {}); | ||
beforeEach('beforeEach suite1A', function () {}); | ||
it('test suite1A', function () { | ||
runOrder.push('test suite1A - should not run'); | ||
}); | ||
afterEach('afterEach suite1A', function () {}); | ||
after('after suite1A', function () {}); | ||
}); | ||
|
||
afterEach('afterEach suite1', function () { | ||
runOrder.push('afterEach suite1 - should not run'); | ||
}); | ||
after('after suite1', function () { | ||
runOrder.push('after suite1'); | ||
assert.deepStrictEqual(runOrder, ['before suite1', 'after suite1']); | ||
}); | ||
}); | ||
|
||
it('should not display this error', function () { | ||
throw new Error('this should not be displayed'); | ||
describe('suite2', function () { | ||
before('before suite2', function () {}); | ||
beforeEach('beforeEach suite2', function () {}); | ||
it('test suite2', function () { | ||
runOrder.push('test suite2 - should not run'); | ||
}); | ||
afterEach('afterEach suite2', function () {}); | ||
after('after suite2', function () {}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
test/integration/fixtures/options/bail-with-beforeEach.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,46 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('suite1', function () { | ||
var runOrder = []; | ||
before('before suite1', function () { | ||
runOrder.push('before suite1'); | ||
}); | ||
beforeEach('beforeEach suite1', function () { | ||
runOrder.push('beforeEach suite1'); | ||
throw new Error('beforeEach suite1 error'); | ||
}); | ||
it('test suite1', function () { | ||
runOrder.push('test suite1 - should not run'); | ||
}); | ||
|
||
describe('suite1A', function () { | ||
before('before suite1A', function () {}); | ||
beforeEach('beforeEach suite1A', function () {}); | ||
it('test suite1A', function () { | ||
runOrder.push('test suite1A - should not run'); | ||
}); | ||
afterEach('afterEach suite1A', function () {}); | ||
after('after suite1A', function () {}); | ||
}); | ||
|
||
afterEach('afterEach suite1', function () { | ||
runOrder.push('afterEach suite1'); | ||
}); | ||
after('after suite1', function () { | ||
runOrder.push('after suite1'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'before suite1', 'beforeEach suite1', 'afterEach suite1', 'after suite1' | ||
]); | ||
}); | ||
}); | ||
|
||
describe('suite2', function () { | ||
before('before suite2', function () {}); | ||
beforeEach('beforeEach suite2', function () {}); | ||
it('test suite2', function () { | ||
runOrder.push('test suite2 - should not run'); | ||
}); | ||
afterEach('afterEach suite2', function () {}); | ||
after('after suite2', function () {}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
test/integration/fixtures/options/bail-with-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,47 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('suite1', function () { | ||
var runOrder = []; | ||
before('before suite1', function () { | ||
runOrder.push('before suite1'); | ||
}); | ||
beforeEach('beforeEach suite1', function () { | ||
runOrder.push('beforeEach suite1'); | ||
}); | ||
it('test suite1', function () { | ||
runOrder.push('test suite1'); | ||
throw new Error('test suite1 error'); | ||
}); | ||
|
||
describe('suite1A', function () { | ||
before('before suite1A', function () {}); | ||
beforeEach('beforeEach suite1A', function () {}); | ||
it('test suite1A', function () { | ||
runOrder.push('test suite1A - should not run'); | ||
}); | ||
afterEach('afterEach suite1A', function () {}); | ||
after('after suite1A', function () {}); | ||
}); | ||
|
||
afterEach('afterEach suite1', function () { | ||
runOrder.push('afterEach suite1'); | ||
}); | ||
after('after suite1', function () { | ||
runOrder.push('after suite1'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'before suite1', 'beforeEach suite1', 'test suite1', | ||
'afterEach suite1', 'after suite1' | ||
]); | ||
}); | ||
}); | ||
|
||
describe('suite2', function () { | ||
before('before suite2', function () {}); | ||
beforeEach('beforeEach suite2', function () {}); | ||
it('test suite2', function () { | ||
runOrder.push('test suite2 - should not run'); | ||
}); | ||
afterEach('afterEach suite2', function () {}); | ||
after('after suite2', 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
Oops, something went wrong.
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.
was this causing a problem? perhaps your changes should actually be additions; two tests that use
done
and two that don't. this would give us confidence that the same thing works properly regardless of the Runnable's strategy (async or sync)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.
no, no problem arose, the 'suite2' describe is skipped (correctly) anyway. I added a second test, one sync and one async.