-
-
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
feat(runtime): add jest.mockModule #10976
base: main
Are you sure you want to change the base?
Conversation
@SimenB as you said in #9430 (comment) this is needed to implement the |
This is not related to |
b4f1300
to
eac6673
Compare
Codecov Report
@@ Coverage Diff @@
## master #10976 +/- ##
==========================================
- Coverage 64.28% 64.17% -0.11%
==========================================
Files 308 308
Lines 13480 13512 +32
Branches 3286 3291 +5
==========================================
+ Hits 8665 8671 +6
- Misses 4106 4134 +28
+ Partials 709 707 -2
Continue to review full report at Codecov.
|
what's the state of this? |
I currently don't have the motivation to work on this feature, so it's in hiatus until I get back to it. Others are of course free to pick it up (missing stuff is mostly laid out in the OP from what I remember) 🙂 I can rebase this, tho |
Codecov Report
@@ Coverage Diff @@
## master #10976 +/- ##
==========================================
- Coverage 68.93% 68.92% -0.02%
==========================================
Files 312 312
Lines 16398 16401 +3
Branches 4749 4750 +1
==========================================
Hits 11304 11304
- Misses 5067 5070 +3
Partials 27 27
Continue to review full report at Codecov.
|
@SimenB, is there a natural point to split up this PR / what remains? For example, if I can take a look at helping with some of this tomorrow. A rebase, if it'd be quick for you, would be appreciated (assuming there might be conflicts to be resolved that I wouldn't have the context for). |
@connorjclark awesome if you wanna pick this up! I just rebased it. Not sure where the best point to pick something up would be. I assume e.g. |
Some of the items from above look required to merge this, but I wonder if some might be able to be moved to follow-ups? E.g. this could provide a lot of value without manual mocks support |
Sure, pretty much every point could be moved to a follow-up except possibly docs... Although one could argue docs can wait until the feature is more stabilized. I could add this as |
Checking it in as |
@benmccann landed that now, will release tonight or tomorrow (cest) |
Thank you so much! |
@SimenB time to update https://jestjs.io/docs/ecmascript-modules , it still says "Please note that we currently don't support jest.mock in a clean way in ESM, but that is something we intend to add proper support for in the future. Follow this issue for updates." |
@n0mer if you're up for a quick PR adding a small note that'd be awesome 👍 Can link to #9430 (comment) or something for the caveats |
Are there any plans to continue this work in the near term? @SimenB |
All work on ESM is paused until most issues linked in nodejs/node#37648 are solved. (I got a message from a developer at Google last week about movement, so hopefully that'll actually move along very soon) |
That said, happy to take PRs of course. But any personal effort is on pause until node's APIs are closer to stabilization. |
The downside to a) For the past 26 years I've written in pure javascript for use in a browser environment (hence why I'm using ESM) At the very least it looks like the From this I would guess that within the same file, the I guess if anybody was to take a crack at |
This comment was marked as off-topic.
This comment was marked as off-topic.
This PR is stale because it has been open 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This PR updates `execa` to `^8.0.1`. Since `execa@>=6.0.0` is ESM-only and `jest` only has experimental ESM support (jestjs/jest#10976), this required switching from `ts-jest` to `babel-jest`. To minimize dependency transpilation, the ESM packages that are necessary to transpile are enumerated in `jest.config.js`. This version of `execa` includes [automatic escaping of shell arguments](https://github.com/sindresorhus/execa/tree/v8.0.1#execafile-arguments-options), which was the entire point of #112, #113, and this PR. The state of ESM support in the Node.js ecosystem is absolutely horrible, and I would not recommend further migrations for the time being. We should continue to dual-release our packages and avoid ESM-only dependencies until the ecosystem has matured. For details see the above `jest` issue and nodejs/node#37648.
Summary
A start on #10025. Lots of stuff missing
__mocks__
directories)mock
anddoMock
on an ES Module, andmockImport
on CJS. I think it should throw?jest.importActual
Test plan
I'll add more tests as we go