@@ -125,25 +125,75 @@ describe("UrlContentFetcher", () => {
125125 } )
126126
127127 describe ( "launchBrowser" , ( ) => {
128- it ( "should launch browser with correct arguments" , async ( ) => {
129- await urlContentFetcher . launchBrowser ( )
130-
131- expect ( vi . mocked ( PCR ) ) . toHaveBeenCalledWith ( {
132- downloadPath : path . join ( "/test/storage" , "puppeteer" ) ,
128+ it ( "should launch browser with correct arguments on non-Linux platforms " , async ( ) => {
129+ // Ensure we're not on Linux for this test
130+ const originalPlatform = process . platform
131+ Object . defineProperty ( process , 'platform' , {
132+ value : 'darwin' // macOS
133133 } )
134134
135- const stats = await vi . mocked ( PCR ) . mock . results [ 0 ] . value
136- expect ( stats . puppeteer . launch ) . toHaveBeenCalledWith ( {
137- args : [
138- "--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" ,
139- "--disable-dev-shm-usage" ,
140- "--disable-accelerated-2d-canvas" ,
141- "--no-first-run" ,
142- "--disable-gpu" ,
143- "--disable-features=VizDisplayCompositor" ,
144- ] ,
145- executablePath : "/path/to/chromium" ,
135+ try {
136+ await urlContentFetcher . launchBrowser ( )
137+
138+ expect ( vi . mocked ( PCR ) ) . toHaveBeenCalledWith ( {
139+ downloadPath : path . join ( "/test/storage" , "puppeteer" ) ,
140+ } )
141+
142+ const stats = await vi . mocked ( PCR ) . mock . results [ 0 ] . value
143+ expect ( stats . puppeteer . launch ) . toHaveBeenCalledWith ( {
144+ args : [
145+ "--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" ,
146+ "--disable-dev-shm-usage" ,
147+ "--disable-accelerated-2d-canvas" ,
148+ "--no-first-run" ,
149+ "--disable-gpu" ,
150+ "--disable-features=VizDisplayCompositor" ,
151+ ] ,
152+ executablePath : "/path/to/chromium" ,
153+ } )
154+ } finally {
155+ // Restore original platform
156+ Object . defineProperty ( process , 'platform' , {
157+ value : originalPlatform
158+ } )
159+ }
160+ } )
161+
162+ it ( "should launch browser with Linux-specific arguments" , async ( ) => {
163+ // Mock process.platform to be linux
164+ const originalPlatform = process . platform
165+ Object . defineProperty ( process , 'platform' , {
166+ value : 'linux'
146167 } )
168+
169+ try {
170+ // Create a new instance to ensure fresh state
171+ const linuxFetcher = new UrlContentFetcher ( mockContext )
172+ await linuxFetcher . launchBrowser ( )
173+
174+ expect ( vi . mocked ( PCR ) ) . toHaveBeenCalledWith ( {
175+ downloadPath : path . join ( "/test/storage" , "puppeteer" ) ,
176+ } )
177+
178+ const stats = await vi . mocked ( PCR ) . mock . results [ vi . mocked ( PCR ) . mock . results . length - 1 ] . value
179+ expect ( stats . puppeteer . launch ) . toHaveBeenCalledWith ( {
180+ args : [
181+ "--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" ,
182+ "--disable-dev-shm-usage" ,
183+ "--disable-accelerated-2d-canvas" ,
184+ "--no-first-run" ,
185+ "--disable-gpu" ,
186+ "--disable-features=VizDisplayCompositor" ,
187+ "--no-sandbox" , // Linux-specific argument
188+ ] ,
189+ executablePath : "/path/to/chromium" ,
190+ } )
191+ } finally {
192+ // Restore original platform
193+ Object . defineProperty ( process , 'platform' , {
194+ value : originalPlatform
195+ } )
196+ }
147197 } )
148198
149199 it ( "should set viewport and headers after launching" , async ( ) => {
0 commit comments