-
-
Notifications
You must be signed in to change notification settings - Fork 11
fix: wasm load error #677
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
base: main
Are you sure you want to change the base?
fix: wasm load error #677
Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Pull Request Overview
This PR adds support for WebAssembly (WASM) modules in Rstest by implementing a custom WASM file loader and integrating it with the runtime module system.
- Adds
readWasmFilefunction to load WASM files from asset files - Modifies the
async_wasm_loadingruntime module to use the custom WASM loader - Prevents WASM files from being externalized during bundling
- Adds an E2E test for WASM factorial function
Reviewed Changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/runtime/worker/loadModule.ts | Implements readWasmFile function to load WASM files from asset files |
| packages/core/src/core/plugins/mockRuntime.ts | Patches async_wasm_loading runtime module to use custom WASM loader |
| packages/core/src/core/plugins/external.ts | Excludes WASM files from externalization |
| packages/core/src/utils/error.ts | Adds type guard for error.stack |
| e2e/wasm/index.test.ts | E2E test for WASM module loading |
| e2e/wasm/src/factorial.wasm.d.ts | TypeScript declaration for WASM module |
| e2e/wasm/src/factorial.wasm | Binary WASM file for testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ( | ||
| !stackFrames.length && | ||
| Array.isArray(error.stack) && | ||
| error.stack.length | ||
| ) { |
Copilot
AI
Nov 6, 2025
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.
The Array.isArray(error.stack) check is incorrect. According to the FormattedError type definition, error.stack is typed as string | undefined, not an array. This check will always be false. The condition should simply check if error.stack is a non-empty string.
| if ( | |
| !stackFrames.length && | |
| Array.isArray(error.stack) && | |
| error.stack.length | |
| ) { | |
| if (!stackFrames.length) { |
| : wasmPath; | ||
| const content = assetFiles[joinedPath]; | ||
| if (content) { | ||
| callback(null, Buffer.from(content, 'utf-8')); |
Copilot
AI
Nov 6, 2025
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.
WASM files are binary data, not UTF-8 text. Using Buffer.from(content, 'utf-8') will corrupt the binary data. The assetFiles dictionary stores file contents as strings, so they should be decoded using base64 encoding (e.g., Buffer.from(content, 'base64')) or the content should be stored and retrieved as binary data without text encoding.
| callback(null, Buffer.from(content, 'utf-8')); | |
| callback(null, Buffer.from(content, 'base64')); |
|
|
||
| if (module.name === 'async_wasm_loading') { | ||
| const finalSource = module.source!.source.toString('utf-8').replace( | ||
| // Sets the object configurable so that imported properties can be spied |
Copilot
AI
Nov 6, 2025
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.
The comment 'Sets the object configurable so that imported properties can be spied' is misleading. This replacement changes readFile( to readWasmFile( to use the custom WASM file loader, not to set object configurability. The comment should be updated to reflect the actual purpose of this transformation.
| // Sets the object configurable so that imported properties can be spied | |
| // Replace readFile with readWasmFile to use the custom WASM file loader |
Summary
TODO: below error should be fixed in rspack 1.6.2 web-infra-dev/rspack#12068

Related Links
fix: #676
Checklist