Skip to content

Commit

Permalink
feat!: better TS types
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Jun 22, 2022
1 parent 4b2a6c6 commit 6bde662
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 118 deletions.
1 change: 0 additions & 1 deletion src/common/DOMWorld.ts
Expand Up @@ -578,7 +578,6 @@ export class DOMWorld {

async function addStyleContent(content: string): Promise<HTMLElement> {
const style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(content));
const promise = new Promise((res, rej) => {
style.onload = res;
Expand Down
117 changes: 0 additions & 117 deletions test/src/waittask.spec.ts
Expand Up @@ -15,7 +15,6 @@
*/

import expect from 'expect';
import sinon from 'sinon';
import {isErrorLike} from '../../lib/cjs/puppeteer/common/util.js';
import {
getTestState,
Expand All @@ -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(`<div>some text</div>`);
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();
Expand Down

0 comments on commit 6bde662

Please sign in to comment.