From aaa7158f32204745e466ff2fac0df362ea5b0bf4 Mon Sep 17 00:00:00 2001 From: Randolf J Date: Thu, 1 Sep 2022 17:14:00 +0200 Subject: [PATCH] chore: fix tests --- src/common/Frame.ts | 46 ++++++++++++------------------------------- test/src/page.spec.ts | 4 ++-- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/src/common/Frame.ts b/src/common/Frame.ts index 5d106f6a662ce..e947d716a57b2 100644 --- a/src/common/Frame.ts +++ b/src/common/Frame.ts @@ -752,7 +752,7 @@ export class Frame { const {path} = options; if (+!!options.url + +!!path + +!!content !== 1) { throw new Error( - 'Exactly one of `url`, `path`, or `content` may be specified.' + 'Exactly one of `url`, `path`, or `content` must be specified.' ); } @@ -772,31 +772,12 @@ export class Frame { content += `//# sourceURL=${path.replace(/\n/g, '')}`; } -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 2563c0600e (chore: fix tests) type = type ?? 'text/javascript'; return this.worlds[MAIN_WORLD].transferHandle( await this.worlds[PUPPETEER_WORLD].evaluateHandle( async ({url, id, type, content}) => { const script = document.createElement('script'); -<<<<<<< HEAD -======= - return this.worlds[PUPPETEER_WORLD].evaluateHandle( - async ({url, id, type, content}) => { - const script = document.createElement('script'); - if (url) { - script.src = url; - } - if (id) { - script.id = id; - } - if (type) { ->>>>>>> 571c30c3e5 (chore: remove unnecessary type signature) -======= ->>>>>>> 2563c0600e (chore: fix tests) script.type = type; script.text = content; if (url) { @@ -881,19 +862,18 @@ export class Frame { return this.worlds[MAIN_WORLD].transferHandle( await this.worlds[PUPPETEER_WORLD].evaluateHandle( async ({url, content}) => { - let element: HTMLLinkElement | HTMLStyleElement; - if (url) { - const link = document.createElement('link'); - link.rel = 'stylesheet'; - link.href = url; - element = link; - } else { - element = document.createElement('style'); - element.appendChild(document.createTextNode(content!)); + if (!url) { + const style = document.createElement('style'); + style.appendChild(document.createTextNode(content!)); + document.head.appendChild(style); + return style; } + const link = document.createElement('link'); + link.rel = 'stylesheet'; + link.href = url; const promise = new Promise((res, rej) => { - element.addEventListener('load', res, {once: true}); - element.addEventListener( + link.addEventListener('load', res, {once: true}); + link.addEventListener( 'error', event => { let message = 'Could not load style'; @@ -905,9 +885,9 @@ export class Frame { {once: true} ); }); - document.head.appendChild(element); + document.head.appendChild(link); await promise; - return element; + return link; }, options ) diff --git a/test/src/page.spec.ts b/test/src/page.spec.ts index c2708305d2822..31b997110251b 100644 --- a/test/src/page.spec.ts +++ b/test/src/page.spec.ts @@ -1631,7 +1631,7 @@ describe('Page', function () { error = error_ as Error; } expect(error.message).toBe( - 'Exactly one of `url`, `path`, or `content` may be specified.' + 'Exactly one of `url`, `path`, or `content` must be specified.' ); }); @@ -1797,7 +1797,7 @@ describe('Page', function () { error = error_ as Error; } expect(error.message).toBe( - 'Provide an object with a `url`, `path` or `content` property' + 'Exactly one of `url`, `path`, or `content` must be specified.' ); });