-
-
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
Use globalThis
(with fallback if needed) instead of global
to enable esbuild support
#11569
Conversation
By using `global`, the package `pretty-format` can not be bundled for the browser by `esbuild` because `global` is not defined in a browser environment. Switching to `globalThis`, with a polyfill for older environments, allows `pretty-format` (and hopefully other packages) to be bundled by `esbuild --platform browser`.
Codecov Report
@@ Coverage Diff @@
## master #11569 +/- ##
==========================================
- Coverage 69.00% 69.00% -0.01%
==========================================
Files 312 312
Lines 16331 16331
Branches 4730 4730
==========================================
- Hits 11270 11269 -1
- Misses 5033 5034 +1
Partials 28 28
Continue to review full report at Codecov.
|
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.
thanks! Could you add an entry to the changelog as well?
globalThis
(with polyfill if needed) instead of global
to enable esbuild supportglobalThis
(with fallback if needed) instead of global
to enable esbuild support
We are not using any of the features which were removed or changed in the new version. The new version also removes the need for the hack.js file we needed to use this is because, the package is using the latest major versio of pretty-format, which contains this update jestjs/jest#11569
We are not using any of the features which were removed or changed in the new version. The new version also removes the need for the hack.js file we needed to use this is because, the package is using the latest major versio of pretty-format, which contains this update jestjs/jest#11569
We are not using any of the features which were removed or changed in the new version. The new version also removes the need for the hack.js file we needed to use this is because, the package is using the latest major versio of pretty-format, which contains this update jestjs/jest#11569
We are not using any of the features which were removed or changed in the new version. The new version also removes the need for the hack.js file we needed to use this is because, the package is using the latest major versio of pretty-format, which contains this update jestjs/jest#11569
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
The motivation for this pull-request is to get the jest packages such as
pretty-format
to work with esbuild when targeting the browser platform. This is because @testing-library/dom uses pretty-format and I am trying to use that package as part of my testing setup.By using
global
, the packagepretty-format
can not be bundled for the browser byesbuild
becauseglobal
is not defined in a browser environment.Switching to
globalThis
, with a polyfill for older environments, allowspretty-format
(and hopefully other packages) to be bundled byesbuild --platform browser
.Test plan
The change does not modify any logic of Jest's packages, it only adds a polyfill for
globalThis
.A way to test this change will solve my original problem would be to build the project and then attempt to bundle
pretty-format
withesbuild --bundle --target=es2020 --platform=browser
and run the bundle in a browser environment.Before
Building from master branch:
Running the bundle in the browser gives an Error
Uncaught ReferenceError: global is not defined
After
Building from globalthis branch:
Running the bundle in the browser gives no error: