How to do headless specs with the BABYLON JS NullEngine
[Everyday code]
In buildin3d.com we are using BABYLON JS. To develop a headless specs for BABYLON JS that could run in a Node.js environment or without the need of an actual canvas we can use BABYLON.NullEngine. A spec could then look like
const engine = new BABYLON.NullEngine();
this.scene = new BABYLON.Scene(engine);
Here is what I found out.
Headless specs
We run a lot of specs for our BABYLON JS logic. All of this specs are against preview.babylonjs.com. The preview version of babylon give us access to the latest most recent changes of babylon that are mode available to the public. These are still not release changes, but are the work of progress of the framework. They are quite stable so I guess at least the internal suite of BABYLON has passed. Preview is much like a nightly build. In BABYLON JS case it is also quite stable.
2 days ago much of our specs failed. I reported at https://forum.babylonjs.com/t/failure-error-typeerror-cannot-read-property-trackubosinframe-of-undefined/16087. There were a lot of errors for :
Cannot read property 'trackUbosInFrame' of undefined.
Turns out that many of our specs were using BABYLON.Engine to construct the scene like
const engine = new BABYLON.Engine();
this.scene = new BABYLON.Scene(engine);
The BABYLON.Engine class is only intended for the cases where we have a canvas. What we should have been doing for headless specs without a canvas is to use BABYLON.NullEngine. Hope you find it helpful.
Write more specs.
Reply
You must be logged in to post a comment.