Skip to content

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

@perrin4869

Description

@perrin4869

🚀 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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions