@@ -5,7 +5,7 @@ const mocks = vi.hoisted(() => ({
55 ensureBrowser : vi . fn ( ) ,
66 findSystemBrowser : vi . fn ( ) ,
77 launch : vi . fn ( ) ,
8- buildChromeArgs : vi . fn ( ( ) => [ ] ) ,
8+ buildChromeArgs : vi . fn ( ( ) : string [ ] => [ ] ) ,
99 resolveBrowserGpuMode : vi . fn ( async ( ) => "software" as const ) ,
1010 compositionRequiresWebGpu : vi . fn ( ( ) => false ) ,
1111 assertWebGpuAdapterAvailable : vi . fn ( async ( ) => undefined ) ,
@@ -33,6 +33,11 @@ vi.mock("@hyperframes/engine", () => ({
3333} ) ) ;
3434
3535import { openSettledCompositionPage } from "./captureCompositionFrame.js" ;
36+ import { Server } from "node:http" ;
37+ import { mkdtempSync , rmSync } from "node:fs" ;
38+ import { tmpdir } from "node:os" ;
39+ import { join } from "node:path" ;
40+ import { serveStaticProjectHtml } from "../utils/staticProjectServer.js" ;
3641
3742const HTML = '<div data-composition-id="main" data-width="1920" data-height="1080"></div>' ;
3843const OPTIONS = {
@@ -54,6 +59,8 @@ function fakeBrowser() {
5459 goto : vi . fn ( async ( ) => undefined ) ,
5560 waitForFunction : vi . fn ( async ( ) => undefined ) ,
5661 evaluate : vi . fn ( async ( ) => undefined ) ,
62+ setRequestInterception : vi . fn ( async ( _on : boolean ) => undefined ) ,
63+ on : vi . fn ( ( _event : string , _handler : ( request : unknown ) => void ) => undefined ) ,
5764 } ;
5865 return {
5966 browser : {
@@ -178,3 +185,69 @@ describe("openSettledCompositionPage Windows bundled-browser recovery", () => {
178185 expect ( mocks . launch ) . toHaveBeenCalledOnce ( ) ;
179186 } ) ;
180187} ) ;
188+
189+ describe ( "openSettledCompositionPage when nothing may listen" , ( ) => {
190+ const launched = ( ) =>
191+ mocks . launch . mock . calls . at ( - 1 ) ?. [ 0 ] as unknown as { pipe ?: boolean ; args : string [ ] } ;
192+
193+ beforeEach ( ( ) => {
194+ vi . resetAllMocks ( ) ;
195+ mocks . ensureBrowser . mockResolvedValue ( { executablePath : BUNDLED , source : "cache" } ) ;
196+ mocks . buildChromeArgs . mockReturnValue ( [ "--headless" ] ) ;
197+ mocks . resolveBrowserGpuMode . mockResolvedValue ( "software" ) ;
198+ mocks . resolveConfig . mockReturnValue ( { allowSoftwareWebGpu : false } ) ;
199+ mocks . usesSoftwareWebGpu . mockReturnValue ( false ) ;
200+ } ) ;
201+
202+ afterEach ( ( ) => vi . restoreAllMocks ( ) ) ;
203+
204+ it ( "drives Chrome over a pipe in one process and answers the page from the project" , async ( ) => {
205+ vi . spyOn ( Server . prototype , "listen" ) . mockImplementation ( function ( this : Server ) {
206+ process . nextTick ( ( ) =>
207+ this . emit ( "error" , Object . assign ( new Error ( "listen EPERM" ) , { code : "EPERM" } ) ) ,
208+ ) ;
209+ return this ;
210+ } ) ;
211+ const dir = mkdtempSync ( join ( tmpdir ( ) , "hf-nolisten-" ) ) ;
212+ const server = await serveStaticProjectHtml ( dir , "<html><body>composition</body></html>" ) ;
213+ const opened = fakeBrowser ( ) ;
214+ mocks . launch . mockResolvedValue ( opened . browser ) ;
215+ try {
216+ await openSettledCompositionPage ( HTML , server . url , OPTIONS ) ;
217+
218+ expect ( launched ( ) . pipe ) . toBe ( true ) ;
219+ expect ( launched ( ) . args ) . toEqual ( [ "--headless" , "--single-process" ] ) ;
220+ expect ( opened . page . setRequestInterception ) . toHaveBeenCalledWith ( true ) ;
221+ const onRequest = opened . page . on . mock . calls . find ( ( [ event ] ) => event === "request" ) ! [ 1 ] ;
222+ const respond = vi . fn ( async ( _response : { status : number ; body : Buffer } ) => undefined ) ;
223+ const proceed = vi . fn ( async ( ) => undefined ) ;
224+ const request = ( url : string ) => ( {
225+ url : ( ) => url ,
226+ method : ( ) => "GET" ,
227+ headers : ( ) => ( { } ) ,
228+ isInterceptResolutionHandled : ( ) => false ,
229+ respond,
230+ continue : proceed ,
231+ abort : vi . fn ( async ( ) => undefined ) ,
232+ } ) ;
233+ onRequest ( request ( `${ server . url } index.html` ) ) ;
234+ await vi . waitFor ( ( ) => expect ( respond ) . toHaveBeenCalledOnce ( ) ) ;
235+ expect ( respond . mock . calls [ 0 ] ! [ 0 ] ) . toMatchObject ( { status : 200 } ) ;
236+ expect ( String ( respond . mock . calls [ 0 ] ! [ 0 ] . body ) ) . toContain ( "composition" ) ;
237+ onRequest ( request ( "https://cdn.example/gsap.js" ) ) ;
238+ expect ( proceed ) . toHaveBeenCalledOnce ( ) ;
239+ } finally {
240+ await server . close ( ) ;
241+ rmSync ( dir , { recursive : true , force : true } ) ;
242+ }
243+ } ) ;
244+
245+ it ( "keeps the usual launch for a project served on a port" , async ( ) => {
246+ const opened = fakeBrowser ( ) ;
247+ mocks . launch . mockResolvedValue ( opened . browser ) ;
248+ await openSettledCompositionPage ( HTML , "http://127.0.0.1:3000" , OPTIONS ) ;
249+ expect ( launched ( ) . pipe ) . toBeUndefined ( ) ;
250+ expect ( launched ( ) . args ) . toEqual ( [ "--headless" ] ) ;
251+ expect ( opened . page . setRequestInterception ) . not . toHaveBeenCalled ( ) ;
252+ } ) ;
253+ } ) ;
0 commit comments