Skip to content

Commit 7606a7a

Browse files
committed
blog: improve vercel preview article
1 parent 49feda7 commit 7606a7a

File tree

2 files changed

+107
-17
lines changed

2 files changed

+107
-17
lines changed

articles/vercel-preview/index.mdx

+107-17
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,116 @@
11
---
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
2+
title: "Guide: Integrating Argos Visual Testing in Vercel Preview"
3+
description: "A guide to setting up Argos integration with Vercel Preview using GitHub Actions."
54
category: Developer Experience
65
author: Jeremy Sfez
76
date: 2024-02-01
87
image: ./main.jpg
98
imageAlt: Vercel covered with Argos
109
---
1110

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.
11+
Argos now seamlessly integrates integrates with Vercel Preview for visual testing, offering a streamlined approach to catch visual regressions in a production-like environment — without the hassle of complex setups. his guide will walk you through implementing Argos with Vercel Preview via GitHub Actions, complete with source code insights.
1312

1413
<MainImage />
1514

16-
## Motivation behind this feature
15+
## Why Visual Testing with Vercel Preview? Key Advantages
1716

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.
17+
- **Direct Visual Verification:** Allows for immediate identification of visual changes in pull requests, ensuring what you see is what you get in production.
18+
- **Cost Reduction:** Reduces CI expenses by eliminating the need to duplicate test environments.
19+
- **Production-like Environment Testing:** Offers a closer approximation to the live site, increasing test reliability.
1920

20-
## How to run Argos on Vercel Preview
21+
**Note:** This method is optimal for repeatable tests that don't significantly alter the environment, as certain tests (e.g. those involving user deletion) may not be applicable.
2122

22-
### 1. Set up Argos
23+
## Getting Started with Argos: Setup Guide
2324

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+
### Prerequisites
2526

26-
### 2. Run tests on your Vercel Preview
27+
Before integrating Argos into Vercel Preview for visual testing, I ensured:
2728

