-
-
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
Support package exports in jest-resolve
#9771
Comments
I chatted with @ljharb about this, and a future version of |
@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 EDIT: I also just stumbled over a WIP PR to |
@SimenB Great! I'll look into those. One question: in Browserify #222 you mentioned:
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/self-resolver.cjs It allows the use of normal |
Progress in resolve appears to be a bit slow. Would you consider using Webpack's enhanced-resolve in meantime? Seems like you can create a Node-compatible ESM resolver with: const enhancedResolve = require('enhanced-resolve');
const resolve = enhancedResolve.create( {
conditionNames: ['import', 'node', 'default'],
extensions: []
} ); |
You can plug in your own resolver in Jest, replacing the use of We're (highly) unlikely to migrate away from |
@overlookmotel I updated the link in my entry above (it was broken). It may help, if you wish to do a custom resolver, though it's purpose is different from a generic ES modules importer. |
@akauppi seems like your resolver doesn't support conditional exports. Or are they supported implicitly by |
@piranna It likely doesn't. I just needed ES module handling and the resolver is made with the one project in mind - not as a general fix. |
Fair enought. Not sure if give it a try and improve it, or wait until we have properly support... :-/ What I'm trying to achieve, is to test that a different file is provided for Node.js and for browser. I could do it with with |
Until this is implemented in |
Currently no. I was gonna wait until |
As mentioned, please open new issues with minimal reproductions. But yes, the way eslint has defined exports should work |
The workaround for gatsby-page-modules seems unneccessary after the issue jestjs/jest#9771 was closed.
because it fixes jestjs/jest#9771
with a fix for jestjs/jest#9771
with a fix for jestjs/jest#9771
With https://github.com/facebook/jest/releases/tag/v28.0.0-alpha.3 the implementation of Please test it! |
Upgrading to EDIT: Let me try with |
@SimenB |
there was an issue if your pattern was |
Ah, wonderful @rmolinamir! |
@SimenB I was wondering if in v27 or in v28 there is a way to call Edit: here is where I got stuck: perrin4869/react-router@8d47441#diff-d8a2cb7ecc9e1cf5168cefd084cb7b9ab315ba051f61b4799ad4e33c2baa1394R20 |
@perrin4869 not related to this issue. However, the answer is "no" - you cannot use "real" import from within Jest. I recommend setting up a separate script using plain node code (you can still use |
@SimenB Ah sorry, I was just getting notifications in this issue and suddenly I felt like revisiting! |
@perrin4869 Not sure if this helps, but you can use exports to bypass mocking. In our project, we conditionally export "mocked" versions of each packages for testing (rather creating manual mocks within the packages' clients, cause DRY). We then also export a direct path to classes if I ever wish to bypass those mocks. so any external code calling It's pretty specific, may not be applicable to your situation, but it sounds like you want something similar to the reasons we set this up. |
@FrozenKiwi Thanks! That's a convenient setup :) |
There's a lot of people subscribed to this issue, please keep discussion about things not related to the resolver implementation of |
with a fix for jestjs/jest#9771
with a fix for jestjs/jest#9771
with a fix for jestjs/jest#9771
see jestjs/jest#9771 using jest v28.0.0-alpha.3 "package exports" are how we export from `mono/model`
with a fix for jestjs/jest#9771
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
https://nodejs.org/docs/latest-v12.x/api/packages.html#packages_exports
Hopefully this can be offloaded to
resolve
. Tracked in browserify/resolve#222The text was updated successfully, but these errors were encountered: