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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
test(asset): the basis suites ask the shared helper, and await the transcoder
esengineae1566e24984
diff --git a/sdk/tests/asset-refcounter-integration.test.ts b/sdk/tests/asset-refcounter-integration.test.tsindex 352685cfb..6de84bc09 100644--- a/sdk/tests/asset-refcounter-integration.test.ts+++ b/sdk/tests/asset-refcounter-integration.test.ts@@ -60,6 +60,8 @@ function emptyResult(): SceneAssetResult {releaseCallbacks: [],scope: new AssetScope(),missing: [],+ timings: {},+ wallMs: 0,};}diff --git a/sdk/tests/basis-mip-chain-wasm.test.ts b/sdk/tests/basis-mip-chain-wasm.test.tsindex dbfa68692..a89dd8c45 100644--- a/sdk/tests/basis-mip-chain-wasm.test.ts+++ b/sdk/tests/basis-mip-chain-wasm.test.ts@@ -5,31 +5,24 @@** The cook's encoder writes a mip chain into every texture. This encodes with* that encoder and transcodes with the built side module, so neither half is a- * stand-in. Requires build/wasm/web/basis.wasm.+ * stand-in.*/import { describe, it, expect, beforeAll } from 'vitest';-import { existsSync, readFileSync, writeFileSync, mkdtempSync } from 'node:fs';-import { tmpdir } from 'node:os';-import { createRequire } from 'node:module';import path from 'node:path';import { transcoderFromModule, type BasisWasmModule } from '../src/asset/basisTranscoder';+import { hasSideModule, loadSideModule } from './helpers/loadWasm';import { CompressedTextureFormat, type BasisTranscoder } from '../src/asset/compressed';import { readKtx2Layout, halveRgba, spliceMipChain } from '../../pipeline/src/assets/ktx2Mips';const ROOT = path.resolve(__dirname, '../..');-const MODULE = path.join(ROOT, 'build/wasm/web/basis.js');const SIDE = 64;-describe.skipIf(!existsSync(MODULE))('a KTX2 mip chain through the built transcoder', () => {+describe.skipIf(!hasSideModule('basis'))('a KTX2 mip chain through the built transcoder', () => {let transcoder: BasisTranscoder;let ktx2: Uint8Array;beforeAll(async () => {- // The glue is CommonJS inside a package that reads `.js` as ESM.- const cjs = path.join(mkdtempSync(path.join(tmpdir(), 'basis-')), 'basis.cjs');- writeFileSync(cjs, readFileSync(MODULE));- const factory = createRequire(__filename)(cjs) as (o: object) => Promise<BasisWasmModule>;- transcoder = transcoderFromModule(await factory({ locateFile: (f: string) => path.join(path.dirname(MODULE), f) }));+ transcoder = transcoderFromModule(await loadSideModule<BasisWasmModule>('basis'));const encoder = await import(path.join(ROOT, 'build-tools/basis/encoder.mjs'));const rgba = new Uint8Array(SIDE * SIDE * 4).map((_, i) => (i * 37) & 0xff);ktx2 = await encoder.encodeToKtx2(@@ -38,15 +31,15 @@ describe.skipIf(!existsSync(MODULE))('a KTX2 mip chain through the built transcoconst sides = [64, 32, 16, 8, 4, 2, 1];- it('comes back with every level, each half the one before', () => {- const t = transcoder.transcode(ktx2, CompressedTextureFormat.ASTC_4x4)!;+ it('comes back with every level, each half the one before', async () => {+ const t = (await transcoder.transcode(ktx2, CompressedTextureFormat.ASTC_4x4))!;expect(t.levels?.map((l) => l.width)).toEqual(sides);// ASTC 4x4: one 16-byte block per 4x4, and a level smaller than a block still takes one.expect(t.levels?.map((l) => l.data.byteLength)).toEqual(sides.map((s) => Math.ceil(s / 4) ** 2 * 16));});- it('decodes every level to RGBA as well', () => {- const r = transcoder.transcodeToRgba(ktx2)!;+ it('decodes every level to RGBA as well', async () => {+ const r = (await transcoder.transcodeToRgba(ktx2))!;expect(r.levels?.map((l) => l.data.byteLength)).toEqual(sides.map((s) => s * s * 4));});@@ -60,7 +53,7 @@ describe.skipIf(!existsSync(MODULE))('a KTX2 mip chain through the built transcoconst half = halveRgba(decoded.pixels, decoded.width, decoded.height, readKtx2Layout(authored)!.srgb);const below = await encoder.encodeToKtx2({ type: encoder.ImageType.RGBA, data: half.rgba, width: half.width, height: half.height },{ mode: 'uastc', mipmaps: true, yFlip: false, uastcLevel: 0, supercompress: true });- const t = transcoder.transcode(spliceMipChain(authored, below), CompressedTextureFormat.ASTC_4x4)!;+ const t = (await transcoder.transcode(spliceMipChain(authored, below), CompressedTextureFormat.ASTC_4x4))!;expect(t.levels?.map((l) => l.width)).toEqual(sides);});});diff --git a/sdk/tests/basis-workers.test.ts b/sdk/tests/basis-workers.test.tsindex 8af9f75ef..ec0df21d5 100644--- a/sdk/tests/basis-workers.test.ts+++ b/sdk/tests/basis-workers.test.ts@@ -7,13 +7,11 @@* a stand-in that does what a browser does to it: `importScripts` of the real* basis glue, the real wasm, and structured-cloned messages both ways. What a* browser adds — a separate thread — is exercised by the Bistro boot on the box.- * Requires build/wasm/web/basis.{js,wasm}.*/import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';-import { existsSync, readFileSync, writeFileSync, mkdtempSync } from 'node:fs';-import { createRequire } from 'node:module';-import { tmpdir } from 'node:os';+import { readFileSync } from 'node:fs';import path from 'node:path';+import { WASM_DIR, hasSideModule, loadSideModule } from './helpers/loadWasm';import { basisTranscoderFor, createWorkerBasisTranscoder } from '../src/asset/basisWorkers';import { transcoderFromModule, type BasisWasmModule } from '../src/asset/basisTranscoder';import { CompressedTextureFormat, type TranscodeResult } from '../src/asset/compressed';@@ -21,8 +19,6 @@ import type { SideModuleHost, SideModuleSource } from '../src/sideModules/host';import { log } from '../src/util/logger';const ROOT = path.resolve(__dirname, '../..');-const GLUE = path.join(ROOT, 'build/wasm/web/basis.js');-const WASM = path.join(ROOT, 'build/wasm/web/basis.wasm');const blobs = new Map<string, string>();const saved = { Worker: globalThis.Worker, createObjectURL: URL.createObjectURL, revokeObjectURL: URL.revokeObjectURL };@@ -82,17 +78,16 @@ afterAll(() => {URL.revokeObjectURL = saved.revokeObjectURL;});-describe.skipIf(!existsSync(GLUE) || !existsSync(WASM))('KTX2 transcoding on workers', () => {+describe.skipIf(!hasSideModule('basis'))('KTX2 transcoding on workers', () => {let source: SideModuleSource;let main: ReturnType<typeof transcoderFromModule>;let ktx2: Uint8Array;beforeAll(async () => {- source = { glueText: readFileSync(GLUE, 'utf8'), globalName: 'ESBasisModule', wasmBytes: readFileSync(WASM).buffer.slice(0) as ArrayBuffer };- const cjs = path.join(mkdtempSync(path.join(tmpdir(), 'basis-')), 'basis.cjs');- writeFileSync(cjs, source.glueText);- const factory = createRequire(__filename)(cjs) as (o: object) => Promise<BasisWasmModule>;- main = transcoderFromModule(await factory({ locateFile: (f: string) => path.join(path.dirname(WASM), f) }));+ const wasm = readFileSync(path.join(WASM_DIR, 'basis.wasm'));+ source = { glueText: readFileSync(path.join(WASM_DIR, 'basis.js'), 'utf8'), globalName: 'ESBasisModule',+ wasmBytes: wasm.buffer.slice(wasm.byteOffset, wasm.byteOffset + wasm.byteLength) as ArrayBuffer };+ main = transcoderFromModule(await loadSideModule<BasisWasmModule>('basis'));const encoder = await import(path.join(ROOT, 'build-tools/basis/encoder.mjs'));const rgba = new Uint8Array(64 * 64 * 4).map((_, i) => (i * 29) & 0xff);ktx2 = await encoder.encodeToKtx2({ type: encoder.ImageType.RGBA, data: rgba, width: 64, height: 64 }, { mode: 'uastc', mipmaps: true });