pkgs icon indicating copy to clipboard operation
pkgs copied to clipboard

`jest.mock` is not hoisted when using `@jest/globals`

Open jfirebaugh opened this issue 1 month ago • 0 comments

Previous issues:

  • https://github.com/swc-project/jest/issues/14
  • https://github.com/swc-project/jest/issues/120
  • https://github.com/swc-project/jest/issues/172
  • https://github.com/swc-project/plugins/issues/310
  • https://github.com/magic-akari/swc_mut_cjs_exports/issues/117

Could you please clarify:

  • What exactly does https://github.com/swc-project/swc/pull/8994 do? https://github.com/swc-project/plugins/issues/310 was closed as "completed", but in the PR @kdy1 wrote "However, the linked issue is wrong because the code tries to break the rule of ESM specification. So although this PR closes the issue, the final form is not the issue author wanted.". And apparently the issue isn't fixed. So what was the purpose of the PR and what does it do?
  • In https://github.com/swc-project/jest/issues/120 @kdy1 implies this issue will never be fixed and links to https://github.com/swc-project/swc/issues/7435 / https://github.com/swc-project/swc/issues/5205. But I don't understand the connection. Specifically, why does hoisting of jest.mock work fine with ESM imports if you don't use @jest/globals, but is supposedly unfixable due to ESM semantics when you do use @jest/globals?
  • Hoisting of vi.mock works fine with ESM. Why can't it work with jest.mock?

jfirebaugh avatar Nov 17 '25 19:11 jfirebaugh