-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Detect open handles with done callbacks #11382
Merged
SimenB
merged 13 commits into
jestjs:master
from
Mr0grog:detect-open-handles-with-done-callbacks
May 20, 2021
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8c6276d
Add failing tests for open handles with `done`
Mr0grog 125d47b
Wrap functions w/ a callback in a named function
Mr0grog 799399e
Add missing copyright headers
Mr0grog 6d47be8
Fix runtime type-checking for non-functions
Mr0grog 944f969
Update snapshot tests with new callstacks
Mr0grog bdb38fd
Keep correct `this` for wrapped test functions
Mr0grog 2088443
Update packages/jest-jasmine2/src/jasmineAsyncInstall.ts
Mr0grog 2adf035
Update packages/jest-jasmine2/src/jasmineAsyncInstall.ts
Mr0grog ca185ca
Use correct type for `this` in test functions
Mr0grog 439018f
Add changelog entries for #11382
Mr0grog b144f11
Follow existing test style without `--forceExit`
Mr0grog 6eb3969
Tweak implementation to pass both Jasmine & Circus
Mr0grog 4803a6c
Revert to previous implementation and tweak test
Mr0grog 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const http = require('http'); | ||
|
||
test('something', done => { | ||
const server = http.createServer((_, response) => response.end('ok')); | ||
server.listen(0, () => { | ||
expect(true).toBe(true); | ||
done(); | ||
}); | ||
}); |
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,18 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const http = require('http'); | ||
|
||
beforeAll(done => { | ||
const server = http.createServer((_, response) => response.end('ok')); | ||
server.listen(0, () => { | ||
done(); | ||
}); | ||
}); | ||
|
||
test('something', () => { | ||
expect(true).toBe(true); | ||
}); |
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
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.
can you use
waitUntil
instead offorceExit
?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.
There doesn't seem to be any text that comes after the message about the open handle(s), so the best I could think to do with
waitUntil()
was to wait for the message that tests were done, then wait a few more ticks for the open handles to be printed. If I wait for the actual message about the open handles, the test would time out waiting in the error case when the handles aren't printed.--forceExit
seemed cleaner and more reliable than that. Is there a better approach I'm missing?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.
I think it makes more sense to match the style of the other tests which will all time out if the message is not printed.
One thing we could do in general I guess is to add a timeout to
waitUntil
and first wait for tests to complete, then wait for the handle text with a timeout. But regardless, for consistency now I prefer not usingforceExit