mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
test: fix leaky newPage calls (#11868)
This commit is contained in:
parent
7d1541de68
commit
4227be34c0
@ -30,7 +30,7 @@ describe('Target.createCDPSession', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not report created targets for custom CDP sessions', async () => {
|
it('should not report created targets for custom CDP sessions', async () => {
|
||||||
const {browser} = await getTestState();
|
const {context} = await getTestState();
|
||||||
let called = 0;
|
let called = 0;
|
||||||
const handler = async (target: Target) => {
|
const handler = async (target: Target) => {
|
||||||
called++;
|
called++;
|
||||||
@ -39,9 +39,9 @@ describe('Target.createCDPSession', function () {
|
|||||||
}
|
}
|
||||||
await target.createCDPSession();
|
await target.createCDPSession();
|
||||||
};
|
};
|
||||||
browser.browserContexts()[0]!.on('targetcreated', handler);
|
context.on('targetcreated', handler);
|
||||||
await browser.newPage();
|
await context.newPage();
|
||||||
browser.browserContexts()[0]!.off('targetcreated', handler);
|
context.off('targetcreated', handler);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send events', async () => {
|
it('should send events', async () => {
|
||||||
|
@ -64,23 +64,30 @@ const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
|||||||
const headfulBrowser = await launchBrowser(
|
const headfulBrowser = await launchBrowser(
|
||||||
Object.assign({userDataDir}, headfulOptions)
|
Object.assign({userDataDir}, headfulOptions)
|
||||||
);
|
);
|
||||||
const headfulPage = await headfulBrowser.newPage();
|
try {
|
||||||
await headfulPage.goto(server.EMPTY_PAGE);
|
const headfulPage = await headfulBrowser.newPage();
|
||||||
await headfulPage.evaluate(() => {
|
await headfulPage.goto(server.EMPTY_PAGE);
|
||||||
return (document.cookie =
|
await headfulPage.evaluate(() => {
|
||||||
'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
|
return (document.cookie =
|
||||||
});
|
'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
|
||||||
await headfulBrowser.close();
|
});
|
||||||
|
} finally {
|
||||||
|
await headfulBrowser.close();
|
||||||
|
}
|
||||||
// Read the cookie from headless chrome
|
// Read the cookie from headless chrome
|
||||||
const headlessBrowser = await launchBrowser(
|
const headlessBrowser = await launchBrowser(
|
||||||
Object.assign({userDataDir}, headlessOptions)
|
Object.assign({userDataDir}, headlessOptions)
|
||||||
);
|
);
|
||||||
const headlessPage = await headlessBrowser.newPage();
|
let cookie = '';
|
||||||
await headlessPage.goto(server.EMPTY_PAGE);
|
try {
|
||||||
const cookie = await headlessPage.evaluate(() => {
|
const headlessPage = await headlessBrowser.newPage();
|
||||||
return document.cookie;
|
await headlessPage.goto(server.EMPTY_PAGE);
|
||||||
});
|
cookie = await headlessPage.evaluate(() => {
|
||||||
await headlessBrowser.close();
|
return document.cookie;
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
await headlessBrowser.close();
|
||||||
|
}
|
||||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||||
try {
|
try {
|
||||||
rmSync(userDataDir);
|
rmSync(userDataDir);
|
||||||
|
@ -42,9 +42,9 @@ describe('Page', function () {
|
|||||||
expect(error.message).toContain('Protocol error');
|
expect(error.message).toContain('Protocol error');
|
||||||
});
|
});
|
||||||
it('should not be visible in browser.pages', async () => {
|
it('should not be visible in browser.pages', async () => {
|
||||||
const {browser} = await getTestState();
|
const {browser, context} = await getTestState();
|
||||||
|
|
||||||
const newPage = await browser.newPage();
|
const newPage = await context.newPage();
|
||||||
expect(await browser.pages()).toContain(newPage);
|
expect(await browser.pages()).toContain(newPage);
|
||||||
await newPage.close();
|
await newPage.close();
|
||||||
expect(await browser.pages()).not.toContain(newPage);
|
expect(await browser.pages()).not.toContain(newPage);
|
||||||
@ -2239,9 +2239,9 @@ describe('Page', function () {
|
|||||||
|
|
||||||
describe('Page.bringToFront', function () {
|
describe('Page.bringToFront', function () {
|
||||||
it('should work', async () => {
|
it('should work', async () => {
|
||||||
const {browser} = await getTestState();
|
const {context} = await getTestState();
|
||||||
const page1 = await browser.newPage();
|
const page1 = await context.newPage();
|
||||||
const page2 = await browser.newPage();
|
const page2 = await context.newPage();
|
||||||
|
|
||||||
await page1.bringToFront();
|
await page1.bringToFront();
|
||||||
expect(
|
expect(
|
||||||
|
@ -285,7 +285,7 @@ describe('Target', function () {
|
|||||||
|
|
||||||
describe('Browser.waitForTarget', () => {
|
describe('Browser.waitForTarget', () => {
|
||||||
it('should wait for a target', async () => {
|
it('should wait for a target', async () => {
|
||||||
const {browser, server} = await getTestState();
|
const {browser, server, context} = await getTestState();
|
||||||
|
|
||||||
let resolved = false;
|
let resolved = false;
|
||||||
const targetPromise = browser.waitForTarget(
|
const targetPromise = browser.waitForTarget(
|
||||||
@ -306,7 +306,7 @@ describe('Target', function () {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const page = await browser.newPage();
|
const page = await context.newPage();
|
||||||
expect(resolved).toBe(false);
|
expect(resolved).toBe(false);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user