Open jeffbski-rga opened 1 month ago
Seeing a "might-be-related" issue: seems core jest functions are being "stomped" on by these, when webpacked. Result is jest module mocks (non-SDK) aren't working, with "moduleName.mockImplementation..." resulting in a ts-loader error: "Property 'mockImplementation' does not exist on type 'xyz'.". Seems similar to Similar to https://github.com/m-radzikowski/aws-sdk-client-mock/issues/180?
The places where I do non-SDK jest mocking are referencing ./node_modules/aws-sdk-client-mock-jest/dist/types/jest.d.ts instead of ./node_modules/@types/jest/index.d.ts. Going back to 4.0.2 fixes it.
Checklist
Bug description
My jest tests were fine with aws-sdk-client-mock-jest@4.0.2 but as soon as I upgrade to 4.1.0 I am getting
Details:
I am running in Node.js 20.17.0 and for jest I run it with
NODE_OPTIONS=--experimental-vm-modules jest
so I can use es modules.Problem is resolved if package.json exports is removed
I was able to diff the aws-sdk-client-mock-jest package.json of 4.0.2 and 4.1.0 and found that the newer package.json includes an exports property. It appears that the inclusion of this is not playing well with jest causing the above error. If I manually remove the exports property from your package.json in node_modules/aws-sdk-client-mock-json then things once again work fine. So there must be some incompatibility with jest and the exports property.
Apparently the exports property was added to support the vitest feature.
Reproduction
Gist with all necessary code to reproduce the problem https://gist.github.com/jeffbski-rga/97f15fbffb23aa7f91484da49aa7d21d
package.json
index.test.mjs
Reproduce in Node.js 20.17.0 by running
npm t
Simply attempting to import the module will cause the error.
Environment
Solution
Removing the exports property from the aws-sdk-client-mock-jest package.json fixes the problem.
The exports in 4.1.0 package.json (remove this to fix, but it may affect vitest feature since it was added for that)
4.0.2 did not have exports and it works properly.