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 () => {
|
||||
const {browser} = await getTestState();
|
||||
const {context} = await getTestState();
|
||||
let called = 0;
|
||||
const handler = async (target: Target) => {
|
||||
called++;
|
||||
@ -39,9 +39,9 @@ describe('Target.createCDPSession', function () {
|
||||
}
|
||||
await target.createCDPSession();
|
||||
};
|
||||
browser.browserContexts()[0]!.on('targetcreated', handler);
|
||||
await browser.newPage();
|
||||
browser.browserContexts()[0]!.off('targetcreated', handler);
|
||||
context.on('targetcreated', handler);
|
||||
await context.newPage();
|
||||
context.off('targetcreated', handler);
|
||||
});
|
||||
|
||||
it('should send events', async () => {
|
||||
|
@ -64,23 +64,30 @@ const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||
const headfulBrowser = await launchBrowser(
|
||||
Object.assign({userDataDir}, headfulOptions)
|
||||
);
|
||||
try {
|
||||
const headfulPage = await headfulBrowser.newPage();
|
||||
await headfulPage.goto(server.EMPTY_PAGE);
|
||||
await headfulPage.evaluate(() => {
|
||||
return (document.cookie =
|
||||
'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
|
||||
});
|
||||
} finally {
|
||||
await headfulBrowser.close();
|
||||
}
|
||||
// Read the cookie from headless chrome
|
||||
const headlessBrowser = await launchBrowser(
|
||||
Object.assign({userDataDir}, headlessOptions)
|
||||
);
|
||||
let cookie = '';
|
||||
try {
|
||||
const headlessPage = await headlessBrowser.newPage();
|
||||
await headlessPage.goto(server.EMPTY_PAGE);
|
||||
const cookie = await headlessPage.evaluate(() => {
|
||||
cookie = await headlessPage.evaluate(() => {
|
||||
return document.cookie;
|
||||
});
|
||||
} finally {
|
||||
await headlessBrowser.close();
|
||||
}
|
||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||
try {
|
||||
rmSync(userDataDir);
|
||||
|
@ -42,9 +42,9 @@ describe('Page', function () {
|
||||
expect(error.message).toContain('Protocol error');
|
||||
});
|
||||
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);
|
||||
await newPage.close();
|
||||
expect(await browser.pages()).not.toContain(newPage);
|
||||
@ -2239,9 +2239,9 @@ describe('Page', function () {
|
||||
|
||||
describe('Page.bringToFront', function () {
|
||||
it('should work', async () => {
|
||||
const {browser} = await getTestState();
|
||||
const page1 = await browser.newPage();
|
||||
const page2 = await browser.newPage();
|
||||
const {context} = await getTestState();
|
||||
const page1 = await context.newPage();
|
||||
const page2 = await context.newPage();
|
||||
|
||||
await page1.bringToFront();
|
||||
expect(
|
||||
|
@ -285,7 +285,7 @@ describe('Target', function () {
|
||||
|
||||
describe('Browser.waitForTarget', () => {
|
||||
it('should wait for a target', async () => {
|
||||
const {browser, server} = await getTestState();
|
||||
const {browser, server, context} = await getTestState();
|
||||
|
||||
let resolved = false;
|
||||
const targetPromise = browser.waitForTarget(
|
||||
@ -306,7 +306,7 @@ describe('Target', function () {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
const page = await context.newPage();
|
||||
expect(resolved).toBe(false);
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user