Skip to content

Commit

Permalink
chore: test all
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Dec 8, 2022
1 parent 46ef46a commit c935310
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .mocharc.cjs
Expand Up @@ -19,8 +19,8 @@ module.exports = {
logLevel: 'debug',
require: ['./test/build/mocha-utils.js', 'source-map-support/register'],
spec: 'test/build/**/*.spec.js',
exit: true,
retries: 0,
exit: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
parallel: !!process.env.PARALLEL,
timeout: 25_000,
reporter: process.env.CI ? 'spec' : 'dot',
Expand Down
3 changes: 1 addition & 2 deletions packages/puppeteer-core/src/common/Frame.ts
Expand Up @@ -396,7 +396,6 @@ export class Frame {
waitUntil,
timeout
);
const navResponse = watcher.navigationResponse();
const error = await Promise.race([
watcher.timeoutOrTerminationPromise(),
watcher.sameDocumentNavigationPromise(),
Expand All @@ -408,7 +407,7 @@ export class Frame {
throw error;
}
log('LIFECYCLE WATCHER wait for navigationResponse');
return await navResponse;
return await watcher.navigationResponse();
} finally {
log('LIFECYCLE WATCHER DISPOSED');
watcher.dispose();
Expand Down
35 changes: 27 additions & 8 deletions packages/puppeteer-core/src/common/FrameManager.ts
Expand Up @@ -145,15 +145,15 @@ export class FrameManager extends EventEmitter {
const result = await Promise.all([
client.send('Page.enable'),
client.send('Page.getFrameTree'),
client.send('Page.setLifecycleEventsEnabled', {enabled: true}),
client.send('Runtime.enable').then(() => {
return this.#createIsolatedWorld(client, UTILITY_WORLD_NAME);
})
]);

const {frameTree} = result[1];
this.#handleFrameTree(client, frameTree);
await Promise.all([
client.send('Page.setLifecycleEventsEnabled', {enabled: true}),
client.send('Runtime.enable').then(() => {
return this.#createIsolatedWorld(client, UTILITY_WORLD_NAME);
}),
// TODO: Network manager is not aware of OOP iframes yet.
client === this.#client
? this.#networkManager.initialize()
Expand Down Expand Up @@ -243,7 +243,20 @@ export class FrameManager extends EventEmitter {
session: CDPSession,
frameTree: Protocol.Page.FrameTree
): void {
log('Handling frame tree', frameTree.frame.id, frameTree.frame.url);
log(
'Handling frame tree',
frameTree.frame.id,
frameTree.frame.url,
'this.#frameNavigatedReceived',
Array.from(this.#frameNavigatedReceived)
);
if (frameTree.frame.parentId) {
this.#onFrameAttached(
session,
frameTree.frame.id,
frameTree.frame.parentId
);
}
if (!this.#frameNavigatedReceived.has(frameTree.frame.id)) {
this.#onFrameNavigated(frameTree.frame);
} else {
Expand Down Expand Up @@ -273,7 +286,7 @@ export class FrameManager extends EventEmitter {
// If an OOP iframes becomes a normal iframe again
// it is first attached to the parent page before
// the target is removed.
log('Updating client in #onFrameAttached')
log('Updating client in #onFrameAttached');
frame.updateClient(session);
}
return;
Expand Down Expand Up @@ -386,15 +399,20 @@ export class FrameManager extends EventEmitter {
): void {
const auxData = contextPayload.auxData as {frameId?: string} | undefined;
const frameId = auxData && auxData.frameId;
log('#onExecutionContextCreated', frameId);
const frame = typeof frameId === 'string' ? this.frame(frameId) : undefined;
let world: IsolatedWorld | undefined;
log('HAS FRAME', !!frame);
if (frame) {
// Only care about execution contexts created for the current session.
if (frame._client() !== session) {
return;
}

if (contextPayload.auxData && !!contextPayload.auxData['isDefault']) {
log(
"contextPayload.auxData && contextPayload.auxData['isDefault']",
contextPayload.auxData && contextPayload.auxData['isDefault']
);
if (contextPayload.auxData && contextPayload.auxData['isDefault']) {
world = frame.worlds[MAIN_WORLD];
} else if (
contextPayload.name === UTILITY_WORLD_NAME &&
Expand All @@ -411,6 +429,7 @@ export class FrameManager extends EventEmitter {
contextPayload,
world
);
log('HAS WORLD', !!world);
if (world) {
world.setContext(context);
}
Expand Down
1 change: 1 addition & 0 deletions packages/puppeteer-core/src/common/IsolatedWorld.ts
Expand Up @@ -296,6 +296,7 @@ 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
7 changes: 6 additions & 1 deletion packages/puppeteer-core/src/common/LifecycleWatcher.ts
Expand Up @@ -286,7 +286,12 @@ export class LifecycleWatcher {
}

#checkLifecycleComplete(): void {
log('LifeCycleWacher checkLifecycleComplete', this.#frame._lifecycleEvents, this.#expectedLifecycle, this.#swapped);
log(
'LifeCycleWacher checkLifecycleComplete',
Array.from(this.#frame._lifecycleEvents),
this.#expectedLifecycle,
this.#swapped
);
// We expect navigation to commit.
if (!checkLifecycle(this.#frame, this.#expectedLifecycle)) {
return;
Expand Down
3 changes: 3 additions & 0 deletions test/src/launcher.spec.ts
Expand Up @@ -797,6 +797,9 @@ 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
29 changes: 15 additions & 14 deletions test/src/mocha-utils.ts
Expand Up @@ -286,22 +286,23 @@ export const describeWithDebugLogs = (
description: string,
body: (this: Mocha.Suite) => void
): Mocha.Suite | void => {
beforeEach(() => {
setLogCapture(true);
});
describe(description + '-debug', () => {
beforeEach(() => {
setLogCapture(true);
});

afterEach(function () {
if (this.currentTest?.state === 'failed') {
console.log(
`\n"${this.currentTest.fullTitle()}" failed. Here is a debug log:`
);
console.log(getCapturedLogs().join('\n') + '\n');
}
setLogCapture(false);
});
afterEach(function () {
if (this.currentTest?.state === 'failed') {
console.log(
`\n"${this.currentTest.fullTitle()}" failed. Here is a debug log:`
);
console.log(getCapturedLogs().join('\n') + '\n');
}
setLogCapture(false);
});

// eslint-disable-next-line mocha/no-exclusive-tests
return describe.only(description, body);
describe(description, body);
});
};

export const shortWaitForArrayToHaveAtLeastNElements = async (
Expand Down

0 comments on commit c935310

Please sign in to comment.