@@ -69,10 +69,34 @@ type suite struct {
6969
7070func (s * suite ) expectBundled (t * testing.T , args bundled ) {
7171 t .Helper ()
72+ s .__expectBundledImpl (t , args , fs .MockUnix )
73+ s .__expectBundledImpl (t , args , fs .MockWindows )
74+ }
75+
76+ func (s * suite ) expectBundledUnix (t * testing.T , args bundled ) {
77+ t .Helper ()
78+ s .__expectBundledImpl (t , args , fs .MockUnix )
79+ }
80+
81+ func (s * suite ) expectBundledWindows (t * testing.T , args bundled ) {
82+ t .Helper ()
83+ s .__expectBundledImpl (t , args , fs .MockWindows )
84+ }
85+
86+ // Don't call this directly. Call the helpers above instead.
87+ func (s * suite ) __expectBundledImpl (t * testing.T , args bundled , fsKind fs.MockKind ) {
88+ t .Helper ()
89+
7290 testName := t .Name ()
73- t .Run ("" , func (t * testing.T ) {
91+ subName := "Unix"
92+ if fsKind == fs .MockWindows {
93+ subName = "Windows"
94+ }
95+
96+ t .Run (subName , func (t * testing.T ) {
7497 t .Helper ()
75- fs := fs .MockFS (args .files )
98+
99+ // Prepare the options
76100 if args .options .ExtensionOrder == nil {
77101 args .options .ExtensionOrder = []string {".tsx" , ".ts" , ".jsx" , ".js" , ".css" , ".json" }
78102 }
@@ -87,15 +111,40 @@ func (s *suite) expectBundled(t *testing.T, args bundled) {
87111 if args .debugLogs {
88112 logKind = logger .DeferLogAll
89113 }
90- log := logger .NewDeferLog (logKind , nil )
91- caches := cache .MakeCacheSet ()
92- resolver := resolver .NewResolver (fs , log , caches , args .options )
93114 entryPoints := make ([]EntryPoint , 0 , len (args .entryPaths )+ len (args .entryPathsAdvanced ))
94115 for _ , path := range args .entryPaths {
95116 entryPoints = append (entryPoints , EntryPoint {InputPath : path })
96117 }
97118 entryPoints = append (entryPoints , args .entryPathsAdvanced ... )
98- bundle := ScanBundle (log , fs , resolver , caches , entryPoints , args .options , nil )
119+
120+ // Handle conversion to Windows-style paths
121+ if fsKind == fs .MockWindows {
122+ for i , entry := range entryPoints {
123+ entry .InputPath = unix2win (entry .InputPath )
124+ entryPoints [i ] = entry
125+ }
126+
127+ for i , absPath := range args .options .InjectAbsPaths {
128+ args .options .InjectAbsPaths [i ] = unix2win (absPath )
129+ }
130+
131+ replace := make (map [string ]bool )
132+ for k , v := range args .options .ExternalSettings .PostResolve .Exact {
133+ replace [unix2win (k )] = v
134+ }
135+ args .options .ExternalSettings .PostResolve .Exact = replace
136+
137+ args .options .AbsOutputFile = unix2win (args .options .AbsOutputFile )
138+ args .options .AbsOutputDir = unix2win (args .options .AbsOutputDir )
139+ args .options .TsConfigOverride = unix2win (args .options .TsConfigOverride )
140+ }
141+
142+ // Run the bundler
143+ log := logger .NewDeferLog (logKind , nil )
144+ caches := cache .MakeCacheSet ()
145+ mockFS := fs .MockFS (args .files , fsKind )
146+ resolver := resolver .NewResolver (mockFS , log , caches , args .options )
147+ bundle := ScanBundle (log , mockFS , resolver , caches , entryPoints , args .options , nil )
99148 msgs := log .Done ()
100149 assertLog (t , msgs , args .expectedScanLog )
101150
@@ -124,6 +173,9 @@ func (s *suite) expectBundled(t *testing.T, args bundled) {
124173 if generated != "" {
125174 generated += "\n "
126175 }
176+ if fsKind == fs .MockWindows {
177+ result .AbsPath = win2unix (result .AbsPath )
178+ }
127179 generated += fmt .Sprintf ("---------- %s ----------\n %s" , result .AbsPath , string (result .Contents ))
128180 }
129181 }
@@ -235,3 +287,19 @@ func TestMain(m *testing.M) {
235287 }
236288 os .Exit (code )
237289}
290+
291+ func win2unix (p string ) string {
292+ if strings .HasPrefix (p , "C:\\ " ) {
293+ p = p [2 :]
294+ }
295+ p = strings .ReplaceAll (p , "\\ " , "/" )
296+ return p
297+ }
298+
299+ func unix2win (p string ) string {
300+ p = strings .ReplaceAll (p , "/" , "\\ " )
301+ if strings .HasPrefix (p , "\\ " ) {
302+ p = "C:" + p
303+ }
304+ return p
305+ }
0 commit comments