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

[wip]: remove @types/jest everywhere #12415

Closed
wants to merge 5 commits into from

Conversation

mrazauskas
Copy link
Contributor

Summary

This is an experiment to see how easy (or hard) it could be to remove @types/jest from jest repo. Motivation is simple: own types of the repo are good enough (in some cases even better) than the ones from @types/jest.

Todo:

  • Figure out how to type Jest globals in test files (also the ones in examples directory).

Test plan

Green CI

@SimenB
Copy link
Member

SimenB commented Feb 17, 2022

Exciting!!

I played with this for 15 minutes last night without being able to make TS augment the global env. Hopefully you can figure out the correct incantation 😀

@mrazauskas
Copy link
Contributor Author

Found two possible solutions.

First was sort of workaround. It augmentation work. The whole idea was to emit a .d.ts file into node_modules/@types/jest directory as a final build step. This did not look elegant.

I though to try explicit imports. Why not? Went through all *.test.ts files and added import {expect, jest, ...} from '@jest/globals'; Exactly 300 files changed. That’s minimal change, so I hope review is doable if such migration is acceptable.

Unfortunately, few tests have jest.mock related error. That’s unexpected. Just pushed a single test file with that error. It shows up in CI as well. @SimenB does it look familiar? Hard to grasp what is going on (;

@mrazauskas
Copy link
Contributor Author

Hm.. Just a transpiler issue? If globals are imported, Babel playground is transpiling the problematic line const realFs = jest.requireActual('fs'); into const realFs = _globals.jest.requireActual('fs'); This could be the explanation.

@mrazauskas
Copy link
Contributor Author

Here is a minimal reproduction – https://github.com/mrazauskas/x-jest-globals. I simply added explicit import to this example – https://jestjs.io/docs/next/mock-functions#mocking-partials

Only wondering if this is a bug or expected behaviour?

@SimenB
Copy link
Member

SimenB commented Feb 18, 2022

It's supposed to change the import, it's not supposed to tag it in the babel plugin. 😅 Can you open up a bug report with it so we can track it separately?

@mrazauskas
Copy link
Contributor Author

Closing in favour of #12856

@mrazauskas mrazauskas closed this Jun 3, 2022
@github-actions
Copy link

github-actions bot commented Jul 4, 2022

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 Jul 4, 2022
@mrazauskas mrazauskas deleted the remove-types-jest branch October 3, 2022 13:48
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

3 participants