From 6bde6628c455be709a4767cb32bd3ba06f0c880c Mon Sep 17 00:00:00 2001 From: Randolf J Date: Wed, 22 Jun 2022 22:45:27 +0200 Subject: [PATCH] feat!: better TS types --- src/common/DOMWorld.ts | 1 - test/src/waittask.spec.ts | 117 -------------------------------------- 2 files changed, 118 deletions(-) diff --git a/src/common/DOMWorld.ts b/src/common/DOMWorld.ts index 11c726473e613..99b7b64b3c91b 100644 --- a/src/common/DOMWorld.ts +++ b/src/common/DOMWorld.ts @@ -578,7 +578,6 @@ export class DOMWorld { async function addStyleContent(content: string): Promise { const style = document.createElement('style'); - style.type = 'text/css'; style.appendChild(document.createTextNode(content)); const promise = new Promise((res, rej) => { style.onload = res; diff --git a/test/src/waittask.spec.ts b/test/src/waittask.spec.ts index 2e01ca3c8bfa5..b75d19f744931 100644 --- a/test/src/waittask.spec.ts +++ b/test/src/waittask.spec.ts @@ -15,7 +15,6 @@ */ import expect from 'expect'; -import sinon from 'sinon'; import {isErrorLike} from '../../lib/cjs/puppeteer/common/util.js'; import { getTestState, @@ -29,122 +28,6 @@ describe('waittask specs', function () { setupTestBrowserHooks(); setupTestPageAndContextHooks(); - describe('Page.waitFor', function () { - /* This method is deprecated but we don't want the warnings showing up in - * tests. Until we remove this method we still want to ensure we don't break - * it. - */ - beforeEach(() => { - return sinon.stub(console, 'warn').callsFake(() => {}); - }); - - it('should wait for selector', async () => { - const {page, server} = getTestState(); - - let found = false; - const waitFor = page.waitForSelector('div').then(() => { - return (found = true); - }); - await page.goto(server.EMPTY_PAGE); - expect(found).toBe(false); - await page.goto(server.PREFIX + '/grid.html'); - await waitFor; - expect(found).toBe(true); - }); - - it('should wait for an xpath', async () => { - const {page, server} = getTestState(); - - let found = false; - const waitFor = page.waitForXPath('//div').then(() => { - return (found = true); - }); - await page.goto(server.EMPTY_PAGE); - expect(found).toBe(false); - await page.goto(server.PREFIX + '/grid.html'); - await waitFor; - expect(found).toBe(true); - }); - it('should allow you to select an element with parenthesis-starting xpath', async () => { - const {page, server} = getTestState(); - let found = false; - const waitFor = page.waitForXPath('(//img)[200]').then(() => { - found = true; - }); - await page.goto(server.EMPTY_PAGE); - expect(found).toBe(false); - await page.goto(server.PREFIX + '/grid.html'); - await waitFor; - expect(found).toBe(true); - }); - it('should not allow you to select an element with single slash xpath', async () => { - const {page} = getTestState(); - - await page.setContent(`
some text
`); - let error!: Error; - await page.waitForXPath('/html/body/div').catch(error_ => { - return (error = error_); - }); - expect(error).toBeTruthy(); - }); - it('should timeout', async () => { - const {page} = getTestState(); - - const startTime = Date.now(); - const timeout = 42; - await page.waitForTimeout(timeout); - expect(Date.now() - startTime).not.toBeLessThan(timeout / 2); - }); - it('should work with multiline body', async () => { - const {page} = getTestState(); - - const result = await page.waitForFunction(` - (() => true)() - `); - expect(await result.jsonValue()).toBe(true); - }); - it('should wait for predicate', async () => { - const {page} = getTestState(); - - await Promise.all([ - page.waitForFunction(() => { - return window.innerWidth < 100; - }), - page.setViewport({width: 10, height: 10}), - ]); - }); - it('should wait for predicate with arguments', async () => { - const {page} = getTestState(); - - await page.waitForFunction( - (arg1, arg2) => { - return arg1 !== arg2; - }, - {}, - 1, - 2 - ); - }); - - it('should log a deprecation warning', async () => { - const {page} = getTestState(); - - await page.waitForFunction(() => { - return true; - }); - - const consoleWarnStub = console.warn as sinon.SinonSpy; - - expect(consoleWarnStub.calledOnce).toBe(true); - expect( - consoleWarnStub.firstCall.calledWith( - 'waitFor is deprecated and will be removed in a future release. See https://github.com/puppeteer/puppeteer/issues/6214 for details and how to migrate your code.' - ) - ).toBe(true); - expect((console.warn as sinon.SinonSpy).calledOnce).toBe(true); - }); - }); - describe('Frame.waitForFunction', function () { it('should accept a string', async () => { const {page} = getTestState();