@@ -145,6 +145,61 @@ describe('Asset Query Parameters with Islands', () => {
145145 } ) ;
146146} ) ;
147147
148+ describe ( 'Asset Query Parameters in Inter-Chunk JS Imports' , ( ) => {
149+ /** @type {import('./test-utils').Fixture } */
150+ let fixture ;
151+
152+ before ( async ( ) => {
153+ fixture = await loadFixture ( {
154+ root : './fixtures/asset-query-params-chunks/' ,
155+ output : 'server' ,
156+ adapter : testAdapter ( {
157+ extendAdapter : {
158+ client : {
159+ assetQueryParams : new URLSearchParams ( { dpl : 'test-deploy-id' } ) ,
160+ } ,
161+ } ,
162+ } ) ,
163+ } ) ;
164+ await fixture . build ( ) ;
165+ } ) ;
166+
167+ it ( 'appends assetQueryParams to relative imports inside client JS chunks' , async ( ) => {
168+ const app = await fixture . loadTestAdapterApp ( ) ;
169+ const response = await app . render ( new Request ( 'http://example.com/' ) ) ;
170+ assert . equal ( response . status , 200 ) ;
171+ const html = await response . text ( ) ;
172+ const $ = cheerio . load ( html ) ;
173+ const scripts = $ ( 'script[src]' ) ;
174+ assert . ok ( scripts . length > 0 , 'Should have at least one external script' ) ;
175+
176+ let foundRelativeImport = false ;
177+ // Read all client JS files and check inter-chunk imports have query params
178+ const jsFiles = await fixture . glob ( 'client/**/*.js' ) ;
179+ for ( const file of jsFiles ) {
180+ const code = await fixture . readFile ( `/${ file } ` ) ;
181+ // Match relative imports: from"./chunk.js", from "./chunk.js", import("./chunk.js")
182+ const allImports = [
183+ ...code . matchAll ( / ( f r o m \s * [ " ' ] ) ( \. \. ? \/ [ ^ " ' ] + \. (?: j s | m j s ) (?: \? [ ^ " ' ] * ) ? ) ( [ " ' ] ) / g) ,
184+ ...code . matchAll ( / ( i m p o r t \s * \( \s * [ " ' ] ) ( \. \. ? \/ [ ^ " ' ] + \. (?: j s | m j s ) (?: \? [ ^ " ' ] * ) ? ) ( [ " ' ] ) / g) ,
185+ ] ;
186+ for ( const match of allImports ) {
187+ foundRelativeImport = true ;
188+ const importPath = match [ 2 ] ;
189+ assert . match (
190+ importPath ,
191+ / \? d p l = t e s t - d e p l o y - i d / ,
192+ `Inter-chunk import should include assetQueryParams: ${ match [ 0 ] } ` ,
193+ ) ;
194+ }
195+ }
196+ assert . ok (
197+ foundRelativeImport ,
198+ 'Expected at least one relative inter-chunk import in client JS files' ,
199+ ) ;
200+ } ) ;
201+ } ) ;
202+
148203describe ( 'Asset Query Parameters with Islands and assetsPrefix map' , ( ) => {
149204 /** @type {import('./test-utils').Fixture } */
150205 let fixture ;
0 commit comments