File tree Expand file tree Collapse file tree 7 files changed +45
-3
lines changed Expand file tree Collapse file tree 7 files changed +45
-3
lines changed Original file line number Diff line number Diff line change 1+ import { expect , test } from '@rstest/core' ;
2+
3+ // TODO: need to fix below error after bump rspack 1.6.2+
4+ // WebAssemb ly.instantiate(): length overflow while decoding section length @+13
5+ test . fails ( 'WASM factorial' , async ( ) => {
6+ const { _Z4facti : AsyncFactorial } = await import ( './src/factorial.wasm' ) ;
7+
8+ expect ( AsyncFactorial ( 1 ) ) . toBe ( 1 ) ;
9+ expect ( AsyncFactorial ( 2 ) ) . toBe ( 2 ) ;
10+ expect ( AsyncFactorial ( 3 ) ) . toBe ( 6 ) ;
11+ } ) ;
Original file line number Diff line number Diff line change 1+ export function _Z4facti ( n : number ) : number ;
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ const autoExternalNodeModules: (
1515 return callback ( ) ;
1616 }
1717
18- if ( request . startsWith ( '@swc/helpers/' ) ) {
18+ if ( request . startsWith ( '@swc/helpers/' ) || request . endsWith ( '.wasm' ) ) {
1919 // @swc /helper is a special case (Load by require but resolve to esm)
2020 return callback ( ) ;
2121 }
Original file line number Diff line number Diff line change @@ -48,6 +48,17 @@ class MockRuntimeRspackPlugin {
4848
4949 module . source ! . source = Buffer . from ( finalSource ) ;
5050 }
51+
52+ if ( module . name === 'async_wasm_loading' ) {
53+ const finalSource = module . source ! . source . toString ( 'utf-8' ) . replace (
54+ // Replace readFile with readWasmFile to use the custom WASM file loader
55+ // Hard coded in EJS template https://github.com/web-infra-dev/rspack/tree/7df875eb3ca3bb4bcb21836fdf4e6be1f38a057c/crates/rspack_plugin_wasm/src/runtime
56+ 'readFile(' ,
57+ 'readWasmFile(' ,
58+ ) ;
59+
60+ module . source ! . source = Buffer . from ( finalSource ) ;
61+ }
5162 } ,
5263 ) ;
5364 } ) ;
Original file line number Diff line number Diff line change @@ -186,6 +186,22 @@ export const loadModule = ({
186186 assetFiles ,
187187 interopDefault ,
188188 ) ,
189+ readWasmFile : (
190+ wasmPath : string ,
191+ callback : ( err : Error | null , data ?: Buffer ) => void ,
192+ ) => {
193+ const joinedPath = isRelativePath ( wasmPath )
194+ ? path . join ( path . dirname ( distPath ) , wasmPath )
195+ : wasmPath ;
196+ const content = assetFiles [ path . normalize ( joinedPath ) ] ;
197+ if ( content ) {
198+ callback ( null , Buffer . from ( content , 'utf-8' ) ) ;
199+ } else {
200+ callback (
201+ new Error ( `WASM file ${ joinedPath } not found in asset files.` ) ,
202+ ) ;
203+ }
204+ } ,
189205 __rstest_dynamic_import__ : defineRstestDynamicImport ( {
190206 testPath,
191207 interopDefault,
Original file line number Diff line number Diff line change @@ -67,8 +67,11 @@ export async function printError(
6767 fullStack : error . fullStack ,
6868 getSourcemap,
6969 } ) ;
70-
71- if ( ! stackFrames . length && error . stack . length ) {
70+ if (
71+ ! stackFrames . length &&
72+ ! ( error . fullStack || isDebug ( ) ) &&
73+ ! error . stack . endsWith ( error . message )
74+ ) {
7275 logger . log (
7376 color . gray (
7477 "No error stack found, set 'DEBUG=rstest' to show fullStack." ,
You can’t perform that action at this time.
0 commit comments