miniflare
miniflare copied to clipboard
Unexpected token 'export' when using `@aws-sdk` with Jest
I have created a new worker using npx wrangler init with typescript. I am using the @aws-sdk/client-eventbridge package in my worker. However, when I try and mock it in tests using aws-sdk-client-mock I get the following error.
.../node_modules/uuid/dist/esm-browser/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';
This appears to be an ES module issue and only occurs when I have new EventBridgeClient({}) in my test code.
My jest config looks like this.
module.exports = {
preset: 'ts-jest',
testEnvironment: 'miniflare',
};
If I change testEnvironment to node, the error no longer occurs and the test will pass. However, I loose the miniflare benefits in jest.
Is there something I'm missing here to get this working with the miniflare test environment?
Hey! 👋 Which version of jest and jest-environment-miniflare are you using? It's possible upgrading to jest@28 and [email protected] might fix this issue.
Hey. I'm on [email protected] and [email protected] and still seeing the above issue.
Interestingly I have been able to work around it by mocking the uuid library in tests like this.
jest.mock('uuid', () => 'eb7b7961-395d-4b4c-afc6-9ebcadaf0150');
Not ideal, but helps me out in my case. Though this would become an issue I guess if I wanted to directly use uuid in my worker without having to supply a mock.
same issue
same issue
same issue, has anyone found a solution?
Same issue
Same
https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149/
This solve my problem create a resolver. the uuid has a incompatibility with jest.
What is the solution for this issue ? i am on jest 29.0 and have the same issue.
@maxy4u as @andreMycroft mentioned, the resolver. He could be a little bit more specific I guess 😝 : https://github.com/microsoft/accessibility-insights-web/pull/5421/commits/9ad4e618019298d82732d49d00aafb846fb6bac7
@maxy4u as @andreMycroft mentioned, the resolver. He could be a little bit more specific I guess 😝 : microsoft/accessibility-insights-web@9ad4e61
Thank you @mkbctrl I will try this. :)