Skip to content

Commit

Permalink
fix: do not wait for navigation event in navigate steps (#859)
Browse files Browse the repository at this point in the history
page.goto() already does it
  • Loading branch information
OrKoN authored Aug 9, 2024
1 parent 223e2f0 commit 2e48a56
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
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

0 comments on commit 2e48a56

Please sign in to comment.