rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[heft]: The `mocked` helper from `@types/heft-jest` might be unnecessary

Open mrazauskas opened this issue 2 years ago • 5 comments

Summary

If I get it right, the purpose of @types/heft-jest is to provide mocked() helper. Seems like code was copied from ts-jest.

The fact is that it was moved to jest (from v28) and removed from ts-jest completely. Now this is jest.mocked().

Perhaps it is time to deprecate @types/heft-jest package? And to tweak Heft documentation as well?

Details

I am not a user of Heft, but I have put some effort to rework jest.mocked() and to add jest.Mocked<T> recently. So I am interested to inform Jest user about these improved/new APIs. Could not figure out which version of Jest ships with Heft. These are the links to Jest v29 (latest):

jest.Mocked<T>: https://jestjs.io/docs/mock-function-api/#jestmockedsource

jest.mocked(): https://jestjs.io/docs/mock-function-api/#jestmockedsource-options

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@rushstack/heft version? latest
Operating system? n/a
Would you consider contributing a PR? Yes
Node.js version (node -v)? 18

mrazauskas avatar Aug 31 '22 10:08 mrazauskas

@octogonz - you originally put this together. Thoughts?

iclanton avatar Aug 31 '22 18:08 iclanton

We don't support Jest 28 yet, but we should soon.

iclanton avatar Aug 31 '22 18:08 iclanton

@octogonz - you originally put this together. Thoughts?

HBO was using this API. @elliot-nelson can you comment on the impact of removing it? How much work would be required to fix up your tests?

octogonz avatar Sep 01 '22 04:09 octogonz

We don't support Jest 28 yet, but we should soon.

I see. So my idea might be premature.

Just to add more detail. Jest v27.4 shipped with jest.mocked() helper added. Jest v29 has reworked jest.mocked() and jest.Mocked* utility types added. These all are Jest's built-in APIs, not through @types/jest or ts-jest.

mrazauskas avatar Sep 01 '22 05:09 mrazauskas

@octogonz I believe we are on Jest 27.0, and we are using the mocked() global construct and not jest.mocked().

But if the work is "switch to jest.mocked() the next time you do a Heft upgrade that moves from Jest 27 to Jest 28", it sounds totally fine to me -- especially if it lets us drop an extra package. (Not sure if you're saying that's all @types/heft-jest is doing or not.)

elliot-nelson avatar Sep 01 '22 13:09 elliot-nelson