11import * as path from 'path'
2- import * as puppeteer from 'puppeteer '
2+ import * as playwright from 'playwright '
33
44describe ( 'lib/extend.ts' , ( ) => {
5- let browser : puppeteer . Browser
6- let page : puppeteer . Page
7- let document : puppeteer . ElementHandle
5+ let browser : playwright . ChromiumBrowser
6+ let page : playwright . Page
7+ let document : playwright . ElementHandle
88
99 it ( 'should require without error' , async ( ) => {
1010 await import ( '../lib/extend' )
1111 } )
1212
13- it ( 'should launch puppeteer ' , async ( ) => {
14- browser = await puppeteer . launch ( { args : [ '--no-sandbox' , '--disable-setuid-sandbox' ] } )
13+ it ( 'should launch playwright ' , async ( ) => {
14+ browser = await playwright . chromium . launch ( { args : [ '--no-sandbox' , '--disable-setuid-sandbox' ] } )
1515 page = await browser . newPage ( )
1616 await page . goto ( `file://${ path . join ( __dirname , 'fixtures/page.html' ) } ` )
1717 } )
1818
19- it ( 'should extend puppeteer ElementHandle' , async ( ) => {
19+ it ( 'should extend playwright ElementHandle' , async ( ) => {
2020 document = await page . getDocument ( )
2121 expect ( typeof document . queryAllByAltText ) . toBe ( 'function' )
2222 } )
@@ -25,21 +25,21 @@ describe('lib/extend.ts', () => {
2525 const element = await document . queryByText ( 'Hello h1' )
2626 expect ( element ) . toBeTruthy ( )
2727 /* istanbul ignore next */
28- expect ( await page . evaluate ( el => el . textContent , element ) ) . toEqual ( 'Hello h1' )
28+ expect ( await page . evaluate ( el => el ? .textContent , element ) ) . toEqual ( 'Hello h1' )
2929 } )
3030
3131 it ( 'should use the new v3 methods' , async ( ) => {
3232 const element = await document . queryByRole ( 'presentation' )
3333 expect ( element ) . toBeTruthy ( )
3434 /* istanbul ignore next */
35- expect ( await page . evaluate ( el => el . textContent , element ) ) . toContain ( 'Layout table' )
35+ expect ( await page . evaluate ( el => el ? .textContent , element ) ) . toContain ( 'Layout table' )
3636 } )
3737
3838 it ( 'should handle regex matching' , async ( ) => {
3939 const element = await document . queryByText ( / H e L l O h ( 1 | 7 ) / i)
4040 expect ( element ) . toBeTruthy ( )
4141 /* istanbul ignore next */
42- expect ( await page . evaluate ( el => el . textContent , element ) ) . toEqual ( 'Hello h1' )
42+ expect ( await page . evaluate ( el => el ? .textContent , element ) ) . toEqual ( 'Hello h1' )
4343 } )
4444
4545 it ( 'should handle the get* methods' , async ( ) => {
@@ -56,9 +56,7 @@ describe('lib/extend.ts', () => {
5656 await scope ! . getByTitle ( 'missing' )
5757 fail ( )
5858 } catch ( err ) {
59- err . message = err . message
60- . replace ( / ( \s * a t .* ( \n | $ ) ) + / gm, '\n <stack>:X:X' )
61- . replace ( 'TestingLibraryElementError' , 'Error' ) // Puppeteer 1.7 returns a generic error
59+ err . message = err . message . replace ( / ( \s * a t .* ( \n | $ ) ) + / gm, '\n <stack>:X:X' )
6260 expect ( err . message ) . toMatchSnapshot ( )
6361 }
6462 } )
@@ -86,7 +84,7 @@ describe('lib/extend.ts', () => {
8684 const scope = await document . $ ( '#scoped' )
8785 const element = await scope ! . queryByText ( / H e l l o / )
8886 /* istanbul ignore next */
89- expect ( await page . evaluate ( el => el . textContent , element ) ) . toEqual ( 'Hello h3' )
87+ expect ( await page . evaluate ( el => el ? .textContent , element ) ) . toEqual ( 'Hello h3' )
9088 } )
9189
9290 it ( 'should get text content' , async ( ) => {
0 commit comments