Skip to content

Commit 36d5d8d

Browse files
authored
Merge pull request #126 from argos-ci/blog-vercel-preview
blog: vercel preview article
2 parents 20a9abc + 20e0462 commit 36d5d8d

File tree

4 files changed

+97
-18
lines changed

4 files changed

+97
-18
lines changed

app/blog/[...slug]/page.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,21 @@ async function Siblings({ slug }: { slug: string }) {
9797
height={article.image.height}
9898
src={article.image.src}
9999
alt={article.imageAlt}
100+
data-visual-test="blackout"
100101
/>
101102
<PostCardBody>
102103
{article.category && (
103-
<PostCardTag>{article.category}</PostCardTag>
104+
<PostCardTag data-visual-test="blackout">
105+
{article.category}
106+
</PostCardTag>
104107
)}
105-
<PostCardTitle>{article.title}</PostCardTitle>
106-
<PostCardFooter>
108+
<PostCardTitle
109+
classname="line-clamp-2"
110+
data-visual-test="blackout"
111+
>
112+
{article.title}
113+
</PostCardTitle>
114+
<PostCardFooter data-visual-test="blackout">
107115
<PostCardAuthor>{article.author}</PostCardAuthor>
108116
<div className="text-xs text-mauve-10">|</div>
109117
<PostCardDate date={article.date} />

articles/vercel-preview/index.mdx

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: How to run Argos visual testing on Vercel Preview
3+
description: Guide to run Argos visual testing on Vercel Preview to ensure consistency in production-like environment.
4+
slug: vercel-preview
5+
category: Developer Experience
6+
author: Jeremy Sfez
7+
date: 2024-02-01
8+
image: ./main.jpg
9+
imageAlt: Vercel covered with Argos
10+
---
11+
12+
Great news for Vercel enthusiasts! Argos seamlessly integrates visual testing with Vercel Preview, enabling you to detect visual regressions in a production-like environment effortlessly. This guide walks you through setting it up with GitHub Actions and Playwright, streamlining your workflow.
13+
14+
<MainImage />
15+
16+
## Motivation behind this feature
17+
18+
Responding to user feedback, we recognized the need for visual testing directly on Vercel Previews, especially for environments akin to production settings. This approach is not only cost-effective, eliminating the need for separate test environments, but also enhances test accuracy by mirroring production conditions closely.
19+
20+
## How to run Argos on Vercel Preview
21+
22+
### 1. Set up Argos
23+
24+
Start by following the Q[Quickstart guide](https://argos-ci.com/docs) to integrate Argos with Playwright. This foundational step ensures that Argos is ready to run visual tests during your CI process.
25+
26+
### 2. Run tests on your Vercel Preview
27+
28+
Adapt your CI workflow with this GitHub Actions configuration to enable Argos visual testing on Vercel Previews:
29+
30+
```yml
31+
name: Playwright + Argos Tests
32+
on: deployment_status:
33+
jobs:
34+
test:
35+
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: actions/setup-node@v3
40+
- name: Install dependencies
41+
run: npm ci && npx playwright install --with-deps
42+
- name: Run Playwright tests
43+
run: npx playwright test
44+
env:
45+
BASE_URL: ${{ github.event.deployment_status.environment_url }}
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
ARGOS_BRANCH: ${{ github.event.deployment_status.environment == 'Production' && 'main' || '' }}
48+
```
49+
50+
For a comprehensive explanation of each step, consult the [Argos documentation](https://argos-ci.com/docs/run-on-preview-deployment).
51+
52+
Next, update your Playwright config file is updated to reflect the preview's URL and configure it to ignore the Vercel toolbar for cleaner test results:
53+
54+
```ts
55+
export default defineConfig({
56+
use: {
57+
# 👉 URL generated for the preview
58+
baseURL: process.env.BASE_URL,
59+
},
60+
extraHTTPHeaders: {
61+
# 👉 Hide vercel toolbar in tests
62+
"x-vercel-skip-toolbar": "0",
63+
},
64+
});
65+
```
66+
67+
Assuming you have automatic deploys set up, you’ll see the results of your deploy in your pull request. Upon a successful deploy, the E2E workflow will start on the preview.
68+
69+
![Github pull-request check statuses](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0zu0bwdykzsu9bvfgzw.png)
70+
71+
## Conclusion
72+
73+
Leveraging Argos with Vercel Previews not only enhances visual consistency in a near-production environment but also optimizes your CI process by eliminating the need for additional environments for testing. This integration streamlines your workflow, ensuring that your projects meet the highest standards of visual quality while being cost-effective.

articles/vercel-preview/main.jpg

201 KB
Loading

components/PostCard.tsx

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { clsx } from "clsx";
21
import Image, { ImageProps } from "next/image";
3-
import type { ComponentProps, ReactNode } from "react";
4-
import { twc } from "react-twc";
2+
import type { ComponentProps } from "react";
3+
import { TwcComponentProps, twc } from "react-twc";
54

6-
export const PostCard = twc.div`rounded-lg border bg-subtle text-left transition duration-300 hover:-translate-y-2 hover:scale-[101%]"`;
5+
export const PostCard = twc.div`rounded-lg border bg-subtle text-left transition duration-300 hover:-translate-y-2 hover:scale-[101%]`;
76

87
export interface PostCardImageProps extends ImageProps {
98
extended?: Boolean;
@@ -52,17 +51,16 @@ export const PostCardTag: React.FC<{ children: React.ReactNode }> = (props) => (
5251
<p className="mb-2 text-xs text-low" {...props} />
5352
);
5453

55-
export const PostCardTitle = ({
56-
extended,
57-
children,
58-
}: {
59-
extended?: Boolean;
60-
children: ReactNode;
61-
}) => (
62-
<h2 className={`mb-2 ${extended ? "text-4xl" : "text-2xl"} font-accent text`}>
63-
{children}
64-
</h2>
65-
);
54+
type PostCardTitleProps = TwcComponentProps<"h2"> & {
55+
extended?: boolean;
56+
classname?: string;
57+
};
58+
59+
export const PostCardTitle = twc.h2<PostCardTitleProps>((props) => [
60+
"mb-2 font-accent",
61+
props.extended ? "text-4xl" : "text-2xl",
62+
props.classname,
63+
]);
6664

6765
export const PostCardDescription = (props: ComponentProps<"div">) => (
6866
<div className="mb-8 leading-normal text-low" {...props} />

0 commit comments

Comments
 (0)