28-
Adapt your CI workflow with this GitHub Actions configuration to enable Argos visual testing on Vercel Previews:
29+
1. Set up a [Next.js](https://nextjs.org/) project with [Playwright](https://playwright.dev).
30+
2. Integrated Playwright tests into CI/CD.
31+
3. Deployed the project on Vercel.
32+
33+
### 1. Project Importation to Argos
34+
35+
I [signed up into Argos](https://app.argos-ci.com/signup) and imported my project. Once done, Argos display an `ARGOS_TOKEN` for this repository. I saved it for the next step.
36+
37+
I [signed up into Argos](https://app.argos-ci.com/signup) on Argos and added my project. After this, Argos generated an `ARGOS_TOKEN` for my repository. I saved it for later.
38+
39+
![Argos GitHub token](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wra1891953mfv4kt6tcs.png)
40+
41+
### 2. Package Installation
42+
43+
```sh
44+
npm install --save-dev @argos-ci/playwright
45+
```
46+
47+
### 3. Setup Argos in Playwright config file
48+
49+
Update the `playwright.config.ts` file:
50+
51+
```ts
52+
import { defineConfig } from "@playwright/test";
53+
54+
export default defineConfig({
55+
reporter: [
56+
process.env.CI ? ["dot"] : ["list"],
57+
[
58+
"@argos-ci/playwright/reporter",
59+
{
60+
uploadToArgos: !!process.env.CI,
61+
token: process.env.ARGOS_TOKEN,
62+
},
63+
],
64+
],
65+
use: {
66+
trace: "on-first-retry",
67+
screenshot: "only-on-failure",
68+
},
69+
});
70+
```
71+
72+
### 4. Screenshot my app
73+
74+
I utilized the [Screenshot pages script](https://argos-ci.com/docs/screenshot-pages-script) from Argos's documentation for capturing my application's homepage. This script is flexible for adding more pages in the future.
75+
76+
```ts
77+
import { argosScreenshot } from "@argos-ci/playwright";
78+
import { test } from "@playwright/test";
79+
80+
const baseUrl = "http://localhost:3000";
81+
const pages = [
82+
{ name: "homepage", path: "/" },
83+
// { name: "faq", path: "/faq" },
84+
// { name: "contact", path: "/contact-us" },
85+
// { name: "pricing", path: "/pricing" },
86+
];
87+
88+
test("screenshot pages", async ({ page }, workerInfo) => {
89+
for (const { name, path } of pages) {
90+
const browserName = workerInfo.project.name;
91+
await page.goto(`${baseUrl}${path}`);
92+
await argosScreenshot(page, `${name}-${browserName}`);
93+
}
94+
});
95+
```
96+
97+
### 5. Set up ARGOS_TOKEN and test integration
98+
99+
First, I set up `ARGOS_TOKEN` as a repository secret on GitHub. Then, I pushed my branch to Github and monitored the status checks to ensure everything was functioning as expected: Playwright, Vercel, and Argos.
100+
101+
![Github tests with Argos](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/om5itnow41f3koolbwio.png)
102+
103+
## Run Argos on Vercel Preview
104+
105+
To run my tests on Vercel Preview, I updated my CI workflow file:
29106

30107
```yml
31108
name: Playwright + Argos Tests
109+
# 👉 Trigger on deployment event
32110
on: deployment_status:
33111
jobs:
34112
test:
113+
# 👉 Run tests only if the deployment is successful
35114
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
36115
runs-on: ubuntu-latest
37116
steps:
@@ -41,33 +120,44 @@ jobs:
41120
run: npm ci && npx playwright install --with-deps
42121
- name: Run Playwright tests
43122
run: npx playwright test
123+
# 👉 Add this variables
44124
env:
45125
BASE_URL: ${{ github.event.deployment_status.environment_url }}
46126
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47127
ARGOS_BRANCH: ${{ github.event.deployment_status.environment == 'Production' && 'main' || '' }}
48128
```
49129
50-
For a comprehensive explanation of each step, consult the [Argos documentation](https://argos-ci.com/docs/run-on-preview-deployment).
130+
For a comprehensive explanation of each step, read [Argos documentation](https://argos-ci.com/docs/run-on-preview-deployment).
51131
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:
132+
Then, I updated my Playwright's config file:
53133
54134
```ts
55135
export default defineConfig({
56136
use: {
57-
# 👉 URL generated for the preview
137+
// URL generated for the preview
58138
baseURL: process.env.BASE_URL,
59139
},
60140
extraHTTPHeaders: {
61-
# 👉 Hide vercel toolbar in tests
141+
// Hide vercel toolbar in tests
62142
"x-vercel-skip-toolbar": "0",
63143
},
64144
});
65145
```
66146

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.
147+
After this my are merged, upon a successful deploy, the E2E workflow start on the preview:
68148

69149
![Github pull-request check statuses](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0zu0bwdykzsu9bvfgzw.png)
70150

151+
## Explore the Source Code
152+
153+
![Github pull-request check statuses](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhp02ieazr6f38o8q915.png)
154+
155+
Explore my GitHub for a detailed guide on integrating Argos with Vercel Preview, particularly highlighted in Pull Request #2 and the live Vercel deployment:
156+
157+
- [Github Repository](https://github.com/jsfez/argos-vercel-preview)
158+
- [Pull Request #2 - test: run argos on vercel preview](https://github.com/jsfez/argos-vercel-preview/pull/2)
159+
- [Deployed Project](https://argos-vercel-preview-gimral7da-jeremy-smooth-code.vercel.app/)
160+
71161
## Conclusion
72162

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.
163+
Integrating Argos and Vercel Preview offers a practical solution for improving visual testing in CI workflows. This setup simplifies identifying visual changes, ensuring your projects look as intended before going live. By following this guide, you're equipped to implement an effective visual testing strategy that minimizes errors and enhances the reliability of your deployments, all within the familiar environment of your existing CI/CD pipeline.

articles/vercel-preview/main.jpg

74.8 KB
Loading

0 commit comments

Comments
 (0)