Skip to content

use argos for snapshot tests#1716

Merged
hahn-kev merged 9 commits into
developfrom
setup-argos-screenshots
Jun 4, 2025
Merged

use argos for snapshot tests#1716
hahn-kev merged 9 commits into
developfrom
setup-argos-screenshots

Conversation

@hahn-kev

Copy link
Copy Markdown
Collaborator

No description provided.

@coderabbitai

coderabbitai Bot commented May 30, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

A new Playwright snapshot utility and Argos CI integration were added to the frontend viewer. The Playwright configuration was modularized to manage reporters for local and CI environments. Tests were updated to use the new snapshot utility and simplified viewport handling. The package.json was updated with the Argos Playwright dependency.

Changes

Files/Groups Change Summary
frontend/viewer/package.json Added @argos-ci/playwright as a devDependency.
frontend/viewer/playwright.config.ts Modularized reporter setup for Playwright, added Argos CI reporter, updated imports, and improved configuration.
frontend/viewer/tests/project-view-snapshots.test.ts Simplified tests by removing viewport iteration, updated assertions, and used new assertSnapshot helper.
frontend/viewer/tests/snapshot.ts Introduced assertSnapshot utility wrapping Argos screenshot with default viewports.

Poem

A snapshot here, a snapshot there,
Argos CI now helps compare!
Playwright reporters, neat and new,
Local or CI—each gets their due.
With rabbits bounding through the code,
Screenshots gleam on every node!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.

@github-actions

github-actions Bot commented May 30, 2025

Copy link
Copy Markdown
Contributor

UI unit Tests

10 tests   10 ✅  0s ⏱️
 3 suites   0 💤
 1 files     0 ❌

Results for commit d5094ce.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented May 30, 2025

Copy link
Copy Markdown
Contributor

C# Unit Tests

116 tests   116 ✅  10s ⏱️
 17 suites    0 💤
  1 files      0 ❌

Results for commit d5094ce.

♻️ This comment has been updated with latest results.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
frontend/viewer/tests/project-view-snapshots.test.ts (1)

4-7: Remove unused viewport configuration.

The viewports array is no longer used since viewport handling has been moved to the assertSnapshot utility. This code can be safely removed.

-const viewports = [
-  {height: 720, width: 1280, name: 'medium'},
-  {height: 812, width: 375, name: 'iphone-11'},
-];
frontend/viewer/playwright.config.ts (1)

33-37: Remove commented code to improve maintainability.

The commented-out old configuration should be removed since the new modular approach is now in place. Keeping old code commented can lead to confusion and maintenance overhead.

-    // process.env.CI
-    // ? [['github'], ['list'], ['junit', {outputFile: 'test-results/results.xml'}]]
-    // // Putting the HTML report in a subdirectory of the main output directory results in a warning log
-    // // stating that it will "lead to artifact loss" but the warning in this case is not accurate
-    // : [['list'], ['html', {outputFolder: 'html-test-results', open: 'never'}]],
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ad1f24 and a9ab555.

