Skip to content
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

[Feature]: Allow regular node dynamic import calls from jest test files #12439

Closed
perrin4869 opened this issue Feb 20, 2022 · 4 comments
Closed

Comments

@perrin4869
Copy link

馃殌 Feature Proposal

Allow calls to import such that they aren't routed through jest's implementation. Maybe provide an unmocked alias such as unmockedImport("./mymodule.js").

Motivation

The motivation is to be able to have tests of the package.json exports field within libraries and prevent exports in node environments from breaking.
An example where this would be useful is in this PR which I abandoned momentarily due to this missing feature.

Example

No response

Pitch

Sorry for spamming on issue #9771
You suggested that one solution would be to have a separate, regular node script to achieve this kind of test, which is something that I had actually considered myself when I was putting together the PR, but I didn't pursue this approach for a number of reasons:

  1. Work on a new version of jest is underway and maybe this would be supported in the new version
  2. I couldn't come up with a way to invoke this test file other than calling exec("node ./mytest.js") from within the scripts file or modifying the package.json test script to read something like "test": "jest && node ./my-separate-test.js".
  3. It seems to me like an escape hatch should be available to be able to make regular import calls in case the jest implementation is not desirable.

Ultimately I was just wondering if this is a won't fix kind of feature, or something you are planning to add?
Thank you for all your hard work on this module!

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 22, 2022
@SimenB
Copy link
Member

SimenB commented Apr 12, 2022

@perrin4869 I'd use https://github.com/nicolo-ribaudo/jest-light-runner. You can use a separate project for just that one file if you want: https://jestjs.io/docs/configuration#projects-arraystring--projectconfig

I don't think Jest itself should support this

@SimenB SimenB closed this as completed Apr 12, 2022
@perrin4869
Copy link
Author

@SimenB Thanks! Yes, I noticed jest-light-runner too, it may be what I was looking for!
I personally never used jest on any project myself, but I ran into this issue when looking at issues in other repos such as: remix-run/react-router#8268, dherault/serverless-offline#1014 or cosmiconfig/cosmiconfig#251.
In the case of serverless-offline and cosmiconfig, the choice of jest as a testing framework ended up making it impossible to simply make a call to import without breaking the whole test suites.
jest-light-runner could be a solution if these modules don't use mocking in their test suites, didn't look into it, I may give it a go at a later time... but it is kinda frustrating that the test suite gets in the way in the way that it does...

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants