# Core/Credit missing ThirdParty/purify in Jest

**URL:** <https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041>\
**Category:** CesiumJS\
**Created:** [February 26, 2019, 7:40pm UTC](https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041 "2019-02-26T19:40:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Behling](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@Brian\_Behling](https://community.cesium.com/u/Brian_Behling)\
**Post date:** [February 26, 2019, 7:40pm UTC](https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041/1 "2019-02-26T19:40:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [February 28, 2019, 12:55pm UTC](https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041/2 "2019-02-28T12:55:18Z")

</div>

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:

> **[cesium](https://www.npmjs.com/package/cesium)**
>
> CesiumJS is a JavaScript library for creating 3D globes and 2D maps in a web browser without a plugin.

---

<div class="post-metadata">

**Author:** ![Brian\_Behling](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@Brian\_Behling](https://community.cesium.com/u/Brian_Behling)\
**Post date:** [February 28, 2019, 5:01pm UTC](https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041/3 "2019-02-28T17:01:19Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Brian\_Behling](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@Brian\_Behling](https://community.cesium.com/u/Brian_Behling)\
**Post date:** [February 28, 2019, 5:04pm UTC](https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041/4 "2019-02-28T17:04:53Z")

</div>

Turns out we are already using the npm package.

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [March 4, 2019, 2:30pm UTC](https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041/5 "2019-03-04T14:30:08Z")

</div>

That’s odd. I do know we have projects that rely on importing Cesium as an npm package. For example, [gltf-pipeline](https://github.com/AnalyticalGraphicsInc/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](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/blob/master/lib/processGltf.js#L2)

Does that kind of import work for you?

---

<div class="post-metadata">

**Author:** ![Brian\_Behling](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@Brian\_Behling](https://community.cesium.com/u/Brian_Behling)\
**Post date:** [March 4, 2019, 6:21pm UTC](https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041/6 "2019-03-04T18:21:14Z")

</div>

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’);

…

---

<div class="post-metadata">

**Author:** ![jhwohlgemuth](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jhwohlgemuth](https://community.cesium.com/u/jhwohlgemuth)\
**Post date:** [September 1, 2019, 2:19am UTC](https://community.cesium.com/t/core-credit-missing-thirdparty-purify-in-jest/8041/7 "2019-09-01T02:19:53Z")

</div>

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](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](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](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](https://github.com/msrose/babel-plugin-transform-amd-to-commonjs), but when I do, I cannot get the module resolution for Cesium to work (see [webpack.config.js](https://github.com/jhwohlgemuth/cesium-h3-demo/blob/master/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
