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

fix(pretty-format): Crash in ES5 environments #9635

Closed
wants to merge 4 commits into from

Conversation

eps1lon
Copy link
Contributor

@eps1lon eps1lon commented Mar 4, 2020

Summary

Fixes a crash in ES5 environments (or other environments not implementing Object.entries)

Test plan

Edit: Only test I have is using prett-format@24 vs pretty-format@25

Don't have any (because the dependency is inlined) unless you somehow build canaries that I can install. I know that ansi-styles@3 does not use Object.entries while ansi-styles@4 does.

@eps1lon
Copy link
Contributor Author

eps1lon commented Mar 4, 2020

Only test I have is using prett-format@24 vs pretty-format@25

@eps1lon eps1lon changed the title fix(pretty-format): Crash in IE 11 fix(pretty-format): Crash in ES5 environments Mar 9, 2020
@eps1lon
Copy link
Contributor Author

eps1lon commented Mar 9, 2020

Wanted to point out that IE 11 is just a specific environment. It crashes on any environment that only supports ES5. Since this packages has a dedicated build for those environments (build-es5) it should not use dependencies that make use of Object.entries.

@thymikee
Copy link
Collaborator

Shouldn't we tinker our build config, so it compiles away Object.entries instead?

@eps1lon
Copy link
Contributor Author

eps1lon commented Mar 10, 2020

Shouldn't we tinker our build config, so it compiles away Object.entries instead?

That's a possibility. Though you would need to compile node_modules/ in this case.

@SimenB
Copy link
Member

SimenB commented Mar 10, 2020

We compile (and bundle) for browser, so I think it makes more sense to transpile than downgrade

@eps1lon
Copy link
Contributor Author

eps1lon commented Mar 10, 2020

We compile (and bundle) for browser, so I think it makes more sense to transpile than downgrade

I'll take a look at the build setup. Thanks for the feedback!

@SimenB
Copy link
Member

SimenB commented Mar 10, 2020

Sorry, I was supposed to link this but got distracted: https://github.com/facebook/jest/blob/master/scripts/browserBuild.js. It's the browser build script, theoretically targeting ES5

@eps1lon
Copy link
Contributor Author

eps1lon commented Mar 10, 2020

No worries I found it already.

We have to keep in mind though that using transform-runtime overtranspiles by a lot. Though there are currently plans in babel to improve this issue:babel/babel#10008.

I don't know if any of the affected packages are used in user-facing bundles. If so then going from 102KB unminified to 537KB is not acceptable. I personally don't care about the size of this package since I only use it when running tests in the browser. Bundle size is no major concern for these cases.

@codecov-io
Copy link

Codecov Report

Merging #9635 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9635      +/-   ##
==========================================
+ Coverage   65.09%   65.11%   +0.01%     
==========================================
  Files         287      287              
  Lines       12144    12144              
  Branches     3009     3009              
==========================================
+ Hits         7905     7907       +2     
+ Misses       3604     3603       -1     
+ Partials      635      634       -1     
Impacted Files Coverage Δ
packages/expect/src/utils.ts 96.22% <0.00%> (+1.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3aa106...4f1a45f. Read the comment docs.

@SimenB
Copy link
Member

SimenB commented Mar 11, 2020

Yikes. Is it possible to target just the offending package?

@eps1lon
Copy link
Contributor Author

eps1lon commented Mar 11, 2020

I already did. Transform-runtime with core-js is just that overzealous. I can take a closer look at the added bytes and see how a prod bundle would look like.

@SimenB
Copy link
Member

SimenB commented Apr 23, 2020

We'll be splitting out the es5 builds in Jest 26 (so you'll install pretty-format-browser or some such) - at that point I guess we don't have to care about the bundle size anymore. We'll still build and publish them from here, but they won't be installed by default, and you have to alias them in your bundler (or drop an unpkg.com link in a script tag with it, I guess)

@thymikee
Copy link
Collaborator

thymikee commented May 3, 2020

@SimenB es5 builds are now removed, but we didn't provide them as separate packages just yet.

@SimenB
Copy link
Member

SimenB commented May 3, 2020

Right... We can create those packages, I guess. index.ts is just export * from 'expect' or whatever and reinstate the old browser build. Anyone up for it?

Telling people to transpile themselves sounds good, but I think being able to use these packages via a script tag is useful

@SimenB SimenB mentioned this pull request May 4, 2020
@eps1lon
Copy link
Contributor Author

eps1lon commented Sep 9, 2021

No longer interested in making this work.

@eps1lon eps1lon closed this Sep 9, 2021
@eps1lon eps1lon deleted the fix/prety-format/object-entries branch September 9, 2021 08:44
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants