fix(test): fix unit tests after 3d-tiles-renderer update #2376
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposition that fixes unit tests on the
3d-tiles-migration
branch after3d-tiles-renderer
update to0.3.36
. I'm not satisfied with the proposed solution but it works and I think it can be sufficient for this work on 3D Tiles migration I think finding a better solution should be treated seperatly in the future. Let me know if you agree with that (in which case I will open an issue dedicated to this matter).Some notes on the implementation and possible improvements:
Unit tests were not running anymore after
3d-tiles-renderer
update to0.3.36
because of a newly added WebGLRenderer import, requiring a gl context which is not available in unit tests they are run in a node environment and not in a browser. The encountered error:Currently, we mock everything that's not available and needed for unit tests in bootstrap.js. To mock the webgl context, we can either mock it ourselves (but that can be complicated) or rely on an external library. Possible libraries are webgl-mock or headless-gl.
webgl-mock
is not maintained anymore (last version released 6 years ago).headless-gl
last activity is more recent but is still not that very active. Both libraries only support webgl 1.0 and there is no official roadmap on supporting WebGL 2.0 (although we would not be the only one to need it 😀 ). This is a major problem since threejs and itowns dropped WebGL 1.0 support.In this PR I went for the "quick way" and used
webgl-mock
(only because I found out aboutheadless-gl
afterwards) and I added the following:WebGLRenderingContext.getParameter
to returnWebGL 2
for this to work. Note that this is a shortcut and it should return a different value depending on theparamater
argument to get (e.g. those two ones that are used forWebGLRenderer
initialization).WebGLRenderer
to get initialized:texImage3D
A better solution would probably be to use
headless-gl
and wait for WebGL 2.0 support (or implement it). We could also use puppeteer (but that's kind of weird to use puppeteer in unit tests). Note that maplibre also struggled with this issue and that they dropped webgl 2.0 unit tests for now (which is not really an option for us here) and that deckgl did the same.