fix: remove implicit global references#932
Merged
ph-fritsche merged 3 commits intoglobals-mergefrom Apr 17, 2022
Merged
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e7dc587:
|
Codecov Report
@@ Coverage Diff @@
## globals-merge #932 +/- ##
=================================================
Coverage ? 100.00%
=================================================
Files ? 85
Lines ? 1784
Branches ? 641
=================================================
Hits ? 1784
Misses ? 0
Partials ? 0 Continue to review full report at Codecov.
|
d5c9f73 to
e7dc587
Compare
|
🎉 This PR is included in version 14.1.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
2 tasks
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.
What:
Remove global references or make them explicit.
Why:
There might be problems with shadowed global variables in testing environments. See #892
The way e.g. jest hoists code we cannot be sure that a reference to e.g.
windowin a module is a reference toglobalThis.window. We further cannot be sure that e.g.document.defaultViewreferences the same object aswindow.Although this is probably no issue in most cases we should be explicit about where we access objects through variables the user provided per
setup()and where we access through global variables.#929 , #931 enforce to be explicit about access to globals. Any reference that can't be found per text search for
globalThis.results in a linting error.How:
Clipboardutil. We already pass downwindowto thecreatefunctions so we can use the scoped variable in theclass.We still access the global
windowfor ourafterEachandafterAllhooks toreset/detachtheClipboardstub. This is probably not an issue as the environments providing a globalafter*hook are probably identical to environments mergingwindowinto the global scope (like jest+jsdom).If you happen to use an environment where you need to work around this, please leave a comment.
setup()explicit. If the user provides adocumentwithdefaultView, these won't be used.parseInt,setTimeout) in utils explicit.Checklist: