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(tests): Use tags instead of projects Playwright #16959

Merged
merged 6 commits into from
Nov 20, 2024

Conversation

svanaeinars
Copy link
Member

@svanaeinars svanaeinars commented Nov 20, 2024

Summary by CodeRabbit

  • Documentation

    • Improved clarity and updated usage instructions for the E2E Testing Library.
    • Revised test execution commands to use tags for filtering tests, promoting a more flexible approach.
    • Simplified test case organization structure and provided enhanced guidance on writing tests, including the use of test.step.
  • Chores

    • Made the cwd parameter in the Playwright configuration a required parameter to streamline configuration setup.

@svanaeinars svanaeinars requested a review from a team as a code owner November 20, 2024 14:30
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The pull request includes updates to the documentation for the E2E Testing Library, enhancing clarity and modifying usage instructions. Key changes involve a new command structure for running tests using tags instead of project-specific commands. Additionally, the structure of test cases has been simplified, with an emphasis on tagging. The createPlaywrightConfig function in playwright-config.ts has also been updated, making the cwd parameter required instead of optional, while maintaining the existing functionality of the configuration object.

Changes

File Path Change Summary
libs/testing/e2e/README.md Updated documentation for the E2E Testing Library, revised test running commands to use --grep <tag>, simplified test case structure, and added guidance on test.step.
libs/testing/e2e/src/lib/config/playwright-config.ts Modified the createPlaywrightConfig function to make the cwd parameter required, removing its default value while retaining the existing timeoutMs default.

Possibly related PRs

Suggested reviewers

  • eirikurn

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.

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.

@svanaeinars svanaeinars added the automerge Merge this PR as soon as all checks pass label Nov 20, 2024
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: 0

🧹 Outside diff range and nitpick comments (6)
libs/testing/e2e/src/lib/config/playwright-config.ts (3)

Line range hint 3-8: Fix type definition inconsistency for cwd parameter

The interface still marks cwd as optional with ? while the implementation treats it as required. This mismatch could lead to runtime errors when TypeScript validation passes but the function fails.

Apply this fix:

interface PlaywrightConfigParams {
  webServerUrl: string
  port?: number
  command: string
- cwd?: string
+ cwd: string
  timeoutMs?: number
}

28-29: Add validation for the cwd parameter

Consider adding runtime validation to ensure cwd is a non-empty string and represents a valid directory path to prevent cryptic errors during test execution.

Example validation:

