Issues with running loaders in test cases with assets on disk

Hey Everyone! I’ve been trying to build test cases for my Three.js application. I have a lot of features that manipulate custom models and textures. To test those features, I’ve been trying to use the loaders to get assets into test cases. I’ve been running into a lot of issues getting these loaders to work in the test cases. I’ve started working out of this repository to isolate these issues: GitHub - CraigKnoblauch/gltf-loader-with-vitest

I’ve run into issues including:

  • The GLTFLoader gives an invalid URL error with the path of file that does exist.
  • The TextureLoader returns a Texture object with the path of a file that does not exist.

I’ve been working with vitest and jsdom. Has anyone been able to run test cases with these loaders and could help out?

Thanks everyone!
Craig

I think three.js loaders are generally expecting a URL, not a path on disk, and fetch() in Node.js does not read from disk. There will be other references to Web APIs in the loaders, but probably jsdom can polyfill most of those.

One option would be to load the GLB from disk first, with Node.js fs/promises API, get the ArrayBuffer, and pass that into GLTFLoader#parse?

I’m not sure what TextureLoader is going to do here, though. A custom handler returning some dummy texture might be the simplest path.