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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(jest): use @jest/globals
package
#44365
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
Hmm, I'm not gonna be fixing tests here before we've discussed this properly. I was hoping the bot would ping all the maintainers, but it seems it has changed behavior since I was last in this repo 馃槄 @orta @alloy thoughts on how to best explore this further? I can open up an issue either here or in fb/jest of course. |
Changing this PR to a draft, and the bot will be quiet 馃憤 |
... oops, so ping @NoHomey @jwbay @asvetliakov @alexjoverm @epicallan @ikatyang @wsmd @JamieMason @douglasduteil @ahnpnl @JoshuaKGoldberg @UselessPickles @r3nya @Hotell @sebald @andys8 @antoinebrault @favna @gstamac @ExE-Boss @quassnoi @Belco90 @tonyhallett @ycmjason @devanshj @pawfa @regevbr Conceptually, I love this idea 馃憤 it's a solid path forwards. There are probably a few For me, the tricky bit on a transition like this is that it's trivial for DT to have massive amounts of JSDoc info on anything exposed to the user. This is done in a way that's not intrusive to working on Jest itself, whereas I think working in a codebase with that much documentation might be more annoying for devs. Re: Contributors, good q - I'd like to hope anyone experienced enough to contribute here would contribute on facebook/jest - given that most of the types live in one spot it should be pretty reasonable for folks to make changes |
Thanks Orta!
Right, good point. I guess we could re-export more granularly and keep the examples here somehow?
Yeah, hopefully. It's somewhat spread out as matchers, matcher utils, diffing options etc are in separate packages, even if the globals themselves are fairly co-located. I'm happy to make structural changes to ease contributions of course. I've already moved some types that are generally useful into |
Personally I know some work was required on jest-environment-puppeteer (#44033) so I'm concerned about that with this change. If you could verify it (taking the comments of the linked PR into account) that would be great. |
It聽might be聽better to聽do: import { ... } from "@jest/globals";
declare global {
export { ... }; // Or whatever the syntax for doing this is.
}; |
Looking at the test results, it seems first order of business is to figure out how to add custom matchers |
@orta do you have any suggested syntax for adding custom matchers? Using interface merging, or something else? I know next to nothing about how that works, tbh |
Interface merging is the right option IMO - so if you make sure the returned value of declare namespace jest {
interface Matchers {
toBeCalled(): void
}
export const expect: Matchers
} Then anyone else can extend it by declare namespace jest {
interface Matchers {
toHaveSVGSnapshot(): void
}
} in their own d.ts files |
No problem with this as long as 1. and 3. are addressed.
@orta @SimenB
With the types that I added there is a helper for interface merging and an alternative that I mentioned in #9810.
Perhaps expect code could change to return itself and there would be no need for the cast ?
Only drawback of both of these
So if your matcher does not need TActual then there is no need for declaration merging if you are writing your own matchers for immediate usage. If you are writing a matchers library and do not need TActual you can use type mapping and there is no need to manually type / build generate and there is safety in the asymmetric matchers. @SimenB Finally. Whilst checking the type changes that I introduced I noticed that there is an error in one of my type names. It is CustomAsyncMatchers when it should be CustomAsymmetricMatchers ( discussed in 2. ) I have changed this in my local branch as well as refactoring to expose the type CustomJestMatchers ( also discussed in 2.). |
98e6cd0
to
07cc99e
Compare
Latest in this space, for anyone following along: jestjs/jest#12424 |
07cc99e
to
9336e7d
Compare
npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present).If changing an existing definition:
@jest/globals
package for importing globals explicitly聽jestjs/jest#9801tslint.json
containing{ "extends": "dtslint/dt.json" }
. If for reason the any rule need to be disabled, disable it for that line using// tslint:disable-next-line [ruleName]
and not for whole package so that the need for disabling can be reviewed.Hey all! 馃憢 Jest maintainer here 馃檪
In
jest@25.5
we've introduced a new package -@jest/globals
. This package was added for people who don't want to use globals in their code (I realize now the name could be better...), but I think it could also be used by DT to expose the types on the global environment.This PR is of course not meant to be merged as is, but I personally want this to be the end goal for
@types/jest
- sticking Jest's types on the global namespace, but doing essentially nothing else. I think it's an improvement to have the types come from the project itself. Jest is written in TypeScript, so we should be in a good position to ship good typings.Now, there are a few things broken by this
jest.DoneCallback
, Serializer types, etc.) are no longer easily accessible - we should restore that functionality. But they should fetch those types from Jest's packages, not define them herejasmine
types are gone (those should stay here in DT - I have no interest in exposing more of the Jasmine stuff from Jest. It's just late at night, so I'm too tired to revert those changes 馃槄)/cc @orta