-
-
Notifications
You must be signed in to change notification settings - Fork 173
chore: removed flaky test from article suite #1156
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -102,27 +102,36 @@ test.describe("Authenticated Articles Page", () => { | |||||||||
| // Waits for articles to be loaded | ||||||||||
| await page.waitForSelector("article"); | ||||||||||
|
|
||||||||||
| const initialArticleCount = await page.$$eval( | ||||||||||
| "article", | ||||||||||
| (articles) => articles.length, | ||||||||||
| ); | ||||||||||
| // This delays the requests by 100ms. | ||||||||||
| // This is needed as the load more article request was resolving too fast | ||||||||||
| await page.route("**/*", async (route) => { | ||||||||||
| await new Promise((f) => setTimeout(f, 100)); | ||||||||||
| await route.continue(); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| if (!isMobile) { | ||||||||||
| await page.getByText("Code Of Conduct").scrollIntoViewIfNeeded(); | ||||||||||
| await page.waitForTimeout(5000); | ||||||||||
| const finalArticleCount = await page.$$eval( | ||||||||||
| "article", | ||||||||||
| (articles) => articles.length, | ||||||||||
| ); | ||||||||||
| expect(finalArticleCount).toBeGreaterThan(initialArticleCount); | ||||||||||
| const articleLocator = page.locator("article"); | ||||||||||
| const initialArticleCount = await articleLocator.count(); | ||||||||||
|
|
||||||||||
| await page | ||||||||||
| .getByRole("link", { name: "Code Of Conduct" }) | ||||||||||
| .scrollIntoViewIfNeeded(); | ||||||||||
|
|
||||||||||
| // We expect to see the loading indicator become visible why loading and then hidden when more articles are loaded | ||||||||||
| await expect(page.getByTestId("article-loading-indicator")).toBeVisible(); | ||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know your not a fan of testIds @NiallJoeMaher the alternative to this is locator('.my-4').first() which isnt very unique so my thought was using a testId will just make it more robust. Can switch it out if needed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I tend to stay away from test IDs but I also prefer having working tests too 😂 |
||||||||||
| await expect(page.getByTestId("article-loading-indicator")).toBeHidden(); | ||||||||||
|
Comment on lines
+121
to
+122
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance reliability of loading indicator assertions The assertions checking the loading indicator's visibility might be timing-sensitive. To improve reliability, consider using timeouts to wait for the expected state or checking for stability. Modify the assertions as follows: -await expect(page.getByTestId("article-loading-indicator")).toBeVisible();
-await expect(page.getByTestId("article-loading-indicator")).toBeHidden();
+await expect(page.getByTestId("article-loading-indicator")).toBeVisible({ timeout: 5000 });
+await expect(page.getByTestId("article-loading-indicator")).toBeHidden({ timeout: 5000 });This ensures the test waits up to 5 seconds for the loading indicator to appear and disappear, enhancing test stability. 📝 Committable suggestion
Suggested change
|
||||||||||
|
|
||||||||||
| expect(await articleLocator.count()).toBeGreaterThan(initialArticleCount); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| await expect(page.getByText("Home")).toBeVisible(); | ||||||||||
| await expect(page.getByRole("link", { name: "Home" })).toBeVisible(); | ||||||||||
| await expect( | ||||||||||
| page.getByLabel("Footer").getByRole("link", { name: "Events" }), | ||||||||||
| ).toBeVisible(); | ||||||||||
| await expect(page.getByText("Sponsorship")).toBeVisible(); | ||||||||||
| await expect(page.getByText("Code Of Conduct")).toBeVisible(); | ||||||||||
| await expect(page.getByRole("link", { name: "Sponsorship" })).toBeVisible(); | ||||||||||
| await expect( | ||||||||||
| page.getByRole("link", { name: "Code Of Conduct" }), | ||||||||||
| ).toBeVisible(); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| test("Should write and publish an article", async ({ page, isMobile }) => { | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limit the network request delay to specific routes to prevent unintended delays
The route handler is currently delaying all network requests by 100ms, which can slow down unrelated requests and impact test performance. To avoid unintended side effects, consider narrowing the route to target only the 'load more articles' request by matching its specific URL or pattern.
Apply this diff to target the specific request:
Replace
"**/api/articles/load-more"with the exact URL pattern of the 'load more articles' endpoint.📝 Committable suggestion