gpujs / gpu.js

GPU Accelerated JavaScript
https://gpu.rocks
MIT License
15.1k stars 654 forks source link

Using Jest to test gives console error Not implemented: HTMLCanvasElement.prototype.getContext #624

Open Le5tes opened 4 years ago

Le5tes commented 4 years ago

What is wrong?

I am seeing the following console errors when unit testing my Kernals with Jest: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package) at module.exports (/codebuild/output/src595994766/src/github.com/Le5tes/gravity-simulator/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17) 102 | at HTMLCanvasElementImpl.getContext (/codebuild/output/src595994766/src/github.com/Le5tes/gravity-simulator/node_modules/jsdom/lib/jsdom/living/nodes/HTMLCanvasElement-impl.js:42:5) 103 | at HTMLCanvasElement.getContext (/codebuild/output/src595994766/src/github.com/Le5tes/gravity-simulator/node_modules/jsdom/lib/jsdom/living/generated/HTMLCanvasElement.js:102:58) 104 | at Function.setupFeatureChecks (/codebuild/output/src595994766/src/github.com/Le5tes/gravity-simulator/node_modules/gpu.js/src/backend/web-gl2/kernel.js:48:30) 105 | at Function.get isSupported [as isSupported] (/codebuild/output/src595994766/src/github.com/Le5tes/gravity-simulator/node_modules/gpu.js/src/backend/web-gl2/kernel.js:36:10) 106 | at GPU.chooseKernel (/codebuild/output/src595994766/src/github.com/Le5tes/gravity-simulator/node_modules/gpu.js/src/gpu.js:191:28) 107 | at new GPU (/codebuild/output/src595994766/src/github.com/Le5tes/gravity-simulator/node_modules/gpu.js/src/gpu.js:126:10)

Though the code is fine and my tests pass fine.

Where does it happen?

Running tests with Jest. Testing Kernals that do not use canvas.

How important is this (1-5)?

1 - doesn't actually affect me apart from unnecessary error message

Expected behavior (i.e. solution)

Since I am not requiring the canvas, this error message is not helpful to me. Perhaps this error could be caught and a warning shown instead that the environment doesn't include HTMLCanvasElement.

harshkhandeparkar commented 4 years ago

GPU.js either the HTML <canvas> or nodejs dependency headless-gl to use the GPU. If you are testing by emulation a browser DOM, there is a very high likelyhood that the canvas element is just a dummy and actually doesn't have the complete implementation.

You'll have to use a complete browser such as puppeteer to test your code.

Le5tes commented 4 years ago

But the tests work fine, really I'm just saying that the error message is unnecessary.