1. A concise explanation of the problem you're experiencing.
I cannot use CesiumJS with Jest
2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
Project Directory:
/home/vagrant/dev/sandbox
Import into unit test with:
import * as Cesium from 'cesium'
Error:
/home/vagrant/dev/sandbox/node_modules/cesium/Source/Cesium.js:1
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/vagrant/dev/sandbox/node_modules/cesium/Source/Cesium.js
require() of ES modules is not supported.
require() of /home/vagrant/dev/sandbox/node_modules/cesium/Source/Cesium.js from /home/vagrant/dev/sandbox/node_modules/cesium/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename Cesium.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/vagrant/dev/sandbox/node_modules/cesium/package.json.
If I remove the "type" attribute from cesium's package.json, it works as desired (from what I can tell)
An example project can be created with
tomo-cli:
tomo new app --use-react --with-cesium
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
Testing is good. Jest is good. Testing with Jest is good. That is to say, I believe that Jest has sufficient market share to be worthy of support.
4. The Cesium version you're using, your operating system and browser.
Cesium Version: 1.65.0
OS: Ubuntu (Xenial) Vagrant Box
Browser: N/A (Jest)