UrlTemplateImageryProvider broken after upgrade from 1.91 to 1.92

Upgrading from CesiumJS 1.91 to 1.92+ causes jest tests to be unable to invoke the UrlTemplateImageryProvider constructor, the returned object is empty (all default values) when on 1.91 and lower it was populated.

Running in debugger we can see there is a stack trace error now

Which then gives
Error: STACKTRACE TRACKING at getStacktraceWithUncaughtError (__project-path__\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:3573:16)

However other constructors such as new Cesium.Resource(options) works perfectly fine, so I believe this is just something wrong with UrlTemplateImageryProvider.

We are using Angular 13, typescript 4.4.3, cesium 1.92 (error actually found at v1.101.0 then we rolled back).

You can see here the resource attribute has been set to undefined which is definitely not the case.

Thanks for any help :slight_smile:

Edit: I missed an error message that I can get through the debugger - this does not cause an app crash but the object remains unpopulated.

TypeError: Cannot read properties of undefined (reading 'length') at Object.get (__project-path__\node_modules\cesium\Build\CesiumUnminified\index.cjs:26966:30) at Object.<anonymous> (<anonymous>:1:26)

Interesting.

I can use UrlTemplateImageryProvider as expected from with Sandcastle, which makes me think this has to do with the build, TypeScipt definitions, or the app build configuration.

Do you have anymore information about how you import CesiumJS into your app (ie. is it the module downloaded from npm? from the website? What’s your build config look like?).

We import cesium from npm - currently v1.91 (1.92 and above is when it starts to break), and then have declare var Cesium in project level typing files to be able to access the cesium object.

Unfortunately this error only seems to happen inside of the jest test environment, I’m working on a stackblitz to demonstrate this. Running the angular app normally it all works, its just the jest environment.

Is there any jest/testing related changes in 1.92 that we need to be aware of? There were imageryprovider changes stated in the changelog.

Hi there,

The biggest change was that we moved from when.js to native Promises which caused some breaking changes. Maybe you are not properly awaiting the readyPromise before accessing values?

Thanks Gabby, that was it - we weren’t treating them as promises so not awaiting them. Thanks so much!

I’d recommend updating the documentation for UrlTemplateImageryProvider that it will need to be awaited as it’s nowhere in the documentation → UrlTemplateImageryProvider - Cesium Documentation

1 Like

Thanks @arye97, we agree this is non-obvious and we’re actually in the middle of a refactor to remove the readyPromise pattern as it can be confusing and their use can cause some tricky race conditions.