mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
test: reduce flakiness and types (#12347)
This commit is contained in:
parent
137236ee2a
commit
c2244d301a
@ -520,7 +520,7 @@ describe('network', function () {
|
||||
|
||||
const responses: HTTPResponse[] = [];
|
||||
page.on('response', response => {
|
||||
return responses.push(response);
|
||||
return !isFavicon(response) && responses.push(response);
|
||||
});
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
expect(responses).toHaveLength(1);
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
import {rm} from 'fs/promises';
|
||||
import {tmpdir} from 'os';
|
||||
import path from 'path';
|
||||
|
||||
import expect from 'expect';
|
||||
import type {Frame} from 'puppeteer-core/internal/api/Frame.js';
|
||||
@ -16,8 +15,6 @@ import {Deferred} from 'puppeteer-core/internal/util/Deferred.js';
|
||||
|
||||
import {compare} from './golden-utils.js';
|
||||
|
||||
const PROJECT_ROOT = path.join(__dirname, '..', '..');
|
||||
|
||||
declare module 'expect' {
|
||||
interface Matchers<R> {
|
||||
toBeGolden(pathOrBuffer: string | Buffer): R;
|
||||
@ -56,28 +53,26 @@ export const extendExpectWithToBeGolden = (
|
||||
});
|
||||
};
|
||||
|
||||
export const projectRoot = (): string => {
|
||||
return PROJECT_ROOT;
|
||||
};
|
||||
|
||||
export const attachFrame = async (
|
||||
pageOrFrame: Page | Frame,
|
||||
frameId: string,
|
||||
url: string
|
||||
): Promise<Frame | undefined> => {
|
||||
using handle = await pageOrFrame.evaluateHandle(attachFrame, frameId, url);
|
||||
return (await handle.asElement()?.contentFrame()) ?? undefined;
|
||||
|
||||
async function attachFrame(frameId: string, url: string) {
|
||||
const frame = document.createElement('iframe');
|
||||
frame.src = url;
|
||||
frame.id = frameId;
|
||||
document.body.appendChild(frame);
|
||||
await new Promise(x => {
|
||||
return (frame.onload = x);
|
||||
});
|
||||
return frame;
|
||||
}
|
||||
): Promise<Frame> => {
|
||||
using handle = await pageOrFrame.evaluateHandle(
|
||||
async (frameId, url) => {
|
||||
const frame = document.createElement('iframe');
|
||||
frame.src = url;
|
||||
frame.id = frameId;
|
||||
document.body.appendChild(frame);
|
||||
await new Promise(x => {
|
||||
return (frame.onload = x);
|
||||
});
|
||||
return frame;
|
||||
},
|
||||
frameId,
|
||||
url
|
||||
);
|
||||
return await handle.contentFrame();
|
||||
};
|
||||
|
||||
export const isFavicon = (request: {url: () => string | string[]}): boolean => {
|
||||
|
Loading…
Reference in New Issue
Block a user