Essentially, what I'm asking is, is there a way to write unit tests for my JavaScript files for three.js library?
I have a 3D viewer that houses a camera, renderer, loader, etc... How do I write tests for something like that? Is there something out there that I can read for that? Is it even possible?
JavaScript Unit Testing is a method where JavaScript test code is written for a web page or web application module. It is then combined with HTML as an inline event handler and executed in the browser to test if all functionalities are working as desired. These unit tests are then organized in the test suite.
A typical unit test contains 3 phases: First, it initializes a small piece of an application it wants to test (also known as the system under test, or SUT), then it applies some stimulus to the system under test (usually by calling a method on it), and finally, it observes the resulting behavior.
The idea is to develop a unit test by following these 3 simple steps: Arrange – setup the testing objects and prepare the prerequisites for your test. Act – perform the actual work of the test. Assert – verify the result.
A better way to achieve z-order would be to hack the engine and set the drawing order for each element in order to force one element to be drawn before another. Also another problem with using three. js is that (at the time of writing) it doesn't handle 2D sprites very well.
I found a way to unit test webgl/threejs in headless way. This does not need any image comparison etc.
https://github.com/AmitTeli/webgl-three-test
Approach taken:
yarn start
)yarn test
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With