@@ -29,6 +29,7 @@ import { wsEndpoint } from '../utils/test-config';
2929import { devices } from 'playwright-chromium' ;
3030import { Server } from '../utils/server' ;
3131import { megabitsToBytes } from '../../src/helpers' ;
32+ import { chromium } from 'playwright-chromium' ;
3233
3334jest . mock ( '../../src/plugins/network' ) ;
3435
@@ -42,12 +43,60 @@ describe('Gatherer', () => {
4243 await server . close ( ) ;
4344 } ) ;
4445
46+ afterEach ( ( ) => {
47+ jest . restoreAllMocks ( ) ;
48+ } ) ;
49+
4550 it ( 'boot and close browser' , async ( ) => {
4651 const driver = await Gatherer . setupDriver ( { wsEndpoint } ) ;
4752 expect ( typeof driver . page . goto ) . toBe ( 'function' ) ;
4853 await Gatherer . stop ( ) ;
4954 } ) ;
5055
56+ // This test should only run when a browser service is up
57+ ( wsEndpoint ? it : it . skip ) (
58+ 'does not the disable-gpu flag to start browser when running headful' ,
59+ async ( ) => {
60+ const chromiumLaunch = jest
61+ . spyOn ( chromium , 'launch' )
62+ . mockImplementation ( ( ) => {
63+ return chromium . connect ( { wsEndpoint } ) ;
64+ } ) ;
65+
66+ await Gatherer . setupDriver ( {
67+ playwrightOptions : { headless : false } ,
68+ } ) ;
69+ expect ( chromiumLaunch ) . toHaveBeenCalledWith (
70+ expect . objectContaining ( {
71+ args : expect . not . arrayContaining ( [ '--disable-gpu' ] ) ,
72+ } )
73+ ) ;
74+ await Gatherer . stop ( ) ;
75+ }
76+ ) ;
77+
78+ // This test should only run when a browser service is up
79+ ( wsEndpoint ? it : it . skip ) (
80+ 'uses the disable-gpu flag to start browser when running headlessly' ,
81+ async ( ) => {
82+ const chromiumLaunch = jest
83+ . spyOn ( chromium , 'launch' )
84+ . mockImplementation ( ( ) => {
85+ return chromium . connect ( { wsEndpoint } ) ;
86+ } ) ;
87+
88+ await Gatherer . setupDriver ( {
89+ playwrightOptions : { headless : true } ,
90+ } ) ;
91+ expect ( chromiumLaunch ) . toHaveBeenCalledWith (
92+ expect . objectContaining ( {
93+ args : expect . arrayContaining ( [ '--disable-gpu' ] ) ,
94+ } )
95+ ) ;
96+ await Gatherer . stop ( ) ;
97+ }
98+ ) ;
99+
51100 it ( 'setup and dispose driver' , async ( ) => {
52101 const driver = await Gatherer . setupDriver ( { wsEndpoint } ) ;
53102 await Gatherer . dispose ( driver ) ;
0 commit comments