I want to unit-test Code that creates a Pixi-JS application with Vitest, however I get a "Worker not defined"-Error.
Other code stripped away, this is what I tried (in a vite-project):
/**
* @vitest-environment jsdom
*/
import { Application } from '@pixi/node';
import { describe, it } from 'vitest';
describe('Render', function() {
it('should be able to create a Render instance', async function() {
new Application();
});
});
Running npm run test gave me that the test failed:
FAIL test/render/Render.test.ts [ test/render/Render.test.ts ]
ReferenceError: Worker is not defined
❯ node_modules/@pixi/assets/lib/_virtual/checkImageBitmap.worker.mjs:20:30
❯ test/render/Render.test.ts:1:31
1| /**
2| * @vitest-environment jsdom
| ^
3| */
4|
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed (1)
Tests no tests
Start at 20:18:55
Duration 0ms