Skip to content

Commit 2946aae

Browse files
fix(e2e): improve dialog handler for Node 24 compatibility
- Add proper cleanup of dialog event listener to prevent memory leaks - Use try-finally pattern to ensure cleanup happens - Fixes Node 24 E2E test failures while maintaining Node 22 compatibility
1 parent 7830018 commit 2946aae

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

  • workspaces/scorecard/packages/app-legacy/e2e-tests/pages

workspaces/scorecard/packages/app-legacy/e2e-tests/pages/CatalogPage.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,25 @@ export class CatalogPage {
3737
}
3838

3939
async loginAndSetLocale(locale: string) {
40-
this.page.on('dialog', dialog => dialog.accept());
40+
// Set up dialog handler before any page navigation to catch potential dialogs
41+
const dialogHandler = (dialog: any) => dialog.accept();
42+
this.page.on('dialog', dialogHandler);
4143

42-
await this.page.goto('/');
43-
const enterButton = this.page.getByRole('button', { name: 'Enter' });
44-
await expect(enterButton).toBeVisible({ timeout: 30000 });
45-
await enterButton.click();
46-
await expect(
47-
this.page.getByRole('link', { name: 'Home' }).first(),
48-
).toBeVisible({
49-
timeout: 30000,
50-
});
51-
await this.switchToLocale(locale);
44+
try {
45+
await this.page.goto('/');
46+
const enterButton = this.page.getByRole('button', { name: 'Enter' });
47+
await expect(enterButton).toBeVisible({ timeout: 30000 });
48+
await enterButton.click();
49+
await expect(
50+
this.page.getByRole('link', { name: 'Home' }).first(),
51+
).toBeVisible({
52+
timeout: 30000,
53+
});
54+
await this.switchToLocale(locale);
55+
} finally {
56+
// Clean up the event listener to prevent memory leaks
57+
this.page.off('dialog', dialogHandler);
58+
}
5259
}
5360

5461
async openCatalog() {

0 commit comments

Comments
 (0)