Skip to content

feat: create pw-test command #1092

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

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

Conversation

ferrandiaz
Copy link
Contributor

@ferrandiaz ferrandiaz commented Jun 19, 2025

Affected Components

  • CLI
  • Create CLI
  • Test
  • Docs
  • Examples
  • Other

Notes for the Reviewer

  • Add a new command pw-test
  • New command allows you to run whatever playwright command you would like
npx checkly pw-test -l us-east-1 -- --project foo --grep @bar
  • following industry standards the commands before the separator -- are related to checkly, the ones after the separator are related to playwright
npx checkly pw-test  { checkly flags } -- { playwright flags }
  • command allows you to run the test on checkly without having a checkly.config.ts file nor the monitor defined
  • If the user wants to create a basic checkly config or wants to add the test they just ran as a monitor they can do that by passing the --create-check flag, if this flag is passed no test/check will run, it will just add the monitor to the config.
npx checkly pw-test -l us-east-1 --create-check -- --project foo --grep @bar

This will create something that will look like:

import { defineConfig } from 'checkly'

const config = defineConfig({
  logicalId: 'logical-id',
  projectName: 'project-name',
  checks: {
    playwrightConfigPath: './playwright.config.ts',
    playwrightChecks: [
      {
        logicalId: 'playwright-check---project-foo---grep--bar',
        name: 'Playwright Test: --project foo --grep @bar',
        testCommand: 'npx playwright test --project foo --grep @bar',
        locations: [
          'us-east-1',
        ],
        frequency: 10,
      },
    ],
    frequency: 10,
    locations: [
      'us-east-1',
    ],
  },
  cli: {
    runLocation: 'us-east-1',
  },
})

export default config

Copy link

coderabbitai bot commented Jun 19, 2025

Walkthrough

This change introduces a new pw-test CLI command for running Playwright tests within the Checkly platform. It adds supporting helpers for AST-based config manipulation, test location and reporter preparation, and Playwright check integration. New end-to-end tests and fixture projects are added, and related config and utility modules are refactored to support Playwright test orchestration and configuration updates.

Changes

