Skip to content

Commit a0694fd

Browse files
authored
feat(e2e): add Playwright configuration and initial tests (#675)
1 parent 723c15c commit a0694fd

File tree

5 files changed

+119
-3
lines changed

5 files changed

+119
-3
lines changed

web/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pnpm-lock.yaml
99
.idea*
1010
types/auto-imports.d.ts
1111
types/components.d.ts
12+
tests/e2e/.output/*

web/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"lint": "npm-run-all -s lint:tsc lint:eslint lint:stylelint",
1616
"lint:tsc": "vue-tsc --noEmit",
1717
"lint:eslint": "eslint . --cache --fix",
18-
"lint:stylelint": "stylelint \"src/**/*.{css,scss,vue}\" --cache --fix"
18+
"lint:stylelint": "stylelint \"src/**/*.{css,scss,vue}\" --cache --fix",
19+
"test:e2e": "playwright test --config=playwright.config.ts"
1920
},
2021
"dependencies": {
2122
"@imengyu/vue3-context-menu": "^1.4.4",
@@ -58,9 +59,11 @@
5859
"@iconify/json": "^2.2.309",
5960
"@iconify/vue": "^4.3.0",
6061
"@intlify/unplugin-vue-i18n": "^6.0.3",
62+
"@playwright/test": "^1.54.2",
6163
"@stylistic/stylelint-config": "^2.0.0",
6264
"@types/archiver": "^6.0.3",
6365
"@types/mockjs": "^1.0.10",
66+
"@types/node": "^24.1.0",
6467
"@types/nprogress": "^0.2.3",
6568
"@types/path-browserify": "^1.0.3",
6669
"@types/qs": "^6.9.18",

web/playwright.config.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
import process from 'node:process'
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// import dotenv from 'dotenv';
9+
// import path from 'path';
10+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
11+
12+
const BASE_DIR = 'tests/e2e'
13+
const OUTPUT_DIR = `${BASE_DIR}/.output`
14+
15+
/**
16+
* See https://playwright.dev/docs/test-configuration.
17+
*/
18+
export default defineConfig({
19+
testDir: BASE_DIR,
20+
/* output directory for test artifacts. */
21+
outputDir: `${OUTPUT_DIR}/test-results`,
22+
/* Run tests in files in parallel */
23+
fullyParallel: true,
24+
/* Fail the build on CI if you accidentally left test.only in the source code. */
25+
forbidOnly: !!process.env.CI,
26+
/* Retry on CI only */
27+
retries: process.env.CI ? 2 : 0,
28+
/* Opt out of parallel tests on CI. */
29+
workers: process.env.CI ? 1 : undefined,
30+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
31+
reporter: [
32+
['html', { open: 'never', outputFolder: `${OUTPUT_DIR}/html-report` }],
33+
],
34+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35+
use: {
36+
/* Base URL to use in actions like `await page.goto('/')`. */
37+
baseURL: 'http://localhost:2888',
38+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
39+
trace: 'retain-on-first-failure',
40+
/* Collect video when retrying the failed test. See https://playwright.dev/docs/screenshots */
41+
screenshot: 'only-on-failure',
42+
/* Collect video when retrying the failed test. See https://playwright.dev/docs/videos */
43+
// video: 'retain-on-failure',
44+
},
45+
46+
/* Configure projects for major browsers */
47+
projects: [
48+
{
49+
name: 'chromium',
50+
use: { ...devices['Desktop Chrome'] },
51+
},
52+
53+
// {
54+
// name: 'firefox',
55+
// use: { ...devices['Desktop Firefox'] },
56+
// },
57+
//
58+
// {
59+
// name: 'webkit',
60+
// use: { ...devices['Desktop Safari'] },
61+
// },
62+
63+
/* Test against mobile viewports. */
64+
// {
65+
// name: 'Mobile Chrome',
66+
// use: { ...devices['Pixel 5'] },
67+
// },
68+
// {
69+
// name: 'Mobile Safari',
70+
// use: { ...devices['iPhone 12'] },
71+
// },
72+
73+
/* Test against branded browsers. */
74+
// {
75+
// name: 'Microsoft Edge',
76+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
77+
// },
78+
// {
79+
// name: 'Google Chrome',
80+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
81+
// },
82+
],
83+
84+
/* Run your local dev server before starting the tests */
85+
webServer: {
86+
command: 'pnpm run dev',
87+
url: 'http://localhost:2888',
88+
reuseExistingServer: !process.env.CI,
89+
},
90+
})

web/tests/e2e/example.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('https://playwright.dev/')
5+
6+
// Expect a title "to contain" a substring.
7+
await expect(page).toHaveTitle(/Playwright/)
8+
})
9+
10+
test('get started link', async ({ page }) => {
11+
await page.goto('https://playwright.dev/')
12+
13+
// Click the get started link.
14+
await page.getByRole('link', { name: 'Get started' }).click()
15+
16+
// Expects page to have a heading with the name of Installation.
17+
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible()
18+
})

web/tsconfig.node.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
"module": "ESNext",
55
"moduleResolution": "bundler",
66
"allowSyntheticDefaultImports": true,
7-
"skipLibCheck": true
7+
"skipLibCheck": true,
8+
"types": [
9+
"node"
10+
]
811
},
912
"include": [
1013
"package.json",
1114
"vite.config.ts",
12-
"vite/**/*.ts"
15+
"vite/**/*.ts",
16+
"playwright.config.ts"
1317
]
1418
}

0 commit comments

Comments
 (0)