jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.26k stars 508 forks source link

(deps): upgrade to Jest 25 #679

Closed agilgur5 closed 4 years ago

agilgur5 commented 4 years ago

Fixes #664

Merges a few Greenkeeper PRs together so all of Jest 25 related deps are done in one step:

Not sure why Greenkeeper didn't make a PR to update Jest itself, it only did the related deps 🤔


This is built on top of #678 , merge that first

Bnaya commented 4 years ago

Make it 26 now? 😅

agilgur5 commented 4 years ago

@Bnaya other than Jest 26 having more breaking changes, it also requires TS 3.8. TS 3.8 private fields break rollup-plugin-typescript2, which is more an upstream Rollup issue, which is more of an upstream Acorn issue, which hasn't been maintained too well so Rollup contributors forked it for class fields support (but not private fields), and those would only really be fixed in Rollup v2, which is also breaking, and breaks various plugins TSDX users use.

Rest assured, I have my eyes on the deps and how they break TSDX's users' code.

nareshbhatia commented 4 years ago

@agilgur5, I am porting over a significant monorepo to TSDX. Getting the packages to compile was fairly straight forward, however many of the tests are failing because TSDX is using Jest v24.9.0. My original monorepo is using Jest v26.1.0 and runs successfully, thanks to various bug fixes in Jest.

I read your comment about TSDX's dependency on rollup-plugin-typescript2 which is holding up the upgrade to Jest. What workaround would you recommend in my case?

TIA.

agilgur5 commented 4 years ago

@nareshbhatia if you need Jest 26, you don't need to wait for TSDX to upgrade to it. You don't need to use tsdx test and can swap it for jest.

nareshbhatia commented 4 years ago

Turns out that even after upgrading to Jest 26 and running jest directly, those errors would not go away. Here are the specific errors:

From everything I read, Jest 26 now includes jsdom 16 which fixes these errors. All I can think of is somehow the correct version of jsdom is not being picked up.

Finally I installed jest-environment-jsdom-sixteen and forced it via jest.config.js:

testEnvironment: 'jest-environment-jsdom-sixteen'

This made all the tests pass. This works even with tsdx test. So I am switching back to it (removed jest 26 completely). Can't explain exactly why it didn't work with Jest 26, but hope this helps anyone else running into this issue.

agilgur5 commented 4 years ago

Can't explain exactly why it didn't work with Jest 26

Yea that's weird. Maybe Jest's auto-import capabilities glitched out with two versions of Jest/JSDOM installed. I know there have been issues with it before but I believe Node's algorithm should choose the closest one by default (which should be the one the Jest version you use specifies).

MutationObserver is not a constructor

Yea this one specifically was addressed in #724 as well.

Good to hear it got resolved one way or another though and that you could still stick to tsdx test.

vercel[bot] commented 4 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/formium/tsdx/lmhmmniws
✅ Preview: https://tsdx-git-fork-agilgur5-jest-25.formium.vercel.app

agilgur5 commented 4 years ago

678 has been merged so rebased everything in and tests are passing. Merging as getting ready to release v0.14.0 now that v0.13.3 has been released

agilgur5 commented 4 years ago

Checked what all the deprecation warnings on a fresh install of v0.13.3 are per https://github.com/formium/tsdx/pull/789#issuecomment-695854530, and saw that this should fix several of them since they're all from transitive dependencies of JSDOM 11, which was upgraded to JSDOM 15 with Jest 25:

npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2. // jest@24.9.0 ... jsdom@11.12.0
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart() // jest@24.9.0 ... jsdom@11.12.0
npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142 // // jest@24.9.0 ... jsdom@11.12.0
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 // jest@24.9.0 ... jsdom@11.12.0
npm WARN deprecated har-validator@5.1.5: this library is no longer supported // jest@24.9.0 ... jsdom@11.12.0 ... request@2.88.0
JBaczuk commented 3 years ago

Finally I installed jest-environment-jsdom-sixteen and forced it via jest.config.js:

testEnvironment: 'jest-environment-jsdom-sixteen'

I can confirm this workaround from @nareshbhatia fixes the issue for me as well. I was having the same problem with TypeError document.createRange is not a function preventing me from using userEvent.type from testing-library/react and the issue is the version of jest. I'm not sure why the test environment needs to be overridden, even without using tsdx and using jest directly, instead.