Jest: Support package exports in `jest-resolve`

Created on 5 Apr 2020  路  6Comments  路  Source: facebook/jest

ES Modules Help Wanted

Most helpful comment

I chatted with @ljharb about this, and a future version of resolve _will_ support this. So we don't have to implement anything here. Will just hook it up when resolve is released with support for it 馃帀

All 6 comments

I chatted with @ljharb about this, and a future version of resolve _will_ support this. So we don't have to implement anything here. Will just hook it up when resolve is released with support for it 馃帀

@SimenB - in the meantime do you think its possible to mock these modules somehow? like uuid, luxon etc My attempts have not worked but i am not super versed in jest mocks. Would be ideal to have some kind of stub to use in the meantime rather than changing core code all over. To be clearer - not mock but reexport in a format suitable for Jest.

As a small update here, Jest 26.4.0 includes #10393 which allows you to specify resolve's packageFilter option, which _should_ allow people to put together custom resolvers and pluck exports out of the package.json. While it's not the native, seamless integration we wanna use, it might possibly unblock people.

EDIT: I also just stumbled over a WIP PR to resolve, so 馃 we can use that soon: https://github.com/browserify/resolve/pull/224

@SimenB Great! I'll look into those.

One question: in Browserify #222 you mentioned:

I'm currently working on support for ESM natively in Jest, ... (Apr 2020)

Since I'm building code exclusively with native ESM, interested in what's the status with that resolver.

Status of the resolver is in that issue. Status of ESM in general is #9430

Made a work-around that someone might find useful: https://github.com/akauppi/firebase-jest-testing/blob/master/sample/hack-jest/custom-resolver.cjs

It allows the use of normal import statements, and fetches the mapping from the same library's package.json. "Good enough for now" for me - allows testing that export is likely usable.

Was this page helpful?
0 / 5 - 0 ratings