Files/Groups Change Summary
packages/cli/src/commands/pw-test.ts Adds new PwTestCommand for Playwright test integration, config manipulation, and test execution.
packages/cli/src/helpers/test-helper.ts, packages/cli/src/helpers/write-config-helpers.ts Adds helpers for run location, reporter prep, CLI flag splitting, and AST-based config manipulation.
packages/cli/src/commands/sync-playwright.ts, packages/cli/src/commands/test.ts Refactors to use new helper modules for config and test location logic; removes duplicated logic.
packages/cli/src/services/checkly-config-loader.ts, packages/cli/src/services/util.ts Updates config loader and default config util to support Playwright check integration and conditional file writing.
packages/cli/e2e/__tests__/pw-test.spec.ts, packages/cli/e2e/__tests__/help.spec.ts Adds new E2E tests for pw-test command and updates CLI help output tests.
packages/cli/e2e/__tests__/fixtures/test-pwt-native/* Adds new Playwright test fixture: configs, test files, and package.json for E2E scenarios.

Possibly related PRs

  • checkly/checkly-cli#1065: Restores Playwright suite support in the CLI, directly related to Playwright integration and the new pw-test command.
  • checkly/checkly-cli#1064: Reverts removal of Playwright check-related code, directly tied to the reintroduction and expansion of Playwright test integration in this PR.
  • checkly/checkly-cli#1042: Focuses on Playwright check support in deploy/test commands and config handling, overlapping with this PR’s Playwright check and config integration.

Suggested reviewers

  • umutuzgur

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-26T07_59_48_869Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29ac4ae and 90caccf.

📒 Files selected for processing (1)
  • packages/cli/src/helpers/write-config-helpers.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/cli/src/helpers/write-config-helpers.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test - windows-latest
  • GitHub Check: test - ubuntu-latest
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@ferrandiaz ferrandiaz force-pushed the ferran/sc-0/pwt-test-command-flags branch from a5beca7 to 7c7e151 Compare June 19, 2025 10:02
@ferrandiaz ferrandiaz added the build Issue regarding building and packaging label Jun 19, 2025

This comment has been minimized.

@ferrandiaz ferrandiaz added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels Jun 19, 2025

This comment has been minimized.

@ferrandiaz ferrandiaz force-pushed the ferran/sc-0/pwt-test-command-flags branch from 2727e21 to ed656b5 Compare June 20, 2025 09:57
@ferrandiaz ferrandiaz force-pushed the ferran/sc-0/pwt-test-command-flags branch from ed656b5 to 29ac4ae Compare June 20, 2025 10:03
@ferrandiaz ferrandiaz added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels Jun 20, 2025

This comment has been minimized.

@ferrandiaz ferrandiaz requested a review from umutuzgur June 20, 2025 15:04
@ferrandiaz ferrandiaz marked this pull request as ready for review June 20, 2025 15:04
Copy link

@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: 4

🧹 Nitpick comments (6)
packages/cli/src/helpers/test-helper.ts (2)

12-12: Consider adding proper type annotations for the API parameter.

The api parameter uses any type, which reduces type safety and IDE support.

Consider defining a proper interface or importing the actual API type:

-  api: any,
+  api: ApiClient, // or whatever the actual type is

38-38: Consider adding proper type annotations for the API parameter.

Same issue as above - the api parameter should have a proper type instead of any.

packages/cli/e2e/__tests__/pw-test.spec.ts (1)

16-25: Consider the necessity of the extended timeout.

The test has a very long timeout (130 seconds) which may indicate slow operations. While this might be necessary for Playwright test execution, consider if this can be optimized or if the timeout can be reduced.

packages/cli/src/commands/pw-test.ts (3)

219-220: Missing retry strategy implementation.

The retry strategy feature is not yet implemented for Playwright tests.

Would you like me to create an issue to track the implementation of retry strategy support for the pw-test command?


369-379: Fix static analysis warnings in package manager detection.

The catch block has an unused variable and unnecessary continue statement.

       try {
         await fs.access(lockFilePath);
         return pm.name;
-      } catch (error) {
-        continue;
+      } catch {
+        // Try next package manager
       }

77-79: Fix misleading flag description.

The skip-record flag description incorrectly states it will record results when it actually skips recording.

     'skip-record': Flags.boolean({
-      description: 'Record test results in Checkly as a test session with full logs, traces and videos.',
+      description: 'Skip recording test results in Checkly as a test session.',
       default: false,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e74e2a2 and 29ac4ae.

⛔ Files ignored due to path filters (1)
  • packages/cli/e2e/__tests__/fixtures/test-pwt-native/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (15)
  • packages/cli/e2e/__tests__/fixtures/test-pwt-native/checkly.config.original.ts (1 hunks)
  • packages/cli/e2e/__tests__/fixtures/test-pwt-native/checkly.config.ts (1 hunks)
  • packages/cli/e2e/__tests__/fixtures/test-pwt-native/package.json (1 hunks)
  • packages/cli/e2e/__tests__/fixtures/test-pwt-native/playwright.config.ts (1 hunks)
  • packages/cli/e2e/__tests__/fixtures/test-pwt-native/test-project/pw-test-project.test.ts (1 hunks)
  • packages/cli/e2e/__tests__/fixtures/test-pwt-native/test/pw-test-example.test.ts (1 hunks)
  • packages/cli/e2e/__tests__/help.spec.ts (1 hunks)
  • packages/cli/e2e/__tests__/pw-test.spec.ts (1 hunks)
  • packages/cli/src/commands/pw-test.ts (1 hunks)
  • packages/cli/src/commands/sync-playwright.ts (2 hunks)
  • packages/cli/src/commands/test.ts (2 hunks)
  • packages/cli/src/helpers/test-helper.ts (1 hunks)
  • packages/cli/src/helpers/write-config-helpers.ts (1 hunks)
  • packages/cli/src/services/checkly-config-loader.ts (3 hunks)
  • packages/cli/src/services/util.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/cli/src/services/util.ts (1)
packages/cli/src/services/checkly-config-loader.ts (2)
  • PlaywrightSlimmedProp (18-21)
  • ChecklyConfig (23-94)
packages/cli/src/commands/test.ts (4)
packages/cli/src/helpers/test-helper.ts (2)
  • prepareRunLocation (9-36)
  • prepareReportersTypes (52-57)
packages/cli/src/commands/trigger.ts (2)
  • prepareRunLocation (188-213)
  • prepareReportersTypes (233-238)
packages/cli/src/config.ts (1)
  • Region (8-31)
packages/cli/src/reporters/reporter.ts (1)
  • ReporterType (19-19)
🪛 Biome (1.9.4)
packages/cli/src/commands/pw-test.ts

[error] 375-375: Unnecessary continue statement

Unsafe fix: Delete the unnecessary continue statement

(lint/correctness/noUnnecessaryContinue)

🪛 GitHub Check: lint
packages/cli/src/commands/pw-test.ts

[warning] 374-374:
'error' is defined but never used

🔇 Additional comments (16)
packages/cli/src/helpers/test-helper.ts (1)

9-36: Good separation of concerns and clear precedence logic.

The function properly handles the precedence of CLI flags over config options and includes comprehensive error handling for various edge cases.

packages/cli/e2e/__tests__/help.spec.ts (1)

47-47: LGTM! Correct addition of the new pw-test command to help output verification.

The test properly verifies that the new pw-test command appears in the core commands section with the correct description.

packages/cli/e2e/__tests__/fixtures/test-pwt-native/package.json (1)

5-5: Verify the Playwright version for security and compatibility.

Since this is June 2025 and the specified version is from 2024, please ensure this version is still supported and free from known vulnerabilities.

What is the latest stable version of @playwright/test and are there any known security vulnerabilities in version 1.53.1?
packages/cli/e2e/__tests__/fixtures/test-pwt-native/test-project/pw-test-project.test.ts (1)

5-7: Test fixture serves its purpose for E2E testing.

While the test logic is trivial, this appears to be intentional for a test fixture used to validate the pw-test CLI command functionality.

packages/cli/e2e/__tests__/fixtures/test-pwt-native/test/pw-test-example.test.ts (1)

4-10: Test fixture appropriately structured for CLI testing.

The tests are intentionally simple and serve their purpose as fixtures for validating the pw-test command's tag filtering and execution capabilities.

packages/cli/e2e/__tests__/fixtures/test-pwt-native/checkly.config.original.ts (1)

1-23: LGTM! Well-structured test fixture configuration.

The Checkly configuration is properly structured with appropriate test settings. The comment about using .test.ts suffix to avoid Jest transpilation errors is a valuable insight for maintaining test compatibility.

packages/cli/e2e/__tests__/fixtures/test-pwt-native/playwright.config.ts (1)

3-17: Configuration looks good with a note on timeout value.

The Playwright configuration is well-structured for testing multi-project setups. The specific timeout of 1234ms appears intentional for testing purposes, but verify this is the desired value rather than a placeholder.

packages/cli/e2e/__tests__/fixtures/test-pwt-native/checkly.config.ts (1)

1-23: LGTM! Working copy of test fixture configuration.

This configuration mirrors the original version and serves as the working copy for e2e tests that modify the config file. The identical structure and content are appropriate for this testing pattern.

packages/cli/src/services/checkly-config-loader.ts (3)

132-132: Good addition of optional parameter for config writing control.

The new writeChecklyConfig parameter with a default value of true maintains backward compatibility while providing flexibility for scenarios where config file writing should be controlled.


147-147: Parameter properly passed through the call chain.

The parameter is correctly passed from the main function to the helper function.


160-171: Conditional config writing implemented correctly.

The conditional logic properly controls when the config file is written based on the shouldWriteConfig parameter, while maintaining the existing error handling flow.

packages/cli/e2e/__tests__/pw-test.spec.ts (2)

10-14: Good test cleanup pattern implemented.

The afterEach hook properly restores the original config file after each test, ensuring test isolation. This is essential for reliable e2e testing.


27-43: Comprehensive assertions for config modification test.

The test thoroughly verifies that the --create-check flag properly adds Playwright configuration to the Checkly config file, including checking the structure, path, and specific check properties.

Verify that the test fixtures contain the expected @TAG-B tagged tests that these e2e tests depend on:

#!/bin/bash
# Description: Verify that @TAG-B tagged tests exist in the fixture directory
# Expected: Find test files with @TAG-B annotations

fd -e .ts . packages/cli/e2e/__tests__/fixtures/test-pwt-native/ --exec grep -l "@TAG-B" {}
packages/cli/src/services/util.ts (1)

294-306: LGTM! Good enhancement for Playwright check configuration.

The function now properly supports optional Playwright check configuration while maintaining backward compatibility with sensible defaults.

packages/cli/src/commands/sync-playwright.ts (1)

8-43: Clean refactoring to use shared AST manipulation helpers.

Good extraction of common AST manipulation logic into reusable helpers, improving code maintainability and following DRY principles.

packages/cli/src/commands/test.ts (1)

26-163: Good refactoring to use shared test helper functions.

The extraction of run location and reporter preparation logic into reusable helpers improves code organization and maintainability.

@ferrandiaz ferrandiaz added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels Jun 26, 2025

This comment has been minimized.

@ferrandiaz ferrandiaz requested a review from sorccu June 30, 2025 14:01
@ferrandiaz ferrandiaz added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels Jul 1, 2025
Copy link

github-actions bot commented Jul 1, 2025

🎉 Experimental release successfully published on npm

npm install checkly@0.0.0-pr.1092.98bcb5e

Copy link
Member

@sorccu sorccu left a comment

Choose a reason for hiding this comment

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

I've left some comments about things that should be addressed.

@sorccu
Copy link
Member

sorccu commented Jul 2, 2025

Also, the Windows tests are flaky because the GH Windows runner is ultra slow - rerun after implementing the changes above if it still doesn't succeed.

Comment on lines +288 to +294
const parseArgs = args.map(arg => {
if (arg.includes(' ')) {
arg = `"${arg}"`
}
return arg
})
const input = parseArgs.join(' ') || ''
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to not do this here, because the unsafeDisplayCommand (used in getTestCommand) quotes args for you. Instead, the input args should just be passed to execCommand() as array items. However, that has some implications for the test name below which also uses the manually quoted input string.

@ferrandiaz ferrandiaz requested a review from sorccu July 4, 2025 08:15
import { parseProject } from '../services/project-parser'
import type { Runtime } from '../rest/runtimes'
import { Diagnostics, Session } from '../constructs'
import { Flags, ux } from '@oclif/core'
Copy link
Member

Choose a reason for hiding this comment

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

You can remove the unused ux import

Copy link
Member

@sorccu sorccu left a comment

Choose a reason for hiding this comment

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

Added a minor comment, but approving for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issue regarding building and packaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants