From db4c6b1ed616536c08b58740401b5620a15da803 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Thu, 7 Mar 2024 10:44:55 -0600 Subject: [PATCH] fix pptr 20+ --- lib/extend.ts | 20 ++++++++++++-------- test/__snapshots__/extend.test.ts.snap | 7 ++----- test/extend.test.ts | 6 +++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/extend.ts b/lib/extend.ts index 1e28033..286e901 100644 --- a/lib/extend.ts +++ b/lib/extend.ts @@ -13,18 +13,22 @@ function requireOrUndefined(path: string): any { } try { - const libPrefix = requireOrUndefined(`puppeteer/lib/cjs/puppeteer/common/Page.js`) - ? 'puppeteer/lib/cjs/puppeteer/common' - : 'puppeteer/lib' + let apiPrefix = 'puppeteer-core/lib/cjs/puppeteer/api' // Puppeteer v18+ - Page = requireOrUndefined(`${libPrefix}/Page.js`) // tslint:disable-line + if (!requireOrUndefined(`${apiPrefix}/Page.js`)) { + apiPrefix = 'puppeteer/lib/cjs/common' // Puppeteer v5-v18 + } else if (!requireOrUndefined(`${apiPrefix}/Page.js`)) { + apiPrefix = 'puppeteer/lib' // Puppeteer "`; exports[`lib/extend.ts should handle the get* method failures 1`] = ` -"Evaluation failed: Error: Unable to find an element with the title: missing. - -
@@ -15,8 +13,7 @@ exports[`lib/extend.ts should handle the get* method failures 1`] = ` -
- :X:X" +" `; exports[`lib/extend.ts should handle the get* methods 1`] = `""`; diff --git a/test/extend.test.ts b/test/extend.test.ts index e9895aa..d7ad57e 100644 --- a/test/extend.test.ts +++ b/test/extend.test.ts @@ -57,9 +57,9 @@ describe('lib/extend.ts', () => { fail() } catch (err) { const message = (err as any).message - .replace(/(\s*at .*(\n|$))+/gm, '\n :X:X') - .replace('TestingLibraryElementError', 'Error') - expect(message).toMatchSnapshot() + expect(message).toContain('Unable to find an element with the title: missing') + const html = message.match(//) + expect(html[0]).toMatchSnapshot() } })