我想使用 Vitest 对创建 Pixi-JS 应用程序的代码进行单元测试,但是我收到“Worker not Defined”错误。
其他代码被剥离,这是我尝试过的(在 vite 项目中):
/**
* @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();
});
});
运行
npm run test
让我测试失败:
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
通过不使用 pixi.js 版本 7.4.0 而是使用 8.0.1 来解决