From 6054f1479472a745c96537b9d4ab65fa01aa2778 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Tue, 11 Aug 2020 15:50:53 -0700 Subject: [PATCH] chore(tests): convert all tests to typescript (#3384) --- ...sibility.spec.js => accessibility.spec.ts} | 2 +- test/assets/shadow.html | 2 +- test/browsercontext-csp.spec.ts | 32 ++++---- test/browsercontext-expose-function.spec.ts | 4 +- test/browsercontext-locale.spec.ts | 2 +- ...c.js => browsertype-launch-server.spec.ts} | 18 ++--- test/channels.spec.ts | 2 +- .../{chromium.spec.js => chromium.spec.ts} | 17 +++-- .../{launcher.spec.js => launcher.spec.ts} | 13 ++-- test/chromium/oopif.spec.ts | 2 +- .../{session.spec.js => session.spec.ts} | 25 +++--- test/defaultbrowsercontext.spec.ts | 2 +- test/{dialog.spec.js => dialog.spec.ts} | 2 +- ...tchevent.spec.js => dispatchevent.spec.ts} | 44 ++++++----- test/electron/electron-app.spec.ts | 2 +- ....js => elementhandle-bounding-box.spec.ts} | 6 +- ...ck.spec.js => elementhandle-click.spec.ts} | 18 ++--- ...js => elementhandle-content-frame.spec.ts} | 4 +- ...c.js => elementhandle-convenience.spec.ts} | 24 +++--- ...=> elementhandle-eval-on-selector.spec.ts} | 16 ++-- ...isc.spec.js => elementhandle-misc.spec.ts} | 16 ++-- ...c.js => elementhandle-owner-frame.spec.ts} | 10 +-- ...ss.spec.js => elementhandle-press.spec.ts} | 4 +- ...s => elementhandle-query-selector.spec.ts} | 10 +-- ...ec.js => elementhandle-screenshot.spec.ts} | 16 ++-- ...=> elementhandle-scroll-into-view.spec.ts} | 4 +- ...c.js => elementhandle-select-text.spec.ts} | 4 +- ...ype.spec.js => elementhandle-type.spec.ts} | 4 +- ...-focus.spec.js => emulation-focus.spec.ts} | 10 +-- ...l.spec.js => eval-on-selector-all.spec.ts} | 6 +- ...ector.spec.js => eval-on-selector.spec.ts} | 6 +- .../{launcher.spec.js => launcher.spec.ts} | 2 +- test/{focus.spec.js => focus.spec.ts} | 24 +++--- ...valuate.spec.js => frame-evaluate.spec.ts} | 26 +++---- ...nt.spec.js => frame-frame-element.spec.ts} | 4 +- ...{frame-goto.spec.js => frame-goto.spec.ts} | 8 +- ...rarchy.spec.js => frame-hierarchy.spec.ts} | 12 +-- ...eolocation.spec.js => geolocation.spec.ts} | 10 +-- test/{headful.spec.js => headful.spec.ts} | 4 +- ...rors.spec.js => ignorehttpserrors.spec.ts} | 2 +- ...erception.spec.js => interception.spec.ts} | 18 ++--- ...nt.spec.js => jshandle-as-element.spec.ts} | 4 +- ...uate.spec.js => jshandle-evaluate.spec.ts} | 8 +- ...ue.spec.js => jshandle-json-value.spec.ts} | 2 +- ...es.spec.js => jshandle-properties.spec.ts} | 4 +- ...ing.spec.js => jshandle-to-string.spec.ts} | 2 +- test/{keyboard.spec.js => keyboard.spec.ts} | 12 +-- test/{launcher.spec.js => launcher.spec.ts} | 8 +- test/{logger.spec.js => logger.spec.ts} | 6 +- test/{mouse.spec.js => mouse.spec.ts} | 26 +++---- ...ulticlient.spec.js => multiclient.spec.ts} | 4 +- ...{navigation.spec.js => navigation.spec.ts} | 2 +- ...equest.spec.js => network-request.spec.ts} | 8 +- ...ponse.spec.js => network-response.spec.ts} | 8 +- ...t.spec.js => page-add-init-script.spec.ts} | 50 ++++++------ ...ag.spec.js => page-add-script-tag.spec.ts} | 27 +++---- ...tag.spec.js => page-add-style-tag.spec.ts} | 9 ++- ...{page-basic.spec.js => page-basic.spec.ts} | 8 +- ...dia.spec.js => page-emulate-media.spec.ts} | 10 +-- ...e.spec.js => page-evaluate-handle.spec.ts} | 8 +- ...evaluate.spec.js => page-evaluate.spec.ts} | 65 ++++++++++------ ...ole.spec.js => page-event-console.spec.ts} | 10 +-- ...crash.spec.js => page-event-crash.spec.ts} | 8 +- ...ork.spec.js => page-event-network.spec.ts} | 10 +-- ...r.spec.js => page-event-pageerror.spec.ts} | 6 +- ...popup.spec.js => page-event-popup.spec.ts} | 14 ++-- ...est.spec.js => page-event-request.spec.ts} | 12 +-- ...n.spec.js => page-expose-function.spec.ts} | 38 +++++----- test/{page-fill.spec.js => page-fill.spec.ts} | 42 +++++----- test/{page-goto.spec.js => page-goto.spec.ts} | 22 +++--- ...e-history.spec.js => page-history.spec.ts} | 10 +-- ...idle.spec.js => page-network-idle.spec.ts} | 30 ++++---- ...{page-route.spec.js => page-route.spec.ts} | 10 +-- ...enshot.spec.js => page-screenshot.spec.ts} | 6 +- ...ion.spec.js => page-select-option.spec.ts} | 76 +++++++++---------- ...ntent.spec.js => page-set-content.spec.ts} | 8 +- ...js => page-set-extra-http-headers.spec.ts} | 10 +-- ...s.spec.js => page-set-input-files.spec.ts} | 8 +- ...ec.js => page-wait-for-load-state.spec.ts} | 21 ++--- ...ec.js => page-wait-for-navigation.spec.ts} | 14 ++-- ....spec.js => page-wait-for-request.spec.ts} | 8 +- ...spec.js => page-wait-for-response.spec.ts} | 10 +-- ...ermissions.spec.js => permissions.spec.ts} | 4 +- test/{popup.spec.js => popup.spec.ts} | 20 ++--- test/{proxy.spec.js => proxy.spec.ts} | 6 +- ...selector.spec.js => queryselector.spec.ts} | 6 +- ...tinue.spec.js => request-continue.spec.ts} | 10 +-- ...ulfill.spec.js => request-fulfill.spec.ts} | 14 ++-- ...{screencast.spec.js => screencast.spec.ts} | 9 ++- ...tors-css.spec.js => selectors-css.spec.ts} | 16 ++-- ...rs-misc.spec.js => selectors-misc.spec.ts} | 6 +- ...ter.spec.js => selectors-register.spec.ts} | 18 ++--- ...rs-text.spec.js => selectors-text.spec.ts} | 18 ++--- ...tion.spec.js => wait-for-function.spec.ts} | 53 ++++++------- ...ctor.spec.js => wait-for-selector.spec.ts} | 18 +++-- test/{workers.spec.js => workers.spec.ts} | 7 +- utils/testserver/index.d.ts | 4 +- 97 files changed, 662 insertions(+), 628 deletions(-) rename test/{accessibility.spec.js => accessibility.spec.ts} (99%) rename test/{browsertype-launch-server.spec.js => browsertype-launch-server.spec.ts} (94%) rename test/chromium/{chromium.spec.js => chromium.spec.ts} (84%) rename test/chromium/{launcher.spec.js => launcher.spec.ts} (90%) rename test/chromium/{session.spec.js => session.spec.ts} (78%) rename test/{dialog.spec.js => dialog.spec.ts} (99%) rename test/{dispatchevent.spec.js => dispatchevent.spec.ts} (79%) rename test/{elementhandle-bounding-box.spec.js => elementhandle-bounding-box.spec.ts} (97%) rename test/{elementhandle-click.spec.js => elementhandle-click.spec.ts} (87%) rename test/{elementhandle-content-frame.spec.js => elementhandle-content-frame.spec.ts} (97%) rename test/{elementhandle-convenience.spec.js => elementhandle-convenience.spec.ts} (90%) rename test/{elementhandle-eval-on-selector.spec.js => elementhandle-eval-on-selector.spec.ts} (85%) rename test/{elementhandle-misc.spec.js => elementhandle-misc.spec.ts} (84%) rename test/{elementhandle-owner-frame.spec.js => elementhandle-owner-frame.spec.ts} (93%) rename test/{elementhandle-press.spec.js => elementhandle-press.spec.ts} (97%) rename test/{elementhandle-query-selector.spec.js => elementhandle-query-selector.spec.ts} (94%) rename test/{elementhandle-screenshot.spec.js => elementhandle-screenshot.spec.ts} (98%) rename test/{elementhandle-scroll-into-view.spec.js => elementhandle-scroll-into-view.spec.ts} (98%) rename test/{elementhandle-select-text.spec.js => elementhandle-select-text.spec.ts} (97%) rename test/{elementhandle-type.spec.js => elementhandle-type.spec.ts} (97%) rename test/{emulation-focus.spec.js => emulation-focus.spec.ts} (95%) rename test/{eval-on-selector-all.spec.js => eval-on-selector-all.spec.ts} (97%) rename test/{eval-on-selector.spec.js => eval-on-selector.spec.ts} (99%) rename test/firefox/{launcher.spec.js => launcher.spec.ts} (97%) rename test/{focus.spec.js => focus.spec.ts} (78%) rename test/{frame-evaluate.spec.js => frame-evaluate.spec.ts} (91%) rename test/{frame-frame-element.spec.js => frame-frame-element.spec.ts} (97%) rename test/{frame-goto.spec.js => frame-goto.spec.ts} (96%) rename test/{frame-hierarchy.spec.js => frame-hierarchy.spec.ts} (96%) rename test/{geolocation.spec.js => geolocation.spec.ts} (95%) rename test/{headful.spec.js => headful.spec.ts} (99%) rename test/{ignorehttpserrors.spec.js => ignorehttpserrors.spec.ts} (99%) rename test/{interception.spec.js => interception.spec.ts} (91%) rename test/{jshandle-as-element.spec.js => jshandle-as-element.spec.ts} (93%) rename test/{jshandle-evaluate.spec.js => jshandle-evaluate.spec.ts} (87%) rename test/{jshandle-json-value.spec.js => jshandle-json-value.spec.ts} (98%) rename test/{jshandle-properties.spec.js => jshandle-properties.spec.ts} (98%) rename test/{jshandle-to-string.spec.js => jshandle-to-string.spec.ts} (99%) rename test/{keyboard.spec.js => keyboard.spec.ts} (97%) rename test/{launcher.spec.js => launcher.spec.ts} (91%) rename test/{logger.spec.js => logger.spec.ts} (96%) rename test/{mouse.spec.js => mouse.spec.ts} (89%) rename test/{multiclient.spec.js => multiclient.spec.ts} (97%) rename test/{navigation.spec.js => navigation.spec.ts} (97%) rename test/{network-request.spec.js => network-request.spec.ts} (98%) rename test/{network-response.spec.js => network-response.spec.ts} (97%) rename test/{page-add-init-script.spec.js => page-add-init-script.spec.ts} (69%) rename test/{page-add-script-tag.spec.js => page-add-script-tag.spec.ts} (84%) rename test/{page-add-style-tag.spec.js => page-add-style-tag.spec.ts} (96%) rename test/{page-basic.spec.js => page-basic.spec.ts} (98%) rename test/{page-emulate-media.spec.js => page-emulate-media.spec.ts} (95%) rename test/{page-evaluate-handle.spec.js => page-evaluate-handle.spec.ts} (96%) rename test/{page-evaluate.spec.js => page-evaluate.spec.ts} (93%) rename test/{page-event-console.spec.js => page-event-console.spec.ts} (97%) rename test/{page-event-crash.spec.js => page-event-crash.spec.ts} (96%) rename test/{page-event-network.spec.js => page-event-network.spec.ts} (97%) rename test/{page-event-pageerror.spec.js => page-event-pageerror.spec.ts} (95%) rename test/{page-event-popup.spec.js => page-event-popup.spec.ts} (91%) rename test/{page-event-request.spec.js => page-event-request.spec.ts} (90%) rename test/{page-expose-function.spec.js => page-expose-function.spec.ts} (86%) rename test/{page-fill.spec.js => page-fill.spec.ts} (86%) rename test/{page-goto.spec.js => page-goto.spec.ts} (97%) rename test/{page-history.spec.js => page-history.spec.ts} (94%) rename test/{page-network-idle.spec.js => page-network-idle.spec.ts} (90%) rename test/{page-route.spec.js => page-route.spec.ts} (99%) rename test/{page-screenshot.spec.js => page-screenshot.spec.ts} (99%) rename test/{page-select-option.spec.js => page-select-option.spec.ts} (73%) rename test/{page-set-content.spec.js => page-set-content.spec.ts} (97%) rename test/{page-set-extra-http-headers.spec.js => page-set-extra-http-headers.spec.ts} (93%) rename test/{page-set-input-files.spec.js => page-set-input-files.spec.ts} (98%) rename test/{page-wait-for-load-state.spec.js => page-wait-for-load-state.spec.ts} (91%) rename test/{page-wait-for-navigation.spec.js => page-wait-for-navigation.spec.ts} (97%) rename test/{page-wait-for-request.spec.js => page-wait-for-request.spec.ts} (96%) rename test/{page-wait-for-response.spec.js => page-wait-for-response.spec.ts} (91%) rename test/{permissions.spec.js => permissions.spec.ts} (99%) rename test/{popup.spec.js => popup.spec.ts} (93%) rename test/{proxy.spec.js => proxy.spec.ts} (98%) rename test/{queryselector.spec.js => queryselector.spec.ts} (97%) rename test/{request-continue.spec.js => request-continue.spec.ts} (96%) rename test/{request-fulfill.spec.js => request-fulfill.spec.ts} (96%) rename test/{screencast.spec.js => screencast.spec.ts} (95%) rename test/{selectors-css.spec.js => selectors-css.spec.ts} (95%) rename test/{selectors-misc.spec.js => selectors-misc.spec.ts} (93%) rename test/{selectors-register.spec.js => selectors-register.spec.ts} (88%) rename test/{selectors-text.spec.js => selectors-text.spec.ts} (93%) rename test/{wait-for-function.spec.js => wait-for-function.spec.ts} (82%) rename test/{wait-for-selector.spec.js => wait-for-selector.spec.ts} (97%) rename test/{workers.spec.js => workers.spec.ts} (96%) diff --git a/test/accessibility.spec.js b/test/accessibility.spec.ts similarity index 99% rename from test/accessibility.spec.js rename to test/accessibility.spec.ts index 858359aa00..6e8a3ff316 100644 --- a/test/accessibility.spec.js +++ b/test/accessibility.spec.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; const {FFOX, CHROMIUM, WEBKIT} = testOptions; diff --git a/test/assets/shadow.html b/test/assets/shadow.html index 7242e673b5..d1fd331eb2 100644 --- a/test/assets/shadow.html +++ b/test/assets/shadow.html @@ -1,7 +1,7 @@ '); + await page.goto('data:text/html,'); expect(await page.evaluate(() => window['result'])).toBe(42); }); diff --git a/test/elementhandle-bounding-box.spec.js b/test/elementhandle-bounding-box.spec.ts similarity index 97% rename from test/elementhandle-bounding-box.spec.js rename to test/elementhandle-bounding-box.spec.ts index e71b7c1e78..6d2567b249 100644 --- a/test/elementhandle-bounding-box.spec.js +++ b/test/elementhandle-bounding-box.spec.ts @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const utils = require('./utils'); +import utils from './utils'; const { FFOX, HEADLESS } = testOptions; it.fail(FFOX && !HEADLESS)('should work', async ({ page, server }) => { @@ -67,7 +67,7 @@ it('should work with SVG nodes', async ({ page, server }) => { }); it.skip(FFOX)('should work with page scale', async ({ browser, server }) => { - const context = await browser.newContext({ viewport: { width: 400, height: 400, isMobile: true } }); + const context = await browser.newContext({ viewport: { width: 400, height: 400 }, isMobile: true }); const page = await context.newPage(); await page.goto(server.PREFIX + '/input/button.html'); const button = await page.$('button'); diff --git a/test/elementhandle-click.spec.js b/test/elementhandle-click.spec.ts similarity index 87% rename from test/elementhandle-click.spec.js rename to test/elementhandle-click.spec.ts index eb854a6e90..38bca7874f 100644 --- a/test/elementhandle-click.spec.js +++ b/test/elementhandle-click.spec.ts @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const utils = require('./utils'); +import utils from './utils'; const { FFOX, HEADLESS } = testOptions; it('should work', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/button.html'); const button = await page.$('button'); await button.click(); - expect(await page.evaluate(() => result)).toBe('Clicked'); + expect(await page.evaluate(() => window['result'])).toBe('Clicked'); }); it('should work with Node removed', async ({ page, server }) => { @@ -31,21 +31,21 @@ it('should work with Node removed', async ({ page, server }) => { await page.evaluate(() => delete window['Node']); const button = await page.$('button'); await button.click(); - expect(await page.evaluate(() => result)).toBe('Clicked'); + expect(await page.evaluate(() => window['result'])).toBe('Clicked'); }); it('should work for Shadow DOM v1', async ({ page, server }) => { await page.goto(server.PREFIX + '/shadow.html'); - const buttonHandle = await page.evaluateHandle(() => button); + const buttonHandle = await page.evaluateHandle(() => window['button'] as HTMLButtonElement); await buttonHandle.click(); - expect(await page.evaluate(() => clicked)).toBe(true); + expect(await page.evaluate('clicked')).toBe(true); }); it('should work for TextNodes', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/button.html'); const buttonTextNode = await page.evaluateHandle(() => document.querySelector('button').firstChild); await buttonTextNode.click(); - expect(await page.evaluate(() => result)).toBe('Clicked'); + expect(await page.evaluate(() => window['result'])).toBe('Clicked'); }); it('should throw for detached nodes', async ({ page, server }) => { @@ -83,10 +83,10 @@ it('should throw for
elements with force', async ({ page, server }) => { it('should double click the button', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/button.html'); await page.evaluate(() => { - window.double = false; + window['double'] = false; const button = document.querySelector('button'); button.addEventListener('dblclick', event => { - window.double = true; + window['double'] = true; }); }); const button = await page.$('button'); diff --git a/test/elementhandle-content-frame.spec.js b/test/elementhandle-content-frame.spec.ts similarity index 97% rename from test/elementhandle-content-frame.spec.js rename to test/elementhandle-content-frame.spec.ts index 9ad8f1096d..8642d22eed 100644 --- a/test/elementhandle-content-frame.spec.js +++ b/test/elementhandle-content-frame.spec.ts @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const utils = require('./utils'); +import utils from './utils'; const { FFOX, HEADLESS } = testOptions; it('should work', async ({ page, server }) => { diff --git a/test/elementhandle-convenience.spec.js b/test/elementhandle-convenience.spec.ts similarity index 90% rename from test/elementhandle-convenience.spec.js rename to test/elementhandle-convenience.spec.ts index 091a651123..2e20d5d08d 100644 --- a/test/elementhandle-convenience.spec.js +++ b/test/elementhandle-convenience.spec.ts @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const utils = require('./utils'); +import utils from './utils'; const { FFOX, HEADLESS } = testOptions; it('should have a nice preview', async ({ page, server }) => { @@ -80,10 +80,10 @@ it('textContent should be atomic', async ({ playwright, page }) => { Promise.resolve().then(() => result.textContent = 'modified'); return result; }, - queryAll(root, selector) { + queryAll(root: HTMLElement, selector: string) { const result = Array.from(root.querySelectorAll(selector)); for (const e of result) - Promise.resolve().then(() => result.textContent = 'modified'); + Promise.resolve().then(() => e.textContent = 'modified'); return result; } }); @@ -97,16 +97,16 @@ it('textContent should be atomic', async ({ playwright, page }) => { it('innerText should be atomic', async ({ playwright, page }) => { const createDummySelector = () => ({ create(root, target) { }, - query(root, selector) { + query(root: HTMLElement, selector: string) { const result = root.querySelector(selector); if (result) Promise.resolve().then(() => result.textContent = 'modified'); return result; }, - queryAll(root, selector) { + queryAll(root: HTMLElement, selector: string) { const result = Array.from(root.querySelectorAll(selector)); for (const e of result) - Promise.resolve().then(() => result.textContent = 'modified'); + Promise.resolve().then(() => e.textContent = 'modified'); return result; } }); @@ -126,10 +126,10 @@ it('innerHTML should be atomic', async ({ playwright, page }) => { Promise.resolve().then(() => result.textContent = 'modified'); return result; }, - queryAll(root, selector) { + queryAll(root: HTMLElement, selector: string) { const result = Array.from(root.querySelectorAll(selector)); for (const e of result) - Promise.resolve().then(() => result.textContent = 'modified'); + Promise.resolve().then(() => e.textContent = 'modified'); return result; } }); @@ -143,16 +143,16 @@ it('innerHTML should be atomic', async ({ playwright, page }) => { it('getAttribute should be atomic', async ({ playwright, page }) => { const createDummySelector = () => ({ create(root, target) { }, - query(root, selector) { + query(root: HTMLElement, selector: string) { const result = root.querySelector(selector); if (result) Promise.resolve().then(() => result.setAttribute('foo', 'modified')); return result; }, - queryAll(root, selector) { + queryAll(root: HTMLElement, selector: string) { const result = Array.from(root.querySelectorAll(selector)); for (const e of result) - Promise.resolve().then(() => result.setAttribute('foo', 'modified')); + Promise.resolve().then(() => (e as HTMLElement).setAttribute('foo', 'modified')); return result; } }); diff --git a/test/elementhandle-eval-on-selector.spec.js b/test/elementhandle-eval-on-selector.spec.ts similarity index 85% rename from test/elementhandle-eval-on-selector.spec.js rename to test/elementhandle-eval-on-selector.spec.ts index 4884548502..5d8c72315f 100644 --- a/test/elementhandle-eval-on-selector.spec.js +++ b/test/elementhandle-eval-on-selector.spec.ts @@ -14,16 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const path = require('path'); -const utils = require('./utils'); +import path from 'path'; +import utils from './utils'; const {FFOX, CHROMIUM, WEBKIT, CHANNEL, USES_HOOKS} = testOptions; it('should work', async({page, server}) => { await page.setContent('
10
'); const tweet = await page.$('.tweet'); - const content = await tweet.$eval('.like', node => node.innerText); + const content = await tweet.$eval('.like', node => (node as HTMLElement).innerText); expect(content).toBe('100'); }); @@ -31,7 +31,7 @@ it('should retrieve content from subtree', async({page, server}) => { const htmlContent = '
not-a-child-div
a-child-div
'; await page.setContent(htmlContent); const elementHandle = await page.$('#myId'); - const content = await elementHandle.$eval('.a', node => node.innerText); + const content = await elementHandle.$eval('.a', node => (node as HTMLElement).innerText); expect(content).toBe('a-child-div'); }); @@ -39,14 +39,14 @@ it('should throw in case of missing selector', async({page, server}) => { const htmlContent = '
not-a-child-div
'; await page.setContent(htmlContent); const elementHandle = await page.$('#myId'); - const errorMessage = await elementHandle.$eval('.a', node => node.innerText).catch(error => error.message); + const errorMessage = await elementHandle.$eval('.a', node => (node as HTMLElement).innerText).catch(error => error.message); expect(errorMessage).toContain(`Error: failed to find element matching selector ".a"`); }); it('should work for all', async({page, server}) => { await page.setContent('
'); const tweet = await page.$('.tweet'); - const content = await tweet.$$eval('.like', nodes => nodes.map(n => n.innerText)); + const content = await tweet.$$eval('.like', nodes => nodes.map(n => (n as HTMLElement).innerText)); expect(content).toEqual(['100', '10']); }); @@ -54,7 +54,7 @@ it('should retrieve content from subtree for all', async({page, server}) => { const htmlContent = '
not-a-child-div
a1-child-div
a2-child-div
'; await page.setContent(htmlContent); const elementHandle = await page.$('#myId'); - const content = await elementHandle.$$eval('.a', nodes => nodes.map(n => n.innerText)); + const content = await elementHandle.$$eval('.a', nodes => nodes.map(n => (n as HTMLElement).innerText)); expect(content).toEqual(['a1-child-div', 'a2-child-div']); }); diff --git a/test/elementhandle-misc.spec.js b/test/elementhandle-misc.spec.ts similarity index 84% rename from test/elementhandle-misc.spec.js rename to test/elementhandle-misc.spec.ts index 3bdb607ced..5cf08e8471 100644 --- a/test/elementhandle-misc.spec.js +++ b/test/elementhandle-misc.spec.ts @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const utils = require('./utils'); +import utils from './utils'; const { FFOX, HEADLESS } = testOptions; it('should hover', async ({ page, server }) => { @@ -38,7 +38,7 @@ it('should fill input', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/textarea.html'); const handle = await page.$('input'); await handle.fill('some value'); - expect(await page.evaluate(() => result)).toBe('some value'); + expect(await page.evaluate(() => window['result'])).toBe('some value'); }); it('should fill input when Node is removed', async ({ page, server }) => { @@ -46,29 +46,29 @@ it('should fill input when Node is removed', async ({ page, server }) => { await page.evaluate(() => delete window['Node']); const handle = await page.$('input'); await handle.fill('some value'); - expect(await page.evaluate(() => result)).toBe('some value'); + expect(await page.evaluate(() => window['result'])).toBe('some value'); }); it('should check the box', async ({ page }) => { await page.setContent(``); const input = await page.$('input'); await input.check(); - expect(await page.evaluate(() => checkbox.checked)).toBe(true); + expect(await page.evaluate('checkbox.checked')).toBe(true); }); it('should uncheck the box', async ({ page }) => { await page.setContent(``); const input = await page.$('input'); await input.uncheck(); - expect(await page.evaluate(() => checkbox.checked)).toBe(false); + expect(await page.evaluate('checkbox.checked')).toBe(false); }); it('should select single option', async ({ page, server }) => { await page.goto(server.PREFIX + '/input/select.html'); const select = await page.$('select'); await select.selectOption('blue'); - expect(await page.evaluate(() => result.onInput)).toEqual(['blue']); - expect(await page.evaluate(() => result.onChange)).toEqual(['blue']); + expect(await page.evaluate(() => window['result'].onInput)).toEqual(['blue']); + expect(await page.evaluate(() => window['result'].onChange)).toEqual(['blue']); }); it('should focus a button', async ({ page, server }) => { diff --git a/test/elementhandle-owner-frame.spec.js b/test/elementhandle-owner-frame.spec.ts similarity index 93% rename from test/elementhandle-owner-frame.spec.js rename to test/elementhandle-owner-frame.spec.ts index 101e3a9d48..6539951a74 100644 --- a/test/elementhandle-owner-frame.spec.js +++ b/test/elementhandle-owner-frame.spec.ts @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const utils = require('./utils'); +import utils from './utils'; const { FFOX, HEADLESS } = testOptions; it('should work', async ({ page, server }) => { @@ -55,7 +55,7 @@ it('should work for cross-frame evaluations', async ({ page, server }) => { await page.goto(server.EMPTY_PAGE); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); const frame = page.mainFrame(); - const elementHandle = await frame.evaluateHandle(() => document.querySelector('#frame1').contentWindow.document.body); + const elementHandle = await frame.evaluateHandle(() => document.querySelector('iframe').contentWindow.document.body); expect(await elementHandle.ownerFrame()).toBe(frame.childFrames()[0]); }); @@ -78,7 +78,7 @@ it('should work for adopted elements', async ({ page, server }) => { await page.goto(server.EMPTY_PAGE); const [popup] = await Promise.all([ page.waitForEvent('popup'), - page.evaluate(url => window.__popup = window.open(url), server.EMPTY_PAGE), + page.evaluate(url => window["__popup"] = window.open(url), server.EMPTY_PAGE), ]); const divHandle = await page.evaluateHandle(() => { const div = document.createElement('div'); @@ -89,7 +89,7 @@ it('should work for adopted elements', async ({ page, server }) => { await popup.waitForLoadState('domcontentloaded'); await page.evaluate(() => { const div = document.querySelector('div'); - window.__popup.document.body.appendChild(div); + window["__popup"].document.body.appendChild(div); }); expect(await divHandle.ownerFrame()).toBe(popup.mainFrame()); }); diff --git a/test/elementhandle-press.spec.js b/test/elementhandle-press.spec.ts similarity index 97% rename from test/elementhandle-press.spec.js rename to test/elementhandle-press.spec.ts index 184e8d001c..6478190501 100644 --- a/test/elementhandle-press.spec.js +++ b/test/elementhandle-press.spec.ts @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const utils = require('./utils'); +import utils from './utils'; const { FFOX, HEADLESS } = testOptions; it('should work', async ({ page }) => { diff --git a/test/elementhandle-query-selector.spec.js b/test/elementhandle-query-selector.spec.ts similarity index 94% rename from test/elementhandle-query-selector.spec.js rename to test/elementhandle-query-selector.spec.ts index 55686fb364..9b1d2b1b5e 100644 --- a/test/elementhandle-query-selector.spec.js +++ b/test/elementhandle-query-selector.spec.ts @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const path = require('path'); -const utils = require('./utils'); +import path from 'path'; +import utils from './utils'; const {FFOX, CHROMIUM, WEBKIT, CHANNEL, USES_HOOKS} = testOptions; it('should query existing element', async({page, server}) => { @@ -41,7 +41,7 @@ it('should work for adopted elements', async({page,server}) => { await page.goto(server.EMPTY_PAGE); const [popup] = await Promise.all([ page.waitForEvent('popup'), - page.evaluate(url => window.__popup = window.open(url), server.EMPTY_PAGE), + page.evaluate(url => window["__popup"] = window.open(url), server.EMPTY_PAGE), ]); const divHandle = await page.evaluateHandle(() => { const div = document.createElement('div'); @@ -57,7 +57,7 @@ it('should work for adopted elements', async({page,server}) => { await popup.waitForLoadState('domcontentloaded'); await page.evaluate(() => { const div = document.querySelector('div'); - window.__popup.document.body.appendChild(div); + window["__popup"].document.body.appendChild(div); }); expect(await divHandle.$('span')).toBeTruthy(); expect(await divHandle.$eval('span', e => e.textContent)).toBe('hello'); diff --git a/test/elementhandle-screenshot.spec.js b/test/elementhandle-screenshot.spec.ts similarity index 98% rename from test/elementhandle-screenshot.spec.js rename to test/elementhandle-screenshot.spec.ts index 67b36971ca..61f9e291b6 100644 --- a/test/elementhandle-screenshot.spec.js +++ b/test/elementhandle-screenshot.spec.ts @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('./base.fixture'); +import './base.fixture'; -const utils = require('./utils'); +import utils from './utils'; const {FFOX, CHROMIUM, WEBKIT, USES_HOOKS, HEADLESS} = testOptions; -const {PNG} = require('pngjs'); +import {PNG} from 'pngjs'; // Firefox headful produces a different image. const ffheadful = FFOX && !HEADLESS; @@ -210,7 +210,7 @@ it.skip(ffheadful)('should work for an element with fractional dimensions', asyn }); it.skip(FFOX)('should work with a mobile viewport', async({browser, server}) => { - const context = await browser.newContext({viewport: { width: 320, height: 480, isMobile: true }}); + const context = await browser.newContext({viewport: { width: 320, height: 480 }, isMobile: true}); const page = await context.newPage(); await page.goto(server.PREFIX + '/grid.html'); await page.evaluate(() => window.scrollBy(50, 100)); @@ -288,7 +288,7 @@ it.skip(ffheadful || USES_HOOKS)('should restore viewport after page screenshot const page = await context.newPage(); await page.goto(server.PREFIX + '/grid.html'); const __testHookBeforeScreenshot = () => { throw new Error('oh my') }; - const error = await page.screenshot({ fullPage: true, __testHookBeforeScreenshot }).catch(e => e); + const error = await page.screenshot({ fullPage: true, __testHookBeforeScreenshot } as any).catch(e => e); expect(error.message).toContain('oh my'); await utils.verifyViewport(page, 350, 360); await context.close(); @@ -299,7 +299,7 @@ it.skip(ffheadful || USES_HOOKS)('should restore viewport after page screenshot const page = await context.newPage(); await page.goto(server.PREFIX + '/grid.html'); const __testHookAfterScreenshot = () => new Promise(f => setTimeout(f, 5000)); - const error = await page.screenshot({ fullPage: true, __testHookAfterScreenshot, timeout: 3000 }).catch(e => e); + const error = await page.screenshot({ fullPage: true, __testHookAfterScreenshot, timeout: 3000 } as any).catch(e => e); expect(error.message).toContain('page.screenshot: Timeout 3000ms exceeded'); await utils.verifyViewport(page, 350, 360); await page.setViewportSize({ width: 400, height: 400 }); @@ -310,7 +310,7 @@ it.skip(ffheadful || USES_HOOKS)('should restore viewport after page screenshot it.skip(ffheadful)('should take element screenshot when default viewport is null and restore back', async({server, browser}) => { const context = await browser.newContext({viewport: null}); - const page = await context.newPage({ viewport: null }); + const page = await context.newPage(); await page.setContent(`
oooo