-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use WebAssembly version libraries for unit testing #16264
Conversation
2848853
to
87c38fe
Compare
Interface Check ReportThis pull request does not change any public interfaces ! |
44e6676
to
165bbfd
Compare
export async function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Imports): Promise<any> { | ||
return fetchBuffer(wasmUrl).then((arrayBuffer) => WebAssembly.instantiate(arrayBuffer, importObject)); | ||
} | ||
|
||
export async function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> { | ||
const relativePathToExternal = /^external:(.*)/.exec(binaryUrl)?.[1]; | ||
if (relativePathToExternal) { | ||
const externalHome = join(__dirname, '..', '..', 'native', 'external'); | ||
const path = join(externalHome, relativePathToExternal); | ||
try { | ||
const content = readFileSync(path); | ||
return content.buffer; | ||
} catch (err) { | ||
throw new Error(`Unable to fetch buffer from ${binaryUrl}`, { cause: error }); | ||
} | ||
} | ||
|
||
throw new Error(`Don't know how to fetch buffer at url ${binaryUrl}`); | ||
} | ||
|
||
export async function ensureWasmModuleReady() { | ||
return Promise.resolve(); | ||
} | ||
|
||
checkPalIntegrity<typeof import('@pal/wasm')>(withImpl<typeof import('./pal-wasm-testing')>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why add this file ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes it possible to use wasm in unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't actually mock pal/wasm module to the web implementation
and please remember to update the related docs https://github.com/cocos/3d-tasks/blob/master/design-docs/scripting/engine-wasm-module.md#%E8%A7%A3%E5%86%B3-ci-%E9%97%AE%E9%A2%98 |
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: