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): Support more options E2E Playwright config #16982

Merged
merged 4 commits into from
Nov 21, 2024

Conversation

svanaeinars
Copy link
Member

@svanaeinars svanaeinars commented Nov 21, 2024

Summary by CodeRabbit

  • Documentation

    • Updated the E2E Testing Library's README to reflect changes in command usage from yarn e2e to yarn nx e2e.
  • New Features

    • Enhanced configurability of Playwright setup by introducing optional parameters and improved error handling for missing fields.

@svanaeinars svanaeinars requested a review from a team as a code owner November 21, 2024 12:53
Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Walkthrough

The pull request introduces changes to the E2E Testing Library, primarily updating the README.md to reflect a shift in command usage from yarn e2e to yarn nx e2e. Additionally, modifications are made to the PlaywrightConfigParams interface and the createPlaywrightConfig function in the playwright-config.ts file, making the command property optional and adding new optional properties for enhanced configuration flexibility. The logic in createPlaywrightConfig is also updated to handle cases where certain parameters are not provided.

Changes

File Path Change Summary
libs/testing/e2e/README.md Updated command usage from yarn e2e to yarn nx e2e in multiple sections, including examples.
libs/testing/e2e/src/lib/config/playwright-config.ts Modified PlaywrightConfigParams to make command optional and added app, dependencies, and proxies as optional properties. Updated createPlaywrightConfig function to handle new parameters and default command construction.

Possibly related PRs

  • chore(tests): Improve E2E Documentation #16909: The changes in the README.md for the E2E Testing Library documentation are related as they both involve updates to the command structure for running tests, enhancing clarity and usability.
  • chore(tests): Use tags instead of projects Playwright #16959: This PR also modifies the README.md to reflect changes in the command structure for running tests, specifically shifting from project-specific flags to a tagging system, which aligns with the updates made in the main PR regarding command usage.

Suggested reviewers

  • AndesKrrrrrrrrrrr

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.

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

24-26: Enhance JSDoc parameter descriptions

The new parameters need more detailed descriptions explaining their purpose and expected values.

Apply this diff to improve the documentation:

  * @param {number} config.timeoutMs - Timeout in milliseconds for server startup.
- * @param {string} config.app - Application to run.
- * @param {string} config.dependencies - Space-separated list of dependencies.
- * @param {boolean} config.proxies - Whether to use proxies.
+ * @param {string} config.app - Name of the application to run in the local environment.
+ * @param {string[]} config.dependencies - List of dependent services required to run the application.
+ * @param {boolean} config.proxies - Whether to enable proxy configuration for the local environment.

40-51: Consider refactoring command string construction

The current string concatenation approach could be improved for maintainability and safety.

Consider using an array to build the command parts:

-    command = `yarn infra run-local-env ${app} --print --no-secrets`
-    if (dependencies.length > 0) {
-      command += ` --dependencies ${dependencies}`
-    }
-    if (proxies) {
-      command += ' --proxies'
-    }
+    const commandParts = [
+      'yarn infra run-local-env',
+      app,
+      '--print',
+      '--no-secrets',
+      ...(dependencies.length > 0 ? ['--dependencies', dependencies.join(' ')] : []),
+      ...(proxies ? ['--proxies'] : [])
+    ]
+    command = commandParts.join(' ')

Line range hint 1-79: Well-structured configuration module design

The module follows good architectural principles:

  • Provides a flexible and type-safe configuration interface
  • Maintains backward compatibility while adding new features
  • Exports types for reuse across different NextJS applications
libs/testing/e2e/README.md (2)

Line range hint 25-35: Consider enhancing the configuration example

While the current example is good, it would be helpful to showcase more configuration options that were recently added to PlaywrightConfigParams, such as app, dependencies, and proxies.

Consider expanding the example like this:

import { createPlaywrightConfig } from '@island.is/testing/e2e'

const playwrightConfig = createPlaywrightConfig({
  webServerUrl: '<web-server-url>',
  command: '<command>', // Optional
  app: '<app-name>', // Optional: Specify the app being tested
  dependencies: ['<dependent-app>'], // Optional: List dependent apps
  proxies: { // Optional: Configure proxies
    '/api': 'http://localhost:3000'
  }
})

export default playwrightConfig
🧰 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 Tests with Tags: Use tags to include ...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)


61-71: Consider varying sentence structure in the "Run Tests with Tags" section

To improve readability and flow, consider rewording the examples to avoid repetitive sentence beginnings.

Here's a suggested revision:

