Skip to content

Commit

Permalink
chore: remove debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Dec 8, 2022
1 parent c935310 commit a863b4e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/common/Frame.ts
Expand Up @@ -37,7 +37,7 @@ import {importFS} from './util.js';

import {debug} from './Debug.js';

const log = debug('puppeteer:frame ');
const log = debug('puppeteer:Frame');

/**
* @public
Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-core/src/common/FrameManager.ts
Expand Up @@ -32,7 +32,7 @@ import {debugError} from './util.js';

import {debug} from './Debug.js';

const log = debug('puppeteer:frameManager ');
const log = debug('puppeteer:FrameManager');

const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';

Expand Down
1 change: 0 additions & 1 deletion packages/puppeteer-core/src/common/IsolatedWorld.ts
Expand Up @@ -296,7 +296,6 @@ export class IsolatedWorld {
waitUntil = ['load'],
timeout = this.#timeoutSettings.navigationTimeout(),
} = options;

// We rely upon the fact that document.open() will reset frame lifecycle with "init"
// lifecycle event. @see https://crrev.com/608658
await this.evaluate(html => {
Expand Down
22 changes: 14 additions & 8 deletions packages/puppeteer-core/src/common/LifecycleWatcher.ts
Expand Up @@ -33,7 +33,7 @@ import {NetworkManagerEmittedEvents} from './NetworkManager.js';
import {CDPSessionEmittedEvents} from './Connection.js';
import {debug} from './Debug.js';

const log = debug('puppeteer:lifecyleWatcher ');
const log = debug('puppeteer:LifecycleWatcher');

/**
* @public
Expand Down Expand Up @@ -113,7 +113,11 @@ export class LifecycleWatcher {
waitUntil: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[],
timeout: number
) {
log('LifeCycleWacher created for frame ', frame._id);
log('instantiated for frame', {
frameId: frame._id,
waitUntil,
timeout,
});
if (Array.isArray(waitUntil)) {
waitUntil = waitUntil.slice();
} else if (typeof waitUntil === 'string') {
Expand Down Expand Up @@ -286,12 +290,14 @@ export class LifecycleWatcher {
}

#checkLifecycleComplete(): void {
log(
'LifeCycleWacher checkLifecycleComplete',
Array.from(this.#frame._lifecycleEvents),
this.#expectedLifecycle,
this.#swapped
);
log('#checkLifecycleComplete', {
frameEvents: Array.from(this.#frame._lifecycleEvents),
expectedEvents: this.#expectedLifecycle,
frameSwapped: this.#swapped,
hasSameDocumentNavigation: this.#hasSameDocumentNavigation,
frameLoaderId: this.#frame._loaderId,
initialLoaderId: this.#initialLoaderId,
});
// We expect navigation to commit.
if (!checkLifecycle(this.#frame, this.#expectedLifecycle)) {
return;
Expand Down
3 changes: 0 additions & 3 deletions test/src/launcher.spec.ts
Expand Up @@ -797,9 +797,6 @@ describe('Launcher specs', function () {
const restoredPage = pages.find(page => {
return page.url() === server.PREFIX + '/frames/nested-frames.html';
})!;
await new Promise(resolve => {
return setTimeout(resolve, 1000);
});
expect(utils.dumpFrames(restoredPage.mainFrame())).toEqual([
'http://localhost:<PORT>/frames/nested-frames.html',
' http://localhost:<PORT>/frames/two-frames.html (2frames)',
Expand Down
5 changes: 5 additions & 0 deletions test/src/mocha-utils.ts
Expand Up @@ -282,6 +282,11 @@ export const expectCookieEquals = (
}
};

/**
* Use it if you want to capture debug logs for a specitic test suite in CI.
* This describe function enables capturing of debug logs and would print them
* only if a test fails to reduce the amount of output.
*/
export const describeWithDebugLogs = (
description: string,
body: (this: Mocha.Suite) => void
Expand Down
20 changes: 2 additions & 18 deletions test/src/oopif.spec.ts
Expand Up @@ -20,9 +20,6 @@ import {describeWithDebugLogs, getTestState} from './mocha-utils.js';
import {Browser} from 'puppeteer-core/internal/api/Browser.js';
import {BrowserContext} from 'puppeteer-core/internal/api/BrowserContext.js';
import {Page} from 'puppeteer-core/internal/api/Page.js';
import {debug} from 'puppeteer-core/internal/common/Debug.js';

const log = debug('puppeteer:test');

describeWithDebugLogs('OOPIF', function () {
/* We use a special browser for this test as we need the --site-per-process flag */
Expand All @@ -49,11 +46,11 @@ describeWithDebugLogs('OOPIF', function () {
});

afterEach(async () => {
await context?.close();
await context.close();
});

after(async () => {
await browser?.close();
await browser.close();
});

it('should treat OOP iframes and normal iframes the same', async () => {
Expand Down Expand Up @@ -132,13 +129,11 @@ describeWithDebugLogs('OOPIF', function () {

const [frame1, frame2] = await Promise.all([frame1Promise, frame2Promise]);

log('FRAMES RESOLVED');
expect(
await frame1.evaluate(() => {
return document.location.href;
})
).toMatch(/one-frame\.html$/);
log('AFTER EVALUATE1');
expect(
await frame2.evaluate(() => {
return document.location.href;
Expand Down Expand Up @@ -176,20 +171,16 @@ describeWithDebugLogs('OOPIF', function () {
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);

const frame = await framePromise;
log('FRAME FOUND');
expect(frame.isOOPFrame()).toBe(false);
const nav = frame.waitForNavigation();
await utils.navigateFrame(
page,
'frame1',
server.CROSS_PROCESS_PREFIX + '/empty.html'
);
log('WAITING FOR NAV TO CROSS_PROCESS_PREFIX ');
await nav;
log('NAVIGATED TO CROSS_PROCESS_PREFIX ');
expect(frame.isOOPFrame()).toBe(true);
await utils.detachFrame(page, 'frame1');
log('NAVIGATED DETACHED');
expect(page.frames()).toHaveLength(1);
});

Expand Down Expand Up @@ -223,21 +214,17 @@ describeWithDebugLogs('OOPIF', function () {
'frame1',
server.CROSS_PROCESS_PREFIX + '/empty.html'
);
log('AFTER ATTACH');
const frame = await framePromise;
log('BEFORE EVALUATE1');
await frame.evaluate(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
_test = 'Test 123!';
});
log('BEFORE EVALUATE2');
const result = await frame.evaluate(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return window._test;
});
log('AFTER EVALUATE2');
expect(result).toBe('Test 123!');
});
it('should provide access to elements', async () => {
Expand Down Expand Up @@ -300,13 +287,10 @@ describeWithDebugLogs('OOPIF', function () {

it('should wait for inner OOPIFs', async () => {
const {server} = getTestState();
log('BEFORE NAV');
await page.goto(`http://mainframe:${server.PORT}/main-frame.html`);
log('AFTER NAV');
const frame2 = await page.waitForFrame(frame => {
return frame.url().endsWith('inner-frame2.html');
});
log('AFTER WAIT');
expect(oopifs(context).length).toBe(2);
expect(
page.frames().filter(frame => {
Expand Down

0 comments on commit a863b4e

Please sign in to comment.