import * as SUT from '../index' ; import { sleep } from '../../../../utils' ; import { Browser , chromium } from 'playwright' ; import { FakeServer } from 'simple-fake-server' ; import * as path from 'path' ; describe ( 'record page errors' , ( ) : void => { let browser = undefined ; let fakeServer = undefined ; beforeAll ( ( ) => { fakeServer = new FakeServer ( 1238 ) ; fakeServer . start ( ) ; } ) ; afterAll ( ( ) => { if ( fakeServer ) { fakeServer . stop ( ) ; } } ) ; beforeEach ( ( ) : void => { } ) ; afterEach ( async ( ) : Promise < void > => { if ( browser ) { await browser . close ( ) ; } } ) ; test ( 'should record page errors' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const context = await browser . newContext ( { viewport : null } ) ; const page = await context . newPage ( ) ; const errors = [ ] ; const callback = ( request ) => errors . push ( request ) ; await SUT . recordPageErrors ( page , callback ) ; await page . goto ( `file:${ path . join ( __dirname , 'record-page-errors.test.html' ) }` ) ; await sleep ( 3000 ) ; expect ( errors . length ) . toBe ( 1 ) ; expect ( errors [ 0 ] . message ) . toContain ( 'Oops' ) ; } ) ; } ) ;