- **Run Tests with Tags**: Filter tests using tags:

  ```bash
  # Execute tests with @fast tag only
  yarn nx e2e <app-name> --grep @fast

  # Skip tests marked with @fast
  yarn nx e2e <app-name> --grep-invert @fast

  # Include tests tagged as either @fast or @slow
  yarn nx e2e <app-name> --grep "@fast|@slow"

<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 Tests with Tags**: Use tags to include ...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

</details>

</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: .coderabbit.yaml**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between be1824e1bb9c09b5cf61988f996c2acd7eeac2ec and 0e87b4477d3a443fba847194a9e555ce23907656.

</details>

<details>
<summary>📒 Files selected for processing (2)</summary>

* `libs/testing/e2e/README.md` (2 hunks)
* `libs/testing/e2e/src/lib/config/playwright-config.ts` (4 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>📓 Path-based instructions (2)</summary>

<details>
<summary>libs/testing/e2e/README.md (1)</summary>

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."


</details>
<details>
<summary>libs/testing/e2e/src/lib/config/playwright-config.ts (1)</summary>

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."


</details>

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

<details>
<summary>libs/testing/e2e/README.md</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 Tests with Tags**: Use tags to include ...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (4)</summary>

<details>
<summary>libs/testing/e2e/src/lib/config/playwright-config.ts (2)</summary>

`6-9`: **LGTM: Interface changes are well-typed and flexible**

The new optional properties enhance configuration flexibility while maintaining type safety.

---

`36-39`: **LGTM: Parameter defaults are well-chosen**

The default values provide sensible fallbacks while maintaining type safety.

</details>
<details>
<summary>libs/testing/e2e/README.md (2)</summary>

`44-44`: **Command usage updates look good!**

The migration from `yarn e2e` to `yarn nx e2e` is consistently applied across all command examples, properly reflecting the new command structure for the nx workspace.



Also applies to: 52-52, 58-58, 65-65, 68-68, 71-71, 83-83, 89-89

---

Line range hint `1-24`: **Documentation structure is well-organized!**

The README follows documentation best practices with clear sections, proper hierarchy, and comprehensive coverage of the E2E testing library usage.

<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 Tests with Tags**: Use tags to include ...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

</details>

</details>

</details>

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

libs/testing/e2e/src/lib/config/playwright-config.ts Outdated Show resolved Hide resolved
@svanaeinars svanaeinars added the automerge Merge this PR as soon as all checks pass label Nov 21, 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 (1)
libs/testing/e2e/src/lib/config/playwright-config.ts (1)

24-26: Enhance return type documentation

The JSDoc could be more specific about the return type structure and its configuration options.

Add more details to the return type documentation:

- * @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.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0e87b44 and bf040eb.

📒 Files selected for processing (1)
  • libs/testing/e2e/src/lib/config/playwright-config.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
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."
🔇 Additional comments (4)
libs/testing/e2e/src/lib/config/playwright-config.ts (4)

6-9: LGTM: Interface changes follow TypeScript best practices

The interface updates properly define optional properties with clear types, maintaining good TypeScript practices.


36-39: LGTM: Well-structured parameter defaults

The new parameters are properly defined with sensible default values.


Line range hint 54-80: LGTM: Well-structured Playwright configuration

The configuration follows Playwright best practices with appropriate settings for different environments (CI vs local).


44-52: ⚠️ Potential issue

Critical: Command Injection Vulnerability

The command construction is vulnerable to command injection attacks through unsanitized input in app and dependencies. An attacker could inject malicious shell commands through these parameters.

Add input validation before command construction:

 if (!command) {
+  // Validate app name (alphanumeric, hyphens, and underscores only)
+  if (!/^[\w-]+$/.test(app)) {
+    throw new Error('Invalid app name. Only alphanumeric characters, hyphens, and underscores are allowed.');
+  }
+  // Validate each dependency name
+  if (!dependencies.every(dep => /^[\w-]+$/.test(dep))) {
+    throw new Error('Invalid dependency name. Only alphanumeric characters, hyphens, and underscores are allowed.');
+  }
   command = `yarn infra run-local-env ${app} --print --no-secrets`
   if (dependencies.length > 0) {
     command += ` --dependencies ${dependencies.join(' ')}`
   }

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 0e87b44 and bf040eb.

📒 Files selected for processing (1)
  • libs/testing/e2e/src/lib/config/playwright-config.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
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."
🔇 Additional comments (4)
libs/testing/e2e/src/lib/config/playwright-config.ts (4)

6-9: LGTM: Interface changes are well-structured

The new optional properties are properly typed and follow TypeScript best practices.


24-26: LGTM: Documentation is comprehensive

The JSDoc comments are well-maintained with clear descriptions for the new parameters.


36-39: LGTM: Parameter defaults are well-chosen

The new parameters have appropriate default values that maintain backward compatibility.


Line range hint 54-80: LGTM: Configuration is well-structured

The Playwright configuration is comprehensive and properly handles both CI and local development environments.

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.62%. Comparing base (6b0e779) to head (4bd2bc9).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16982   +/-   ##
=======================================
  Coverage   35.62%   35.62%           
=======================================
  Files        6914     6914           
  Lines      145990   145990           
  Branches    41446    41446           
=======================================
  Hits        52011    52011           
  Misses      93979    93979           
Flag Coverage Δ
judicial-system-backend 55.60% <ø> (ø)

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 6b0e779...4bd2bc9. Read the comment docs.

---- 🚨 Try these New Features:

@kodiakhq kodiakhq bot merged commit 57e6c90 into main Nov 21, 2024
33 checks passed
@kodiakhq kodiakhq bot deleted the chore/add-options-for-e2e-playwright-config branch November 21, 2024 17:06
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* chore(tests): Support more options E2E Playwright config

* Fix nested if statement

* Small correction

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
6 tasks
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