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: Fix flaky tests in CI #681

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

AngusMcConnell
Copy link
Contributor

@AngusMcConnell AngusMcConnell commented Feb 3, 2025

Some visual regression tests inconsistently fail when running in GitHub Actions. I think this is because the govuk-frontend-supported class is added to the <body> when JavaScript is enabled. This takes a second or two to initialise, and Playwright thinks the page has stabilised before the class is applied.

This PR adds a short timeout to visual regression tests between the page loading and the page being compared to the 'golden screenshot' to allow the govuk-frontend-supported class to be applied and the page to stabilise.

Some visual regression tests inconsistently fail when running in GitHub Actions. I think this is because the `govuk-frontend-supported` class is added to the `<body>` when JavaScript is enabled. This takes a second or two to initialise, and Playwright thinks the page has stabilised before the class is applied.
@AngusMcConnell AngusMcConnell marked this pull request as ready for review February 4, 2025 10:32
@AngusMcConnell AngusMcConnell requested a review from a team as a code owner February 4, 2025 10:32
Copy link
Contributor

@tamoreton tamoreton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think the commit type would be test rather than fix.

@@ -8,6 +8,10 @@ test.describe('@visual-regression', () => {
test.describe(exampleName, () => {
test.beforeEach(async ({ page }) => {
await page.goto(`./components/${component}/${exampleName}`)
// The `govuk-frontend-supported` class is added to the `<body>` when JavaScript is enabled.
// This takes a second or two to initialise, and Playwright thinks the page has stabilised before the class is applied.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. It would explain why this suddenly started happening when updated the code to support v5 of govuk-frontend.

It might not be this class being added but initAll that causes the layout shift, though. Does this only happen on pages with components that have associated JavaScript?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - it seems to also happen with components that don't have JavaScript e.g. Tag. That's why I didn't originally think that this was the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right - I've tried await expect(page.locator('body')).toHaveClass(/govuk-frontend-supported/) and await page.waitForSelector('body.govuk-frontend-supported') but we're still getting failing tests

e2e/tests/visual-regression.spec.ts Outdated Show resolved Hide resolved
@AngusMcConnell
Copy link
Contributor Author

Nitpick: I think the commit type would be test rather than fix.

Will fix when I rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants