Skip to content

Commit aea8de4

Browse files
authored
test(e2e): migrate from cypress to playwright (#1540)
1 parent d837efc commit aea8de4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+864
-1744
lines changed

.eslintrc.cjs

+1-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ module.exports = {
1515
},
1616
},
1717
{
18-
files: ['**/e2e/**/*.cy.ts', '**/e2e/cypress/**/*.ts'],
19-
extends: 'plugin:cypress/recommended',
20-
rules: {
21-
'@typescript-eslint/no-namespace': 'off',
22-
},
23-
},
24-
{
25-
files: ['**/tests/**/*.ts', 'tsup.config.ts'],
18+
files: ['**/tests/**/*.ts', 'e2e/**/*.ts', 'tsup.config.ts'],
2619
rules: {
2720
'@typescript-eslint/explicit-function-return-type': 'off',
2821
'import/no-extraneous-dependencies': 'off',

.github/workflows/e2e.yml

+2-17
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,9 @@ jobs:
3535
- name: Install dependencies
3636
run: pnpm install --frozen-lockfile
3737

38-
- name: Get cypress cache path
38+
- name: Install playwright chromium
3939
working-directory: ./e2e
40-
shell: bash
41-
run: |
42-
echo "CYPRESS_CACHE_PATH=$(pnpm cypress cache path)" >> $GITHUB_ENV
43-
44-
- name: Setup cypress cache
45-
uses: actions/cache@v3
46-
with:
47-
path: ${{ env.CYPRESS_CACHE_PATH }}
48-
key: cypress-${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('pnpm-lock.yaml') }}
49-
restore-keys: |
50-
cypress-${{ runner.os }}-node-${{ matrix.node }}-
51-
cypress-${{ runner.os }}-
52-
53-
- name: Install cypress binary
54-
working-directory: ./e2e
55-
run: pnpm cypress install
40+
run: pnpm playwright install chromium
5641

5742
- name: Build source files
5843
run: pnpm build

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ dist/
1313
coverage/
1414

1515
# E2E temp files
16-
e2e/cypress/screenshots/
16+
e2e/playwright-report/
17+
e2e/test-results/
1718

1819
# Node modules
1920
node_modules/

.vscode/extensions.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"recommendations": [
33
"dbaeumer.vscode-eslint",
44
"esbenp.prettier-vscode",
5+
"ms-playwright.playwright",
56
"vue.volar"
67
]
78
}

CONTRIBUTING.md