export const createPlaywrightConfig = ({
  webServerUrl,
  port,
  command,
  cwd,
  timeoutMs = 5 * 60 * 1000,
}: PlaywrightConfigParams) => {
+ if (!cwd || cwd.trim() === '') {
+   throw new Error('cwd must be a non-empty string');
+ }
  return defineConfig({

Line range hint 47-51: Update test organization to use tags instead of projects

According to the PR objectives, we're transitioning from projects to tags for test categorization. The current configuration still uses the project-based approach.

Consider replacing the projects configuration with tag-based filtering:

- projects: [
-   { name: 'everything', testMatch: 'e2e/**/*.spec.[tj]s' },
-   { name: 'smoke', testMatch: 'e2e/smoke/**/*.spec.[tj]s' },
-   { name: 'acceptance', testMatch: 'e2e/acceptance/**/*.spec.[tj]s' },
- ],
+ grep: process.env.TEST_TAG ? new RegExp(`@${process.env.TEST_TAG}`) : /.*/,
libs/testing/e2e/README.md (3)

61-64: Enhance the tag-based filtering documentation

While the command syntax is correct, consider improving this section by:

  1. Documenting the tagging convention (e.g., always prefix with @)
  2. Providing a list of commonly used/recommended tags (@fast, @slow, @smoke, etc.)
  3. Including examples of combining multiple tags
 - **Run with a Specific Tag**: Run only the tests tagged with a specific tag:

   ```bash
    yarn e2e <app-name> --grep @fast
  • Test Tags

  • Tests can be categorized using tags prefixed with @. Common tags include:
    • @fast: Quick tests (< 30s)
    • @slow: Long-running tests
    • @flaky: Tests that may need retries
  • You can combine multiple tags:
  • Run tests that are both fast and smoke

  • yarn e2e --grep "@fast.*@smoke"

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e <app-name> --skip-nx-cache   ```  - **Run with a Specific Tag**: Run only the tes...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

</details>

</details>

---

`101-106`: **Clarify the transition from projects to tags**

The folder structure is simplified, but it would be helpful to:
1. Show example test files with their tags
2. Provide migration guidance for teams transitioning from the project-based approach


```diff
 Test cases are written in spec files. Tests are tagged based on their execution time or other criteria. For example, you can use tags like `@fast` for quick tests and `@slow` for longer-running tests. Here is an example of the folder layout for testing the search engine and front-page of the `web` project:

 ```shell
 web/                      (app name)
-├── home-page.spec.ts     (feature name, kebab-case)
-└── search.spec.ts
+├── home-page.spec.ts     # Contains @fast tests
+└── search.spec.ts        # Contains @slow tests

+### Migrating from Projects to Tags
+
+If you're migrating from the project-based approach:
+1. Move tests from project-specific folders to feature-based files
+2. Add appropriate tags to your test descriptions:

    • Previous smoke project → Add @smoke tag
    • Previous acceptance project → Add @acceptance tag

---

`131-131`: **Enhance the test case example with comprehensive tag usage**

The example shows basic tag usage, but it would be more helpful to demonstrate multiple tags and explain tag selection criteria.


```diff
-  test('should get paid @slow', () => {
+  // Tags:
+  // @slow - Takes >30s due to payment processing
+  // @smoke - Critical business functionality
+  test('should get paid @slow @smoke', () => {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 09fed24 and 397d325.

📒 Files selected for processing (2)
  • libs/testing/e2e/README.md (3 hunks)
  • libs/testing/e2e/src/lib/config/playwright-config.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/testing/e2e/README.md (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/config/playwright-config.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🪛 LanguageTool
libs/testing/e2e/README.md

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e --skip-nx-cache ``` - Run with a Specific Tag: Run only the tes...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🔇 Additional comments (1)
libs/testing/e2e/src/lib/config/playwright-config.ts (1)

Line range hint 1-67: Implementation follows library guidelines

The code successfully meets the guidelines for libs/** files:

  • Uses TypeScript for type definitions
  • Provides a reusable configuration utility
  • Follows proper module export patterns for effective tree-shaking

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)
libs/testing/e2e/src/lib/config/playwright-config.ts (2)

Line range hint 47-51: Implement tag-based test filtering

The PR title suggests moving from projects to tags, but the configuration still uses project-based filtering. Consider implementing tag-based filtering to align with the PR objectives.

Consider replacing project-based configuration with tag-based filtering:

-  projects: [
-    { name: 'everything', testMatch: 'e2e/**/*.spec.[tj]s' },
-    { name: 'smoke', testMatch: 'e2e/smoke/**/*.spec.[tj]s' },
-    { name: 'acceptance', testMatch: 'e2e/acceptance/**/*.spec.[tj]s' },
-  ],
+  grep: process.env.TEST_TAGS ? new RegExp(process.env.TEST_TAGS) : undefined,

Line range hint 11-21: Enhance return type documentation

While the JSDoc is comprehensive, consider adding more specific details about the return type structure and its configuration options.

Add return type details to the JSDoc:

- * @returns A configuration object for Playwright E2E tests.
+ * @returns {import('@playwright/test').PlaywrightTestConfig} A configuration object
+ * containing test directory settings, parallel execution options, retry logic,
+ * reporter configuration, and web server settings.
libs/testing/e2e/README.md (1)

61-64: LGTM! Consider enhancing tag examples.

The new tag-based filtering approach is well documented. To make it even more helpful, consider adding more common tag examples like @smoke, @regression, or @critical to showcase the tagging convention.

🧰 Tools
🪛 LanguageTool

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e --skip-nx-cache ``` - Run with a Specific Tag: Run only the tes...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 09fed24 and 397d325.

📒 Files selected for processing (2)
  • libs/testing/e2e/README.md (3 hunks)
  • libs/testing/e2e/src/lib/config/playwright-config.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/testing/e2e/README.md (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/config/playwright-config.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🪛 LanguageTool
libs/testing/e2e/README.md

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e --skip-nx-cache ``` - Run with a Specific Tag: Run only the tes...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🔇 Additional comments (2)
libs/testing/e2e/src/lib/config/playwright-config.ts (2)

Line range hint 3-9: Well-structured TypeScript interface

The TypeScript implementation follows best practices with explicit types and proper exports, enabling good type safety and reusability across NextJS apps.


28-28: Breaking Change: cwd parameter is now required

Removing the default value for cwd is a breaking change that requires all consumers to explicitly specify the working directory.

Let's verify the impact on existing implementations:

libs/testing/e2e/README.md Show resolved Hide resolved
libs/testing/e2e/README.md Outdated Show resolved Hide resolved
Copy link
Member

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr left a comment

Choose a reason for hiding this comment

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

LGTM

Minor documentation comments

libs/testing/e2e/README.md Outdated Show resolved Hide resolved
libs/testing/e2e/README.md Outdated Show resolved Hide resolved
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 397d325 and 435e043.

📒 Files selected for processing (1)
  • libs/testing/e2e/README.md (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/testing/e2e/README.md (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🪛 LanguageTool
libs/testing/e2e/README.md

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e --skip-nx-cache ``` - Run with a Specific Tag: Run only the tes...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

libs/testing/e2e/README.md Outdated Show resolved Hide resolved
libs/testing/e2e/README.md Show resolved Hide resolved
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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 435e043 and 027baf5.

📒 Files selected for processing (1)
  • libs/testing/e2e/README.md (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/testing/e2e/README.md (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🪛 LanguageTool
libs/testing/e2e/README.md

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e --skip-nx-cache ``` - Run Tests with Tags: Use tags to include ...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

libs/testing/e2e/README.md Outdated Show resolved Hide resolved
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: 1

🧹 Outside diff range and nitpick comments (1)
libs/testing/e2e/README.md (1)

110-115: Add examples of common tag categories

Consider adding a table of commonly used tags with their descriptions:

| Tag Category | Example | Description |
|--------------|---------|-------------|
| Speed        | @fast   | Tests that complete within 30 seconds |
| Type         | @smoke  | Critical path tests |
| Feature      | @auth   | Authentication-related tests |
| Status       | @flaky  | Tests that may need investigation |
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 027baf5 and f64c620.

📒 Files selected for processing (1)
  • libs/testing/e2e/README.md (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/testing/e2e/README.md (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🪛 LanguageTool
libs/testing/e2e/README.md

[style] ~61-~61: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...e --skip-nx-cache ``` - Run Tests with Tags: Use tags to include ...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

libs/testing/e2e/README.md Show resolved Hide resolved
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.41%. Comparing base (7883b6f) to head (0d4796c).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16959   +/-   ##
=======================================
  Coverage   36.41%   36.41%           
=======================================
  Files        6898     6898           
  Lines      144868   144868           
  Branches    41403    41403           
=======================================
  Hits        52751    52751           
  Misses      92117    92117           
Flag Coverage Δ
api 3.34% <ø> (ø)
application-system-api 41.03% <ø> (ø)
application-template-api-modules 27.74% <ø> (ø)
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-driving-license 18.14% <ø> (ø)
application-templates-estate 12.15% <ø> (ø)
application-templates-financial-aid 15.77% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.52% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.42% <ø> (ø)
application-templates-parental-leave 29.74% <ø> (-0.12%) ⬇️
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.58% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 15.90% <ø> (ø)
shared-components 26.91% <ø> (ø)
shared-form-fields 31.26% <ø> (ø)
web 1.76% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7883b6f...0d4796c. Read the comment docs.

---- 🚨 Try these New Features:

@datadog-island-is
Copy link

Datadog Report

All test runs b6d4ca4 🔗

19 Total Test Services: 0 Failed, 18 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.1%), 102 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.36s 1 no change Link
application-system-api 0 0 0 112 2 3m 19.78s 1 no change Link
application-template-api-modules 0 0 0 116 0 2m 0.95s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 15.78s 1 no change Link
application-templates-driving-license 0 0 0 13 0 13.58s 1 no change Link
application-templates-financial-aid 0 0 0 11 0 13.32s 1 no change Link
application-templates-general-petition 0 0 0 5 0 10.51s 1 no change Link
application-templates-health-insurance 0 0 0 0 0 642.46ms 1 no change Link
application-templates-mortgage-certificate 0 0 0 3 0 15.83s 1 no change Link
application-templates-parental-leave 0 0 0 163 0 15.34s 1 decreased (-0.1%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • application-templates-parental-leave - jest 34.9% (-0.1%) - Details

@kodiakhq kodiakhq bot merged commit 6752b9b into main Nov 20, 2024
93 checks passed
@kodiakhq kodiakhq bot deleted the chore/remove-projects-playwright branch November 20, 2024 17:04
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* chore(tests): Use tags instead of projects Playwright

* Tiny fix

* Update libs/testing/e2e/README.md

Co-authored-by: Kristofer <[email protected]>

* Update documentation

* Small fix

---------

Co-authored-by: Kristofer <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants