@@ -31,13 +31,14 @@ async function withTimeout(promise, description) {
3131}
3232
3333describe ( "lazy MultiCompiler artifact provenance" , ( ) => {
34- it ( "keeps dependent and coalesced file-backed generations normal" , async ( ) => {
34+ async function runArtifactChain ( _watcherName , nativeWatcher ) {
3535 const root = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "rspack-lazy-chain-" ) ) ;
3636 const sourceFile = path . join ( root , "source.js" ) ;
3737 const coalescedEntry = path . join ( root , "coalesced-source.js" ) ;
3838 const stampFile = name => path . join ( root , name , "stamp.txt" ) ;
3939 const generations = Object . fromEntries ( names . map ( name => [ name , 0 ] ) ) ;
4040 const events = [ ] ;
41+ const invalidations = [ ] ;
4142 let delayedSource ;
4243 let resolveFileInvalidation ;
4344 let server ;
@@ -56,6 +57,14 @@ describe("lazy MultiCompiler artifact provenance", () => {
5657 coalescedEntry ,
5758 'export const coalesced = "coalesced";\n'
5859 ) ;
60+ // Keep Watchpack's initial scan from treating fresh fixture files as edits.
61+ const beforeWatch = new Date ( Date . now ( ) - 3000 ) ;
62+ await Promise . all (
63+ [
64+ ...names . map ( name => path . join ( root , `${ name } .js` ) ) ,
65+ coalescedEntry
66+ ] . map ( file => fs . utimes ( file , beforeWatch , beforeWatch ) )
67+ ) ;
5968
6069 const config = name => ( {
6170 context : root ,
@@ -65,7 +74,7 @@ describe("lazy MultiCompiler artifact provenance", () => {
6574 name === "source"
6675 ? { main : "./source.js" , coalesced : "./coalesced-source.js" }
6776 : { main : `./${ name } .js` } ,
68- experiments : { nativeWatcher : true } ,
77+ experiments : { nativeWatcher } ,
6978 lazyCompilation : { entries : true , imports : false } ,
7079 mode : "development" ,
7180 name,
@@ -78,6 +87,7 @@ describe("lazy MultiCompiler artifact provenance", () => {
7887 {
7988 apply ( compiler ) {
8089 compiler . hooks . invalid . tap ( "lazy-artifact-chain" , file => {
90+ invalidations . push ( { name, file } ) ;
8191 if ( name === "source" && file === sourceFile ) {
8292 resolveFileInvalidation ?. ( ) ;
8393 }
@@ -278,19 +288,32 @@ describe("lazy MultiCompiler artifact provenance", () => {
278288 const fileInvalidated = new Promise ( resolve => {
279289 resolveFileInvalidation = resolve ;
280290 } ) ;
281- delayedSource = { started : signalSourceStarted , release : sourceRelease } ;
291+ delayedSource = {
292+ started : signalSourceStarted ,
293+ release : sourceRelease
294+ } ;
282295 const beforeCoalesced = events . length ;
283296 const beforeGenerations = { ...generations } ;
284297 assert . equal ( await activate ( "source" , JSON . parse ( coalescedId ) ) , 200 ) ;
285298 await withTimeout ( sourceStarted , "the coalesced source build to start" ) ;
299+ const beforeFileInvalidations = invalidations . length ;
286300 await fs . writeFile (
287301 sourceFile ,
288302 'export const source = "source";\nexport const edited = "file-edit";\n'
289303 ) ;
290- await withTimeout ( fileInvalidated , "the coalesced source file event" ) ;
304+ if ( nativeWatcher ) {
305+ await withTimeout ( fileInvalidated , "the coalesced source file event" ) ;
306+ }
291307 releaseSource ( ) ;
292308 assertBuild ( await nextBuild ( ) , [ "source" , "dependent" , "tail" ] , "normal" ) ;
293309 const coalesced = events . slice ( beforeCoalesced ) ;
310+ assert . equal (
311+ invalidations
312+ . slice ( beforeFileInvalidations )
313+ . filter ( event => event . name === "source" ) . length ,
314+ 1 ,
315+ "a coalesced file edit must notify the source compiler exactly once"
316+ ) ;
294317 assert . equal (
295318 coalesced . every ( event => event . kind === "normal" ) ,
296319 true ,
@@ -319,6 +342,9 @@ describe("lazy MultiCompiler artifact provenance", () => {
319342 assert . equal ( generations . tail , beforeGenerations . tail + 1 ) ;
320343 assert . equal ( generations . unrelated , beforeGenerations . unrelated ) ;
321344 await assertTail ( ) ;
345+ const deliveredGenerations = { ...generations } ;
346+ await new Promise ( resolve => setTimeout ( resolve , 80 ) ) ;
347+ assert . deepEqual ( generations , deliveredGenerations ) ;
322348 } finally {
323349 if ( watching ) {
324350 await new Promise ( ( resolve , reject ) =>
@@ -328,5 +354,13 @@ describe("lazy MultiCompiler artifact provenance", () => {
328354 if ( server ) await new Promise ( resolve => server . close ( resolve ) ) ;
329355 await fs . rm ( root , { force : true , recursive : true } ) ;
330356 }
331- } ) ;
357+ }
358+
359+ it . each ( [
360+ [ "native" , true ] ,
361+ [ "watchpack" , false ]
362+ ] ) (
363+ "keeps dependent and coalesced file-backed generations normal with %s watching" ,
364+ runArtifactChain
365+ ) ;
332366} ) ;
0 commit comments