File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export const httpParserWasmUrl = new URL (
2+ '../http_parser.wasm' ,
3+ import . meta. url
4+ ) ;
Original file line number Diff line number Diff line change 11import { describe , expect , test } from 'vitest' ;
22import { HttpParser } from '../parser.js' ;
3+ import { httpParserWasmUrl } from '../wasm-url.js' ;
34import { LlhttpBindings } from './bindings.js' ;
45
56const encoder = new TextEncoder ( ) ;
@@ -29,6 +30,14 @@ async function readText(readable: ReadableStream<Uint8Array>) {
2930}
3031
3132describe ( 'LlhttpBindings' , ( ) => {
33+ test ( 'uses the package wasm asset URL' , ( ) => {
34+ expect ( httpParserWasmUrl . pathname ) . toMatch ( / \/ h t t p _ p a r s e r \. w a s m $ / ) ;
35+ expect ( httpParserWasmUrl . pathname ) . not . toContain ( '/src/' ) ;
36+ expect ( httpParserWasmUrl . pathname ) . not . toMatch (
37+ / \/ @ t c p i p \/ h t t p _ p a r s e r \. w a s m $ /
38+ ) ;
39+ } ) ;
40+
3241 test ( 'parses a response with streamed body bytes' , async ( ) => {
3342 const runtime = new LlhttpBindings ( ) ;
3443 await runtime . ready ( ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import type {
55 HttpParserRuntime ,
66 HttpParserType ,
77} from '../types.js' ;
8+ import { httpParserWasmUrl } from '../wasm-url.js' ;
89import { fetchFile } from './fetch-file.js' ;
910import type { LlhttpExports , LlhttpImports , Pointer } from './types.js' ;
1011
@@ -98,27 +99,7 @@ export class LlhttpBindings implements HttpParserRuntime {
9899 }
99100
100101 async #source( ) {
101- // Source tests run from src/wasm; published builds run from dist. Try both
102- // relative paths back to the package-root wasm asset.
103- const urls = [
104- new URL ( '../../http_parser.wasm' , import . meta. url ) ,
105- new URL ( '../http_parser.wasm' , import . meta. url ) ,
106- ] ;
107-
108- let lastError : unknown ;
109- for ( const url of urls ) {
110- try {
111- const response = await fetchFile ( url , 'application/wasm' ) ;
112- if ( response . ok ) {
113- return response ;
114- }
115- lastError = new Error ( `failed to fetch ${ url } : ${ response . status } ` ) ;
116- } catch ( error ) {
117- lastError = error ;
118- }
119- }
120-
121- throw lastError ;
102+ return fetchFile ( httpParserWasmUrl , 'application/wasm' ) ;
122103 }
123104
124105 createParser ( type : HttpParserType , callbacks : HttpParserCallbacks ) {
You can’t perform that action at this time.
0 commit comments