Skip to content

Commit e18155f

Browse files
committed
ci: setup playwright pipeline
1 parent e35fce4 commit e18155f

File tree

4 files changed

+83
-50
lines changed

4 files changed

+83
-50
lines changed

.github/workflows/test.yml

+35-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ jobs:
6363
with:
6464
token: ${{ secrets.CODECOV_TOKEN }}
6565

66-
e2e_tests:
67-
name: E2E test
66+
cypress_e2e_tests:
67+
name: Cypress E2E test
6868
runs-on: ubuntu-latest
6969
steps:
7070
- uses: actions/checkout@v4
@@ -100,3 +100,36 @@ jobs:
100100

101101
- name: E2E test
102102
run: pnpm test:e2e:ci
103+
104+
playwright_e2e_tests:
105+
name: Playwright E2E test
106+
runs-on: ubuntu-latest
107+
steps:
108+
- uses: actions/checkout@v4
109+
110+
- uses: pnpm/action-setup@v4
111+
with:
112+
version: 9
113+
run_install: false
114+
115+
- name: Use Node.js 22.x
116+
uses: actions/setup-node@v4
117+
with:
118+
node-version: 22.x
119+
cache: pnpm
120+
121+
- name: Install dependencies
122+
run: pnpm install
123+
124+
- name: Install playwright binary
125+
run: pnpm playwright install --with-deps
126+
127+
- name: E2E test
128+
run: pnpm test:playwright:ci
129+
130+
- uses: actions/upload-artifact@v4
131+
if: always()
132+
with:
133+
name: playwright-report
134+
path: playwright-report/
135+
retention-days: 30

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
"type": "module",
66
"scripts": {
77
"prepare": "simple-git-hooks",
8-
"dev": "vite --port 5173",
8+
"dev": "vite --port 4173",
99
"build": "vite build",
1010
"serve": "vite preview --port 4173",
1111
"type-check": "vue-tsc --noEmit",
1212
"lint": "eslint --fix .",
1313
"test": "npm run test:unit && npm run test:e2e:ci",
14-
"test:cypress:local": "cypress open --e2e -c baseUrl=http://localhost:5173",
14+
"test:cypress": "npm run build && concurrently -rk -s first \"npm run serve\" \"cypress run --e2e",
15+
"test:cypress:ui": "cypress open --e2e",
1516
"test:cyprsss:prod": "cypress run --e2e -c baseUrl=https://vue3-realworld-example-app-mutoe.vercel.app",
16-
"test:e2e": "npm run build && concurrently -rk -s first \"npm run serve\" \"cypress open --e2e -c baseUrl=http://localhost:4173\"",
17-
"test:e2e:ci": "npm run build && concurrently -rk -s first \"npm run serve\" \"cypress run --e2e -c baseUrl=http://localhost:4173\"",
18-
"test:playwright:ci": "playwright test",
19-
"test:playwright:local": "playwright test --ui",
20-
"test:playwright:local:debug": "playwright test --ui --headed --debug",
17+
"test:playwright": "npm run build && cross-env CI=true playwright test",
18+
"test:playwright:prod": "cross-env E2E_BASE_URL='https://vue3-realworld-example-app-mutoe.vercel.app' playwright test",
19+
"test:playwright:ui": "playwright test --ui",
20+
"test:playwright:ui:debug": "playwright test --ui --headed --debug",
2121
"test:unit": "vitest run",
2222
"generate:api": "curl -sL https://raw.githubusercontent.com/gothinkster/realworld/main/api/openapi.yml -o ./src/services/openapi.yml && sta -p ./src/services/openapi.yml -o ./src/services -n api.ts"
2323
},
@@ -40,6 +40,7 @@
4040
"@vitejs/plugin-vue": "^5.1.2",
4141
"@vitest/coverage-v8": "^2.0.5",
4242
"concurrently": "^8.2.2",
43+
"cross-env": "^7.0.3",
4344
"cypress": "^13.13.2",
4445
"eslint": "^8.57.0",
4546
"eslint-plugin-cypress": "^3.4.0",

playwright.config.ts

+28-41
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { defineConfig, devices } from '@playwright/test'
77
// import dotenv from 'dotenv';
88
// dotenv.config({ path: path.resolve(__dirname, '.env') });
99

10-
const baseURL = 'http://localhost:5173'
11-
1210
const isCI = process.env.CI
11+
const baseURL = process.env.E2E_BASE_URL || 'http://localhost:4173'
1312

1413
/**
1514
* See https://playwright.dev/docs/test-configuration.
@@ -26,15 +25,16 @@ export default defineConfig({
2625
workers: isCI ? 1 : undefined,
2726
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
2827
reporter: [
29-
['line'],
3028
['html', { open: 'never' }],
29+
isCI ? ['github'] : ['list'],
3130
],
3231
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3332
use: {
3433
/* Base URL to use in actions like `await page.goto('/')`. */
3534
baseURL,
3635

37-
navigationTimeout: 4000,
36+
navigationTimeout: isCI ? 10_000 : 4000,
37+
actionTimeout: isCI ? 10_000 : 4000,
3838

3939
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4040
screenshot: 'only-on-failure',
@@ -43,46 +43,33 @@ export default defineConfig({
4343
},
4444

4545
/* Configure projects for major browsers */
46-
projects: [
47-
{
48-
name: 'chromium',
49-
use: { ...devices['Desktop Chrome'] },
50-
},
51-
52-
isCI && {
53-
name: 'firefox',
54-
use: { ...devices['Desktop Firefox'] },
55-
},
56-
57-
isCI && {
58-
name: 'webkit',
59-
use: { ...devices['Desktop Safari'] },
60-
},
61-
62-
/* Test against mobile viewports. */
63-
// {
64-
// name: 'Mobile Chrome',
65-
// use: { ...devices['Pixel 5'] },
66-
// },
67-
// {
68-
// name: 'Mobile Safari',
69-
// use: { ...devices['iPhone 12'] },
70-
// },
71-
72-
/* Test against branded browsers. */
73-
// {
74-
// name: 'Microsoft Edge',
75-
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
76-
// },
77-
// {
78-
// name: 'Google Chrome',
79-
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
80-
// },
81-
].filter(Boolean),
46+
projects: isCI
47+
? [
48+
{
49+
name: 'chromium',
50+
use: { ...devices['Desktop Chrome'] },
51+
},
52+
{
53+
name: 'firefox',
54+
use: { ...devices['Desktop Firefox'] },
55+
},
56+
{
57+
name: 'webkit',
58+
use: { ...devices['Desktop Safari'] },
59+
},
60+
]
61+
: [
62+
{
63+
name: 'chromium',
64+
use: {
65+
...devices['Desktop Chrome'],
66+
},
67+
},
68+
],
8269

8370
/* Run your local dev server before starting the tests */
8471
webServer: {
85-
command: 'npm run dev',
72+
command: isCI ? 'pnpm serve' : 'npm run dev',
8673
url: baseURL,
8774
reuseExistingServer: !isCI,
8875
ignoreHTTPSErrors: true,

pnpm-lock.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)