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

chore: removed flaky test from article suite #1156

Merged

Conversation

JohnAllenTech
Copy link
Contributor

✨ Codu Pull Request 💻

Fixes 1/2 on #1154

Pull Request details

  • Removed use of page.waitForTimeout this hardens the test as timeouts are a natural source of flakiness
  • Added a test id to the loading indicator

Any Breaking changes

  • None

Associated Screenshots

  • None

@JohnAllenTech JohnAllenTech requested a review from a team as a code owner October 19, 2024 17:29
Copy link

vercel bot commented Oct 19, 2024

@JohnAllenTech is attempting to deploy a commit to the Codú Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 19, 2024

Walkthrough

The changes in this pull request involve modifications to three files: the ArticleLoading component, end-to-end tests for articles, and the Playwright configuration. The ArticleLoading component now includes a data-testid attribute for improved testability. The end-to-end tests have been enhanced to handle loading states and user authentication more robustly, including the addition of a route handler to delay requests. Lastly, the Playwright configuration has been updated to include a new expect property with a timeout setting.

Changes

File Change Summary
components/ArticlePreview/ArticleLoading.tsx Added data-testid="article-loading-indicator" to the outer <div> for improved testability.
e2e/articles.spec.ts Enhanced tests for loading articles with a 100ms delay on requests, updated article counting method, added visibility assertions for the loading indicator, and standardized visibility checks using getByRole.
playwright.config.ts Added expect property with timeout: 10000 to the exported configuration object for customizing timeout duration in tests.

Possibly related PRs

  • Fix/e2e tests #1061: This PR improves end-to-end tests related to loading articles, which may interact with the ArticleLoading component modified in the main PR by ensuring that the loading indicator is visible during the loading process.
  • fix: update e2e tests for newer changes in site #1085: Updates to the end-to-end tests in this PR include checks for the visibility of loading indicators, which directly relates to the changes made in the ArticleLoading component.
  • Feat/improving existing e2e tests #1125: This PR enhances existing end-to-end tests, potentially including tests that verify the visibility of loading indicators, which aligns with the modifications made in the main PR.
  • chore: added article creation e2e test #1139: The addition of a test for writing and publishing articles in this PR may involve the ArticleLoading component, as it checks for the loading state during article creation and publication processes.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐇 In the meadow, the articles load,
With a twinkle and a testing code.
A loading sign, so clear and bright,
Helps us see when things are right!
Hooray for tests that help us play,
In the world of code, hip-hip-hooray! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

.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();
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 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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 😂

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
playwright.config.ts (1)

32-34: LGTM! Consider monitoring the impact on test execution times.

The addition of the expect property with a 10-second timeout is a good step towards improving test reliability. This change aligns well with the PR's objective of addressing flaky tests.

However, it's important to monitor how this global timeout affects overall test execution times. If you notice significant increases in test duration, you might want to consider:

  1. Adjusting the timeout value.
  2. Using more specific timeouts for individual tests or test suites that require longer wait times.

To ensure this change doesn't mask performance issues, consider implementing performance monitoring for your tests. This could involve tracking and reporting on test execution times, which would help identify any unexpected slowdowns introduced by this change.

e2e/articles.spec.ts (2)

120-120: Correct the typo in the comment

There's a typo in the comment: "We expect to see the loading indicator become visible why loading...". It should be "while".

Apply this diff to fix the typo:

-// We expect to see the loading indicator become visible why loading and then hidden when more articles are loaded
+// We expect to see the loading indicator become visible while loading and then hidden when more articles are loaded

124-124: Include 'await' before 'expect' for consistency

While expect is synchronous, adding await before it maintains consistency with other asynchronous operations and improves readability.

Apply this diff:

-expect(await articleLocator.count()).toBeGreaterThan(initialArticleCount);
+await expect(await articleLocator.count()).toBeGreaterThan(initialArticleCount);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d32599b and 6d9b197.

📒 Files selected for processing (3)
  • components/ArticlePreview/ArticleLoading.tsx (1 hunks)
  • e2e/articles.spec.ts (1 hunks)
  • playwright.config.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
components/ArticlePreview/ArticleLoading.tsx (1)

2-5: Excellent addition for improved testability!

The addition of the data-testid="article-loading-indicator" attribute to the outer <div> is a great improvement. This change enhances the component's testability by providing a reliable and specific selector for automated tests. It aligns well with the PR objective of improving test reliability and removing flaky tests.

This modification:

  1. Does not affect the component's visual appearance or functionality.
  2. Facilitates more robust and stable end-to-end tests.
  3. Follows best practices for making components easily testable.
e2e/articles.spec.ts (1)

127-134: LGTM!

The assertions correctly verify the visibility of the footer links, ensuring that key navigation elements are present.

Comment on lines +105 to +110
// 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();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

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:

-await page.route("**/*", async (route) => {
+await page.route("**/api/articles/load-more", async (route) => {
   await new Promise((f) => setTimeout(f, 100));
   await route.continue();
 });

Replace "**/api/articles/load-more" with the exact URL pattern of the 'load more articles' endpoint.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 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();
});
// This delays the requests by 100ms.
// This is needed as the load more article request was resolving too fast
await page.route("**/api/articles/load-more", async (route) => {
await new Promise((f) => setTimeout(f, 100));
await route.continue();
});

Comment on lines +121 to +122
await expect(page.getByTestId("article-loading-indicator")).toBeVisible();
await expect(page.getByTestId("article-loading-indicator")).toBeHidden();
Copy link
Contributor

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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 });

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

Successfully merging this pull request may close these issues.

2 participants