+2-15
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pnpm build
4343
- [TypeScript](https://www.typescriptlang.org/) as the development language
4444
- [ESLint](https://eslint.org/) + [Prettier](https://prettier.io/) for code linting and formatting
4545
- [Vitest](https://vitest.dev/) for unit testing
46-
- [Cypress](https://www.cypress.io/) for end-to-end testing
46+
- [Playwright](https://playwright.dev/) for end-to-end testing
4747

4848
### Scripts
4949

@@ -69,7 +69,7 @@ The `lint` script uses ESLint to check all source files.
6969

7070
#### `pnpm test`
7171

72-
The `test` script uses Vitest to run unit testings, and uses Cypress to run end-to-end testings.
72+
The `test` script uses Vitest to run unit testings, and uses Playwright to run end-to-end testings.
7373

7474
## End-to-end Testing
7575

@@ -97,19 +97,6 @@ pnpm docs:serve
9797

9898
### Run E2E Tests
9999

100-
After starting a dev server or a preview server, you can run e2e tests in another terminal:
101-
102-
```bash
103-
# open Cypress GUI
104-
pnpm cy:open:dev
105-
pnpm cy:open:build
106-
# or, run tests in command line
107-
pnpm cy:run:dev
108-
pnpm cy:run:build
109-
```
110-
111-
If you don't want to start a server and run tests in two different terminals, you can make use of the following commands:
112-
113100
```bash
114101
# run e2e tests in dev mode
115102
pnpm e2e:dev

CONTRIBUTING_zh.md

+2-15
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pnpm build
4343
- [TypeScript](https://www.typescriptlang.org/) 作为开发语言
4444
- [ESLint](https://eslint.org/) + [Prettier](https://prettier.io/) 用于代码检查和格式化
4545
- [Vitest](https://vitest.dev/) 用于单元测试
46-
- [Cypress](https://www.cypress.io/) 用于端到端测试
46+
- [Playwright](https://playwright.dev/) 用于端到端测试
4747

4848
### 开发脚本
4949

@@ -69,7 +69,7 @@ pnpm build
6969

7070
#### `pnpm test`
7171

72-
`test` 命令使用 Vitest 来运行单元测试,使用 Cypress 来运行端到端测试。
72+
`test` 命令使用 Vitest 来运行单元测试,使用 Playwright 来运行端到端测试。
7373

7474
## 端到端测试
7575

@@ -97,19 +97,6 @@ pnpm docs:serve
9797

9898
### 运行 E2E 测试
9999

100-
在启动开发服务器或预览服务器后,你可以在另一个终端中运行 e2e 测试:
101-
102-
```bash
103-
# 启动 Cypress 图形界面
104-
pnpm cy:open:dev
105-
pnpm cy:open:build
106-
# 或者,直接在命令行中运行测试
107-
pnpm cy:run:dev
108-
pnpm cy:run:build
109-
```
110-
111-
如果你不想在两个不同终端内启动服务器和运行测试,你可以使用如下命令:
112-
113100
```bash
114101
# 在开发模式下运行 e2e 测试
115102
pnpm e2e:dev

e2e/cypress.config.ts

-82
This file was deleted.

e2e/cypress/support/commands.ts

-34
This file was deleted.

e2e/cypress/support/e2e.ts

-1
This file was deleted.

e2e/docs/components/route-link.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
### Slots
4747

4848
- <RouteLink to="/README.md"><span>text</span></RouteLink>
49-
- <RouteLink to="/README.md"><span>text</span><span>text</span></RouteLink>
49+
- <RouteLink to="/README.md"><span>text</span><span>text2</span></RouteLink>
5050

5151
### Hash and query
5252

e2e/docs/router/navigation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<button id="home" @click="goHome">Home</button>
2-
<button id="404" @click="go404">404</button>
2+
<button id="not-found" @click="go404">404</button>
33

44
<script setup lang="ts">
55
import { useRouter } from 'vuepress/client';

e2e/package.json

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"cy:open:build": "cross-env E2E_COMMAND=build cypress open",
8-
"cy:open:dev": "cross-env E2E_COMMAND=dev cypress open",
9-
"cy:run:build": "cross-env E2E_COMMAND=build cypress run",
10-
"cy:run:dev": "cross-env E2E_COMMAND=dev cypress run",
117
"docs:build": "vuepress build docs --clean-cache --clean-temp",
128
"docs:build-webpack": "cross-env E2E_BUNDLER=webpack pnpm docs:build",
139
"docs:clean": "rimraf docs/.vuepress/.temp docs/.vuepress/.cache docs/.vuepress/dist",
1410
"docs:dev": "vuepress dev docs --clean-cache --clean-temp",
1511
"docs:dev-webpack": "cross-env E2E_BUNDLER=webpack pnpm docs:dev",
1612
"docs:serve": "anywhere -s -h localhost -p 9080 -d docs/.vuepress/dist",
17-
"e2e:build": "pnpm docs:clean && pnpm docs:build && start-server-and-test docs:serve http-get://localhost:9080 cy:run:build",
18-
"e2e:dev": "pnpm docs:clean && start-server-and-test docs:dev http-get://127.0.0.1:9080 cy:run:dev"
13+
"e2e:build": "cross-env E2E_COMMAND=build playwright test",
14+
"e2e:build-webpack": "cross-env E2E_COMMAND=build E2E_BUNDLER=webpack playwright test",
15+
"e2e:dev": "cross-env E2E_COMMAND=dev playwright test",
16+
"e2e:dev-webpack": "cross-env E2E_COMMAND=dev E2E_BUNDLER=webpack playwright test"
1917
},
2018
"dependencies": {
2119
"@vuepress-e2e/conditional-exports": "file:./modules/conditional-exports",
@@ -27,10 +25,8 @@
2725
"vuepress": "workspace:*"
2826
},
2927
"devDependencies": {
28+
"@playwright/test": "^1.43.0",
3029
"anywhere": "^1.6.0",
31-
"cross-env": "^7.0.3",
32-
"cypress": "^13.7.2",
33-
"process": "^0.11.10",
34-
"start-server-and-test": "^2.0.3"
30+
"cross-env": "^7.0.3"
3531
}
3632
}

e2e/playwright.config.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
import { BASE, BUNDLER, isCI, isDev } from './utils/env'
3+
4+
const commandPart1 = isDev ? 'docs:dev' : 'docs:build'
5+
const commandPart2 = BUNDLER === 'vite' ? '' : `-${BUNDLER}`
6+
const commandPart3 = isDev ? '' : ' && pnpm docs:serve'
7+
8+
export default defineConfig({
9+
testDir: 'tests',
10+
forbidOnly: isCI,
11+
reporter: isCI ? 'github' : 'line',
12+
retries: isCI ? 2 : 0,
13+
workers: isCI || isDev ? 1 : undefined,
14+
projects: [
15+
{
16+
name: 'chromium',
17+
use: { ...devices['Desktop Chrome'] },
18+
},
19+
],
20+
use: {
21+
baseURL: `http://127.0.0.1:9080${BASE}`,
22+
trace: 'on-first-retry',
23+
},
24+
webServer: {
25+
command: `pnpm docs:clean && pnpm ${commandPart1}${commandPart2}${commandPart3}`,
26+
url: 'http://127.0.0.1:9080',
27+
reuseExistingServer: !isCI,
28+
},
29+
})

e2e/tests/client-config/root-components.cy.ts

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
test('should render root components correctly', async ({ page }) => {
4+
await page.goto('', { waitUntil: 'domcontentloaded' })
5+
6+
await expect(page.locator('.root-component-from-theme p')).toHaveText(
7+
'root component from theme',
8+
)
9+
await expect(page.locator('.root-component-from-user-config p')).toHaveText(
10+
'root component from user config',
11+
)
12+
})

0 commit comments

Comments
 (0)