Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not wait for navigation event in navigate steps #859

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions __snapshots__/LighthouseStringifyExtension.test.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ const puppeteer = require('puppeteer'); // v23.0.0 or later
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
const startWaitingForEvents = () => {
promises.push(targetPage.waitForNavigation());
}
startWaitingForEvents();
await targetPage.goto('https://example.com');
await Promise.all(promises);
}
await lhFlow.endNavigation();
await lhFlow.startTimespan();
Expand Down Expand Up @@ -84,13 +78,7 @@ const puppeteer = require('puppeteer'); // v23.0.0 or later
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
const startWaitingForEvents = () => {
promises.push(targetPage.waitForNavigation());
}
startWaitingForEvents();
await targetPage.goto('https://example.com');
await Promise.all(promises);
}
await lhFlow.endNavigation();
await lhFlow.startTimespan();
Expand All @@ -111,13 +99,7 @@ const puppeteer = require('puppeteer'); // v23.0.0 or later
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
const startWaitingForEvents = () => {
promises.push(targetPage.waitForNavigation());
}
startWaitingForEvents();
await targetPage.goto('https://example.com/page/');
await Promise.all(promises);
}
await lhFlow.endNavigation();
const lhFlowReport = await lhFlow.generateReport();
Expand Down Expand Up @@ -156,13 +138,7 @@ const puppeteer = require('puppeteer'); // v23.0.0 or later
await lhFlow.startNavigation();
{
const targetPage = page;
const promises = [];
const startWaitingForEvents = () => {
promises.push(targetPage.waitForNavigation());
}
startWaitingForEvents();
await targetPage.goto('https://example.com');
await Promise.all(promises);
}
await lhFlow.endNavigation();
await lhFlow.startNavigation();
Expand Down
11 changes: 5 additions & 6 deletions src/PuppeteerStringifyExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ export class PuppeteerStringifyExtension extends StringifyExtension {
out.appendLine(`const timeout = ${step.timeout};`);
}
this.#appendContext(out, step);
if (step.assertedEvents) {
const waitForEvents =
step.assertedEvents && step.type !== StepType.Navigate;
if (waitForEvents) {
out.appendLine('const promises = [];');
out.appendLine('const startWaitingForEvents = () => {').startBlock();
for (const event of step.assertedEvents) {
for (const event of step.assertedEvents!) {
switch (event.type) {
case AssertedEventType.Navigation: {
out.appendLine(
Expand All @@ -118,7 +120,7 @@ export class PuppeteerStringifyExtension extends StringifyExtension {

this.#appendStepType(out, step);

if (step.assertedEvents) {
if (waitForEvents) {
out.appendLine('await Promise.all(promises);');
}

Expand Down Expand Up @@ -326,9 +328,6 @@ export class PuppeteerStringifyExtension extends StringifyExtension {
}

#appendNavigationStep(out: LineWriter, step: NavigateStep): void {
if (step.assertedEvents?.length) {
out.appendLine(`startWaitingForEvents();`);
}
out.appendLine(
`await targetPage.goto(${formatJSONAsJS(step.url, out.getIndent())});`
);
Expand Down