Skip to content
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

[test] Fix open handles in unit tests #117

Merged
merged 3 commits into from
Nov 15, 2023

Conversation

Drarig29
Copy link
Contributor

@Drarig29 Drarig29 commented Nov 14, 2023

This PR will fix this issue:

image

This is caused by azure-pipelines-task-lib, which used to use sync-request (a way to synchronously make a request, which they use to download Node.js before running the unit tests).

This sync-request package is known for leaving orphan processes (ForbesLindesay/sync-request#137) at import time and it recently had some vulnerabilities, which led Microsoft to remove this dependency (microsoft/azure-pipelines-task-lib#932), hence the need to bump azure-pipelines-task-lib: 07464dd

@@ -1,6 +1,6 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
moduleFileExtensions: ['js', 'ts', 'node'],
Copy link
Contributor Author

@Drarig29 Drarig29 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addition solves this issue. Found the solution here: jestjs/jest#1694 (comment)

Comment on lines +40 to +41
const task = await new MockTestRunner().LoadAsync(file)
await task.runAsync(nodeVersion)
Copy link
Contributor Author

@Drarig29 Drarig29 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now has to be async, otherwise this line will do an infinite loop. See this CI, that I had to cancel.

@Drarig29 Drarig29 marked this pull request as ready for review November 14, 2023 14:58
@Drarig29 Drarig29 requested a review from a team as a code owner November 14, 2023 14:58
@Drarig29 Drarig29 changed the title Fix open handles in unit tests [test] Fix open handles in unit tests Nov 14, 2023
Comment on lines -43 to 46
// Warnings usually come from `mockery`, and can be useful to spot mocking issues.
// Warnings can be useful to spot mocking issues.
// For example, "Replacing existing mock for module: azure-pipelines-task-lib/task" means
// that we tried to mock `azure-pipelines-task-lib/task`, which is already mocked
// by `azure-pipelines-task-lib/mock-run`. So our mock would be overwritten.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They removed mockery (microsoft/azure-pipelines-task-lib#968), and Replacing existing mock for module can still be logged, so I updated the comment.

Copy link
Contributor

@jakepruitt jakepruitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for handling this

@Drarig29 Drarig29 merged commit f53c760 into main Nov 15, 2023
6 checks passed
@Drarig29 Drarig29 deleted the corentin.girard/fix-open-handles-in-unit-tests branch November 15, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants