-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Dont run before and after hooks when all tests are skipped (#1283) #1570
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,19 +178,32 @@ class TestCollection extends EventEmitter { | |
| _buildTests(tests) { | ||
| return tests.map(test => this._buildTestWithHooks(test)); | ||
| } | ||
| _hasUnskippedTests() { | ||
| return this.tests.serial.concat(this.tests.concurrent) | ||
| .some(test => { | ||
| return !(test.metadata && test.metadata.skipped === true); | ||
| }); | ||
| } | ||
| build() { | ||
| const beforeHooks = new Sequence(this._buildHooks(this.hooks.before)); | ||
| const afterHooks = new Sequence(this._buildHooks(this.hooks.after)); | ||
|
|
||
| const serialTests = new Sequence(this._buildTests(this.tests.serial), this.bail); | ||
| const concurrentTests = new Concurrent(this._buildTests(this.tests.concurrent), this.bail); | ||
| const allTests = new Sequence([serialTests, concurrentTests]); | ||
|
|
||
| let finalTests = new Sequence([beforeHooks, allTests, afterHooks], true); | ||
| let finalTests; | ||
| // Only run before and after hooks when there are unskipped tests | ||
| if (this._hasUnskippedTests()) { | ||
| const beforeHooks = new Sequence(this._buildHooks(this.hooks.before)); | ||
| const afterHooks = new Sequence(this._buildHooks(this.hooks.after)); | ||
| finalTests = new Sequence([beforeHooks, allTests, afterHooks], true); | ||
| } else { | ||
| finalTests = new Sequence([allTests], true); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be an empty sequence, since presumably all tests are skipped if it gets to this point. That would make the logic easier to grasp IMHO.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that would work. If it's an empty sequence, the skipped tests won't be reported in the runner output.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah that makes sense 👍 |
||
| } | ||
|
|
||
| if (this.hooks.afterAlways.length > 0) { | ||
| const afterAlwaysHooks = new Sequence(this._buildHooks(this.hooks.afterAlways)); | ||
| finalTests = new Sequence([finalTests, afterAlwaysHooks], false); | ||
| } | ||
|
|
||
| return finalTests; | ||
| } | ||
| attributeLeakedError(err) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import test from '../..'; | ||
|
|
||
| test.before(() => { | ||
| throw new Error('should not run'); | ||
| }); | ||
|
|
||
| test.after(() => { | ||
| throw new Error('should not run'); | ||
| }); | ||
|
|
||
| test.beforeEach(() => { | ||
| throw new Error('should not run'); | ||
| }); | ||
|
|
||
| test.afterEach(() => { | ||
| throw new Error('should not run'); | ||
| }); | ||
|
|
||
| test.skip('some skipped test', t => { | ||
| t.fail(); | ||
| }); |
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.
You could create the
allTestssequence in this branch.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.
Not sure I can, see response to the comment below.