vtk-js: Can't use @kitware/vtk.js with Jest
High-level description
@kitware/vtk.js seems to be built incorrectly, test frameworks such as Jest are unable to parse the package and throw an error.
I think the library should be compiled with ES5 as target (at least, for the module
entry point), this way better interoperability will be provided.
Steps to reproduce
- Download the sample project d8lhv.zip, or setup a Create React App and import any
@kitware/vtk.js
module from the package; - Add
"node_modules/(?!(@kitware)/)"
to thetransformIgnorePatterns
in package.json > jest - Create a test file and import
App.js
- Run
yarn test
Detailed behavior
Jest fails with the following error:
FAIL src/App.test.js
● Test suite failed to run
/Users/federicozivolo/Downloads/d8lhv/node_modules/@kitware/vtk.js/Common/Core/Math.js: Cannot use import statement outside a module
at interopRequire (node_modules/babel-plugin-macros/dist/index.js:86:15)
at applyMacros (node_modules/babel-plugin-macros/dist/index.js:208:17)
at ImportDeclaration (node_modules/babel-plugin-macros/dist/index.js:114:28)
Expected behavior
Jest should be able to import the library without erroring.
Environment
- vtk.js: 18.4.
- OS: macOS 11.4
- Browser: Node 12.20.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (8 by maintainers)
Yep, that would be the intended approach.
Ah yes, that would still be a problem. But fixing it would be as simple as providing an alias for
macro.js
that reexports frommacro.js
, right? Should work fine and be backwards compatible if a little messy…FYI I also opened an issue into the babel-plugin-macros repository to see if something can be done on their side.
https://github.com/kentcdodds/babel-plugin-macros/issues/178