Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix: fix editor tests failing in jsdom environment

esenginef1ba15fbb806
diff --git a/editor/src/__tests__/PlayModeService.test.ts b/editor/src/__tests__/PlayModeService.test.ts
index 4cff2b523..d3ac507a5 100644
--- a/editor/src/__tests__/PlayModeService.test.ts
+++ b/editor/src/__tests__/PlayModeService.test.ts
@@ -57,6 +57,8 @@ vi.mock('esengine', () => ({
audioPlugin: { stopAllSources: vi.fn() },
getComponent: vi.fn(() => null),
getComponentAssetFields: vi.fn(() => []),
+ getAllAssetExtensions: vi.fn(() => new Set(['.png', '.jpg', '.esscene', '.json'])),
+ registerAssetBuildTransform: vi.fn(),
}));
vi.mock('../renderer/SharedRenderContext', () => ({
diff --git a/editor/src/__tests__/setup.ts b/editor/src/__tests__/setup.ts
index cae19c75f..4a7ceda42 100644
--- a/editor/src/__tests__/setup.ts
+++ b/editor/src/__tests__/setup.ts
@@ -1 +1,11 @@
// Vitest setup for editor tests
+
+// Fix TextEncoder cross-realm instanceof check in jsdom.
+// jsdom provides its own globals from a separate realm, so
+// Node's TextEncoder.encode() returns a Uint8Array that fails
+// `instanceof Uint8Array` against jsdom's Uint8Array.
+// esbuild-wasm checks this invariant at import time and throws.
+const OriginalEncode = TextEncoder.prototype.encode;
+TextEncoder.prototype.encode = function (input?: string): Uint8Array {
+ return new Uint8Array(OriginalEncode.call(this, input));
+};