Core/Credit missing ThirdParty/purify in Jest

Hello.

I’m trying to load Cesium into Jest test framework. In my test, when I try

import Ellipsoid from ‘cesium/Core/Ellipsoid’

this error is thrown “Core/Credit missing ThirdParty/purify”.

My guess is I have to include the purify someone into Jest, but not sure how.

Any ideas?

How did you install Cesium in this framework? If you manually placed the folder in there, you might just be missing the Source/ThirdParty folder, which is where I can see the purify.js file is.

Otherwise, there is a Cesium npm package that might make it easier to set it up here:

To load Cesium into jest, I’ve tried using the moduleNameMapper property. Jests loads modules similar to webpack, but there are some differences.

https://jestjs.io/docs/en/webpack

So I referenced the cesium node_modules directory.

Next what I tried using babel to transpile the Cesium modules from AMD to CommonJS. This got me far enough to import cesium modules using import statements, However, when I run methods I get errors such as:

TypeError: _Cartesian.default.fromDegreesArray is not a function

or

TypeError: _PolygonHierarchy.default is not a constructor

I’ll give the npm package a try.

Turns out we are already using the npm package.

That’s odd. I do know we have projects that rely on importing Cesium as an npm package. For example, gltf-pipeline is both a library and a commandline tool that includes it this way:

https://github.com/AnalyticalGraphicsInc/gltf-pipeline/blob/master/lib/processGltf.js#L2

Does that kind of import work for you?

The code we are testing uses es6 import statements, we won’t be able to modify our code around the tests.

I did try using require as an import statement, but got errors “define is not defined”. That error happens because Jest doesn’t support requirejs or AMD modules.

Transpiling the cesum modules to commonjs using babel results in the TypeError errors.

The modules will look like this after the transpiling

module.exports = function () {

var Cartesian2 = require(’./Cartesian2’);

var Cartographic = require(’./Cartographic’);

var Check = require(’./Check’);

Good evening fellow CesiumJS users!

I apologize for jumping into this conversation, but I too am trying to get CesiumJS to work with Jest (with no success…).

Here is the repo: https://github.com/jhwohlgemuth/cesium-h3-demo

The file I am trying to load into a test: https://github.com/jhwohlgemuth/cesium-h3-demo/blob/master/src/components/Body.js

The test being run by Jest: https://github.com/jhwohlgemuth/cesium-h3-demo/blob/master/tests/example.test.js

(the test currently has a jest.mock to side step the issues with Cesium…)

When I remove the Jest mock, I get

}(requirejsVars.require, requirejsVars.requirejs, requirejsVars.define));
^

ReferenceError: requirejsVars is not defined

  at exec (node_modules/requirejs/bin/r.js:62:23)
  at setBaseUrl (node_modules/requirejs/bin/r.js:30248:13)
  at node_modules/requirejs/bin/r.js:30338:9
  at Object.<anonymous> (node_modules/requirejs/bin/r.js:30427:2)
  at Object.<anonymous> (node_modules/cesium/index.js:13:17)

``

I have tried using babel-plugin-transform-amd-commonjs, but when I do, I cannot get the module resolution for Cesium to work (see webpack.config.js)

I understand that my use of Webpack and Resium make my issue more complicated, but I am fairly certain that the resolution to my issue will be relevant to Brian’s.

If I am way off base here, I will apologetically move my query to a separate thread.

Any help would be appreciated. Thank you for your time.

Sincerely,

Jason