Merged
Conversation
`withinSandbox` is designed for tests that need to act on the filesystem. It creates a temporary directory and passes it to the function so that it can do whatever it needs to do within the directory in a safer fashion. The name of the sandbox directory is generated from the current time to ensure that each one is unique. However, this causes problems when Jest is running more than one test file, each of which make use of the sandbox. Jest runs test files in parallel, so paired with the naming — and the fact that time can be frozen in tests — it is possible for two tests to create and use the same sandbox simultaneously. `withinSandbox` double-checks that the directory it would have created does not already exist, so when the first test creates the directory it will cause the second test to fail. Also, since `withinSandbox` removes the sandbox directory after it runs its function, this will also cause the second test to fail if it's still running and using that directory. To fix this, this commit changes `withinSandbox` to use a UUID to name the sandbox directory instead of the current time.
|
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
kanthesha
approved these changes
Mar 5, 2024
kanthesha
left a comment
There was a problem hiding this comment.
Tested with module-lint, worked fine.
LGTM.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
withinSandboxis designed for tests that need to act on the filesystem. It creates a temporary directory and passes it to the function so that it can do whatever it needs to do within the directory in a safer fashion.The name of the sandbox directory is generated from the current time to ensure that each one is unique. However, this causes problems when Jest is running more than one test file, each of which make use of the sandbox. Jest runs test files in parallel, so paired with the naming — and the fact that time can be frozen in tests — it is possible for two tests to create and use the same sandbox simultaneously.
withinSandboxdouble-checks that the directory it would have created does not already exist, so when the first test creates the directory it will cause the second test to fail. Also, sincewithinSandboxremoves the sandbox directory after it runs its function, this will also cause the second test to fail if it's still running and using that directory.To fix this, this commit changes
withinSandboxto use a UUID to name the sandbox directory instead of the current time.Fixes #166.