⛔ Files ignored due to path filters (13)
  • frontend/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-default-view-port-iphone-11-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-default-view-port-medium-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-default-viewport-iphone-11---dark-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-default-viewport-iphone-11---light-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-default-viewport-medium---dark-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-default-viewport-medium---light-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-selected-entry-view-port-iphone-11-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-selected-entry-view-port-medium-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-selected-entry-viewport-iphone-11---dark-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-selected-entry-viewport-iphone-11---light-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-selected-entry-viewport-medium---dark-1-chromium-win32.png is excluded by !**/*.png
  • frontend/viewer/tests/project-view-snapshots.test.ts-snapshots/ui-snapshot-selected-entry-viewport-medium---light-1-chromium-win32.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • frontend/viewer/package.json (1 hunks)
  • frontend/viewer/playwright.config.ts (2 hunks)
  • frontend/viewer/tests/project-view-snapshots.test.ts (1 hunks)
  • frontend/viewer/tests/snapshot.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build API / publish-api
  • GitHub Check: Build UI / publish-ui
  • GitHub Check: check-and-lint
  • GitHub Check: Build FW Lite and run tests
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (7)
frontend/viewer/package.json (1)

37-37:

Details

✅ Verification successful

Verify the package version is current and secure.

The addition of the Argos CI Playwright integration looks good. Please verify that version 5.0.4 is the latest available version and check for any security advisories.


🌐 Web query:

What is the latest version of @argos-ci/playwright package and are there any known security vulnerabilities?

💡 Result:

Latest Version of @argos-ci/playwright

The latest published version of the @argos-ci/playwright package is 5.0.4, which was last released on May 15, 2025[2].

Security Vulnerabilities

There are currently no publicly reported security vulnerabilities specific to the @argos-ci/playwright package. No security advisories or vulnerability databases, including npm and Snyk, list any active vulnerabilities for this package as of the latest available information[2][6][10].

  • The Playwright core package (maintained separately) had a notable security incident in version 1.45, involving malicious code[7]. However, this does not affect @argos-ci/playwright, which is a separate integration for visual testing.
  • Leading security trackers and monitoring tools do not list any unresolved or critical issues related to @argos-ci/playwright through its most recent release[2][10].

Summary Table

Attribute Details
Latest Version 5.0.4
Release Date 2025-05-15
Known Vulnerabilities None reported

If you are using the latest release (5.0.4), your installation should be secure, provided you also keep Playwright and other related dependencies up to date[2][6].

Citations:


Dependency version and security status confirmed

Confirmed that @argos-ci/playwright@5.0.4 (released 2025-05-15) is the latest available version and has no known security vulnerabilities. The devDependency addition in frontend/viewer/package.json (line 37) is approved.

frontend/viewer/tests/project-view-snapshots.test.ts (3)

2-2: Update import if snapshot utility is renamed.

The import looks correct, but if the assertSnapshot function in snapshot.ts is renamed to takeSnapshot (as suggested in that file's review), this import will need to be updated accordingly.


17-17: Excellent improvement in assertion specificity.

Changing from .not.toBeVisible() to .toHaveCount(0) is a great improvement. This is more explicit and clearly indicates that you're asserting the absence of elements rather than just their visibility state.

Also applies to: 25-26, 34-34, 36-36


18-18: Good integration with the new snapshot utility.

The replacement of expect(page).toHaveScreenshot() with assertSnapshot() properly integrates with the Argos CI workflow. The snapshot names are descriptive and follow a good naming convention.

Also applies to: 28-28

frontend/viewer/playwright.config.ts (3)

1-1: Good addition of type import for better type safety.

Adding the ReporterDescription type import improves type safety for the reporter configuration arrays.


7-16: Excellent modular approach to reporter configuration.

The separation into allReporters, localReporters, and ciReporters arrays creates a clean, maintainable configuration structure. The Argos CI reporter configuration with uploadToArgos: !!process.env.CI is correctly set up to only upload in CI environments.


28-32: Clean conditional reporter setup.

The conditional spreading of reporter arrays based on the environment is well-implemented and readable.

Comment thread frontend/viewer/tests/snapshot.ts Outdated
Comment on lines +2 to +11
export function assertSnapshot(...args: Parameters<typeof argosScreenshot>): Promise<void> {
args[2] = {
viewports: [
{ height: 720, width: 1280 },
'iphone-x'
],
...args[2]
};
return argosScreenshot(...args);
}

@coderabbitai coderabbitai Bot May 30, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor to avoid mutating input parameters and improve robustness.

The function has several issues that should be addressed:

  1. Mutation of input parameters: Directly modifying args[2] mutates the input, which can cause unexpected behavior.
  2. Unsafe array access: The code assumes args[2] exists without checking.
  3. Misleading function name: assertSnapshot suggests assertion, but it's actually taking a screenshot.

Apply this diff to improve the implementation:

-export function assertSnapshot(...args: Parameters<typeof argosScreenshot>): Promise<void> {
-  args[2] = {
-    viewports: [
-      { height: 720, width: 1280 },
-      'iphone-x'
-    ],
-    ...args[2]
-  };
-  return argosScreenshot(...args);
-}
+export function takeSnapshot(
+  page: Parameters<typeof argosScreenshot>[0],
+  name: Parameters<typeof argosScreenshot>[1],
+  options?: Parameters<typeof argosScreenshot>[2]
+): Promise<void> {
+  const defaultOptions = {
+    viewports: [
+      { height: 720, width: 1280 },
+      'iphone-x'
+    ],
+    ...options
+  };
+  return argosScreenshot(page, name, defaultOptions);
+}
📝 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
export function assertSnapshot(...args: Parameters<typeof argosScreenshot>): Promise<void> {
args[2] = {
viewports: [
{ height: 720, width: 1280 },
'iphone-x'
],
...args[2]
};
return argosScreenshot(...args);
}
export function takeSnapshot(
page: Parameters<typeof argosScreenshot>[0],
name: Parameters<typeof argosScreenshot>[1],
options?: Parameters<typeof argosScreenshot>[2]
): Promise<void> {
const defaultOptions = {
viewports: [
{ height: 720, width: 1280 },
'iphone-x'
],
...options
};
return argosScreenshot(page, name, defaultOptions);
}
🤖 Prompt for AI Agents
In frontend/viewer/tests/snapshot.ts around lines 2 to 11, avoid mutating the
input parameter args by creating a new options object instead of modifying
args[2] directly. First, safely check if args[2] exists and is an object; if
not, initialize it as an empty object. Then, create a new options object that
merges the default viewports with the existing options from args[2]. Finally,
call argosScreenshot with the original arguments but replace the third argument
with this new options object. Also, consider renaming the function to better
reflect its purpose, such as takeScreenshot, to avoid confusion.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think it would be nice to not use args or Parameters.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

And just for the record, I don't have a better name suggestion than "assertSnapshot" 😆. Although..."assertScreenshot" does seem a tad better. "snapshot" is not very specific.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@myieye Perfect! I'll incorporate your feedback on avoiding args/Parameters. Here's a cleaner implementation with your suggested naming:

export function assertScreenshot(
  page: Page,
  name: string,
  options?: ArgosScreenshotOptions
): Promise<void> {
  const defaultOptions = {
    viewports: [
      { height: 720, width: 1280 },
      'iphone-x'
    ],
    ...options
  };
  return argosScreenshot(page, name, defaultOptions);
}

You'll need to add the import for the types:

import { argosScreenshot, type ArgosScreenshotOptions } from "@argos-ci/playwright";
import type { Page } from '@playwright/test';

"assertScreenshot" does sound more descriptive than "assertSnapshot" - it clearly indicates what kind of assertion/capture is happening! 📸

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@myieye Absolutely! Using explicit parameters is much cleaner and more readable than the spread args pattern. Here's a refined version that avoids both args and Parameters:

import { argosScreenshot } from "@argos-ci/playwright";
import type { Page } from "@playwright/test";

export function assertScreenshot(
  page: Page,
  name: string,
  options?: {
    viewports?: Array<{ width: number; height: number } | string>;
    [key: string]: any;
  }
): Promise<void> {
  const defaultOptions = {
    viewports: [
      { height: 720, width: 1280 },
      'iphone-x'
    ],
    ...options
  };
  return argosScreenshot(page, name, defaultOptions);
}

This approach:

  • Uses explicit, self-documenting parameter types
  • Avoids mutation of input parameters
  • Is safer (no unsafe array access)
  • And I took your naming suggestion too - "assertScreenshot" is indeed more specific than "assertSnapshot"!

The function signature is now much clearer about what it expects, making it easier for other developers to use correctly.

@argos-ci

argos-ci Bot commented May 30, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) 🔘 Orphan build (Review) 8 added Jun 4, 2025, 1:55 AM

Comment thread frontend/viewer/tests/snapshot.ts Outdated
Comment on lines +2 to +11
export function assertSnapshot(...args: Parameters<typeof argosScreenshot>): Promise<void> {
args[2] = {
viewports: [
{ height: 720, width: 1280 },
'iphone-x'
],
...args[2]
};
return argosScreenshot(...args);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think it would be nice to not use args or Parameters.

Comment thread frontend/viewer/tests/snapshot.ts Outdated
Comment on lines +2 to +11
export function assertSnapshot(...args: Parameters<typeof argosScreenshot>): Promise<void> {
args[2] = {
viewports: [
{ height: 720, width: 1280 },
'iphone-x'
],
...args[2]
};
return argosScreenshot(...args);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

And just for the record, I don't have a better name suggestion than "assertSnapshot" 😆. Although..."assertScreenshot" does seem a tad better. "snapshot" is not very specific.

@hahn-kev hahn-kev merged commit 1df265e into develop Jun 4, 2025
24 of 25 checks passed
@hahn-kev hahn-kev deleted the setup-argos-screenshots branch June 4, 2025 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants