-
-
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
chore: replace @types/jest
with a new private @jest/test-globals
package
#13344
Conversation
I don't mind more private packages 🙂
That make sense, but the contents of the files should probably be identical. |
Super exciting stuff! I'll take a look tomorrow - currently on my way to a concert 🙂 |
Yes, I think this is the best idea so far. Have a nice evening (; |
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.
this is super exciting!
(came back from concert full of adrenaline, so... 😅 )
@@ -5,6 +5,8 @@ | |||
* LICENSE file in the root directory of this source tree. | |||
*/ | |||
|
|||
/// <reference lib="dom" /> |
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.
really? how? it's running in node env, so shouldn't need or use any DOM APIs
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.
This is odd one. Window
type does not work without "dom"
:
And it is used to type requestAnimationFrame
:
I added reference
to silence a lot of type errors, but will come back to this.
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.
ah, for rAF it makes sense 👍
/** | ||
* Wraps a class, function or object type with Jest mock type definitions. | ||
*/ | ||
export type Mocked<T extends object> = JestMocked<T>; |
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.
object
seems weakly typed, but that's not for this PR to figure out 😀
conflicts 😅 |
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.
super awesome! 👍
Nice! Now it would be good to run type checks for test files. I was trying out already. This will be fun ;D |
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
What if
@types/jest
would be replaced with a new private package@jest/test-globals
? Here is how I came to this:.d.ts
file with type declarations of Jest globals. For example, it could live in root of the repo. In the.d.ts
it is unavoidable to have something likeimport('@jest/globals')['beforeAll']
which would reference a package like@jest/globals
which might be not yet build. TypeScript will see these broken references and will not be happy..d.ts
file in some package and to use projectreferences
. This way TypeScript would build the referenced projects first. The problem is solved.@jest/type-utils
looked like a good candidate to be that package. I was adding"./globals": {"types": "./build/globals.d.ts"}
topackage.json
, but TypeScript was still not happy to see"types": ["@jest/test-utils/globals"]
intsconfig.josn
. Also everything looked clumsy.@jest/test-globals
package only for type declaration of Jest global APIs looked like a cleaner solution. (Indeed it is somewhat similar to feat(jest): allow enabling Jest global types through"types": ["jest"]
intsconfig.json
#12856.)It might sound unnecessary to have one more private package, but I think it is worth a discussion.
First the new package has very clear task – to provide type declarations of Jest's global test APIs for tests of Jest repo. Task is clear and simple as well as the usage of the package:
"types": ["@jest/test-globals"]
. (Also replacing of@types/jest
package with another package is sort of logic.)One more detail to keep in mind. DefinitelyTyped/DefinitelyTyped#62037 is not a solution for Jest repo, because in that case
@types/jest
will includeimport('@jest/globals')
, i.e. it will again reference packages which are not yet build. So having a private package which is replacing@types/jest
makes even more sense.One detail is left to think about:
@types/jest
. Since there is no future for@types/jest
in this repo, I will that to use imports from@jest/globals
Test plan
Green CI.