@@ -8,7 +8,15 @@ import {AbortError} from '@shopify/cli-kit/node/error'
88import { readFile } from 'fs/promises'
99
1010vi . mock ( '@shopify/cli-kit/node/session' )
11- vi . mock ( '@shopify/cli-kit/node/system' )
11+ vi . mock ( '@shopify/cli-kit/node/system' , async ( ) => {
12+ const actual = await vi . importActual ( '@shopify/cli-kit/node/system' )
13+ return {
14+ ...actual ,
15+ openURL : vi . fn ( ) . mockResolvedValue ( true ) ,
16+ isWsl : vi . fn ( ) . mockResolvedValue ( false ) ,
17+ convertWslPath : vi . fn ( ( path : string ) => Promise . resolve ( path ) ) ,
18+ }
19+ } )
1220vi . mock ( '@shopify/cli-kit/node/output' )
1321vi . mock ( '../utilities/theme-environment/storefront-password-prompt.js' )
1422vi . mock ( '../utilities/theme-environment/storefront-session.js' )
@@ -82,6 +90,42 @@ describe('profile', () => {
8290 expect ( htmlContent ) . toContain ( 'speedscope' )
8391 } )
8492
93+ test ( 'converts all WSL paths before opening browser' , async ( ) => {
94+ // Given
95+ const { isWsl, convertWslPath} = await import ( '@shopify/cli-kit/node/system' )
96+ vi . mocked ( isWsl ) . mockResolvedValue ( true )
97+ vi . mocked ( convertWslPath ) . mockImplementation ( ( linuxPath : string ) => {
98+ if ( linuxPath . endsWith ( '.html' ) ) {
99+ return Promise . resolve ( 'C:\\Users\\dev\\AppData\\Local\\Temp\\speedscope-12345-999.html' )
100+ }
101+ if ( linuxPath . endsWith ( '.js' ) ) {
102+ return Promise . resolve ( 'C:\\Users\\dev\\AppData\\Local\\Temp\\speedscope-12345-999.js' )
103+ }
104+ // speedscope index.html asset path
105+ return Promise . resolve ( 'C:\\Users\\dev\\node_modules\\speedscope\\dist\\release\\index.html' )
106+ } )
107+
108+ // When
109+ await profile ( mockAdminSession , themeId , urlPath , false , undefined , undefined )
110+
111+ // Then
112+ expect ( isWsl ) . toHaveBeenCalled ( )
113+ // All 3 paths should be converted
114+ expect ( convertWslPath ) . toHaveBeenCalledTimes ( 3 )
115+ expect ( convertWslPath ) . toHaveBeenCalledWith ( expect . stringContaining ( 'index.html' ) )
116+ expect ( convertWslPath ) . toHaveBeenCalledWith ( expect . stringMatching ( / \. j s $ / ) )
117+ expect ( convertWslPath ) . toHaveBeenCalledWith ( expect . stringMatching ( / \. h t m l $ / ) )
118+ expect ( openURL ) . toHaveBeenCalledWith ( 'file://C:\\Users\\dev\\AppData\\Local\\Temp\\speedscope-12345-999.html' )
119+
120+ // Verify the redirect HTML contains Windows paths (not Linux paths)
121+ const openUrlCalls = vi . mocked ( openURL ) . mock . calls
122+ const firstCall = openUrlCalls [ 0 ]
123+ if ( ! firstCall ) throw new Error ( 'Expected at least one openURL call' )
124+ const convertWslPathCalls = vi . mocked ( convertWslPath ) . mock . calls
125+ expect ( convertWslPathCalls . some ( ( call ) => String ( call [ 0 ] ) . endsWith ( '.js' ) ) ) . toBe ( true )
126+ expect ( convertWslPathCalls . some ( ( call ) => String ( call [ 0 ] ) . includes ( 'index.html' ) ) ) . toBe ( true )
127+ } )
128+
85129 test ( 'throws error when fetch fails' , async ( ) => {
86130 // Given
87131 vi . mocked ( render ) . mockRejectedValue ( new Error ( 'Network error' ) )
0 commit comments