bpmn-io / bpmn-js

A BPMN 2.0 rendering toolkit and web modeler.
https://bpmn.io/toolkit/bpmn-js/
Other
8.63k stars 1.33k forks source link

Not able to run test cases in react + vite #2112

Open nikhilguptagl opened 8 months ago

nikhilguptagl commented 8 months ago

While running test cases, I am getting below errors -

src/shared/components/BpmnEditor/tests/BpmnEditor.test.tsx [ src/shared/components/BpmnEditor/tests/BpmnEditor.test.tsx ] SyntaxError: Unexpected token 'export' ❯ Object.compileFunction node:vm:352:18 ❯ Object. node_modules/bpmn-js-properties-panel/lib/cmd/UpdateBusinessObjectHandler.js:4:10

Module D:/Repository/Hitachi/content-hub-ui/Frontend/author/node_modules/bpmn-js/lib/util/ModelUtil.js:9 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "bpmn-js" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
  test: {
    server: {
      deps: {
        inline: [
          "bpmn-js"
        ]
      }
    }
  }
}

However, I am also adding bpmn-js in vite.config but still it throws the same error. Is there anything I can do to run my test cases sucessfully or the team needs to add "type": "module" in their package.json ?

nikku commented 8 months ago

Is there anything I can do to run my test cases sucessfully or the team needs to add "type": "module" in their package.json ?

The team (we) need to convert this library to ESM in order to fix this issue.

nikku commented 8 months ago

Even with this issue addressed you'd likely still run into issues testing bpmn-js in node. Consider to mock it or apply browser-based testing (including bundling).