@@ -6,6 +6,33 @@ import type { Violation } from './violations.utils'
66import type { Page } from '@playwright/test'
77
88const toolchain = process . env . E2E_TOOLCHAIN ?? 'vite'
9+ const fixtureRoot = path . resolve ( import . meta. dirname , '..' )
10+ const workspaceRoot = path . resolve ( import . meta. dirname , '../../../..' )
11+
12+ function stripLocation ( value : string ) : string {
13+ return value . replace ( / : \d + : \d + $ / , '' )
14+ }
15+
16+ function normalizeKeyPath ( value : string ) : string {
17+ let normalized = stripLocation ( value ) . replace ( / \\ / g, '/' )
18+ const normalizedFixtureRoot = fixtureRoot . replace ( / \\ / g, '/' )
19+ const normalizedWorkspaceRoot = workspaceRoot . replace ( / \\ / g, '/' )
20+
21+ if ( normalized . startsWith ( `${ normalizedFixtureRoot } /` ) ) {
22+ normalized = normalized . slice ( normalizedFixtureRoot . length + 1 )
23+ } else if ( normalized . startsWith ( `${ normalizedWorkspaceRoot } /` ) ) {
24+ normalized = normalized . slice ( normalizedWorkspaceRoot . length + 1 )
25+ }
26+
27+ normalized = normalized . replace (
28+ / ^ p a c k a g e s \/ r e a c t - s t a r t \/ d i s t \/ e s m \/ ( .+ ) $ / ,
29+ '@tanstack/react-start/$1' ,
30+ )
31+ normalized = normalized . replace ( / \. [ c m ] ? [ t j ] s x ? $ / , '' )
32+ normalized = normalized . replace ( / \/ i n d e x $ / , '' )
33+
34+ return normalized
35+ }
936
1037async function readViolations (
1138 type : 'build' | 'dev' | 'dev.cold' | 'dev.warm' ,
@@ -571,7 +598,7 @@ test('warm run produces violations', async () => {
571598 expect ( warm . length ) . toBeGreaterThan ( 0 )
572599} )
573600
574- test ( 'warm run detects the same unique violations as cold run' , async ( ) => {
601+ test ( 'warm run detects every unique cold- run violation ' , async ( ) => {
575602 const cold = await readViolations ( 'dev.cold' )
576603 const warm = await readViolations ( 'dev.warm' )
577604
@@ -581,13 +608,29 @@ test('warm run detects the same unique violations as cold run', async () => {
581608 // the `.ts` extension) because different detection code-paths fire.
582609 // Normalize to the resolved path (without extension) for a stable key.
583610 const normalizeSpec = ( v : Violation ) =>
584- ( v . resolved ?? v . specifier ) . replace ( / \. [ c m ] ? [ t j ] s x ? $ / , '' )
611+ normalizeKeyPath ( v . resolved ?? v . specifier )
612+ const normalizeImporter = ( v : Violation ) => {
613+ const importer = stripLocation ( v . importer )
614+ const leafTraceFile = v . trace . at ( - 1 ) ?. file
615+
616+ if (
617+ leafTraceFile &&
618+ ! importer . includes ( '/' ) &&
619+ normalizeKeyPath ( leafTraceFile ) . endsWith ( normalizeKeyPath ( importer ) )
620+ ) {
621+ return normalizeKeyPath ( leafTraceFile )
622+ }
623+
624+ return normalizeKeyPath ( importer )
625+ }
585626 const uniqueKey = ( v : Violation ) =>
586- `${ v . envType } |${ v . type } |${ normalizeSpec ( v ) } |${ v . importer . replace ( / : . * / , '' ) } `
627+ `${ v . envType } |${ v . type } |${ normalizeSpec ( v ) } |${ normalizeImporter ( v ) } `
587628
588629 const coldUniq = [ ...new Set ( cold . map ( uniqueKey ) ) ] . sort ( )
589- const warmUniq = [ ...new Set ( warm . map ( uniqueKey ) ) ] . sort ( )
590- expect ( warmUniq ) . toEqual ( coldUniq )
630+ const warmUniq = new Set ( warm . map ( uniqueKey ) )
631+ const missingFromWarm = coldUniq . filter ( ( key ) => ! warmUniq . has ( key ) )
632+
633+ expect ( missingFromWarm ) . toEqual ( [ ] )
591634} )
592635
593636test ( 'warm run traces include line numbers' , async ( ) => {
0 commit comments