Skip to content

Commit d3b3b2f

Browse files
committed
chore(test): Migrate cypress offline tests to playwright
I was sick of debugging flaky Cypress tests, so I gave Playwright a try. Signed-off-by: Jonas <jonas@freesources.org>
1 parent 997d6b0 commit d3b3b2f

11 files changed

Lines changed: 450 additions & 50 deletions

File tree

.github/workflows/playwright.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
name: Playwright Tests
5+
on:
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
timeout-minutes: 60
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout app
15+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
16+
17+
- name: Check composer.json
18+
id: check_composer
19+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v2
20+
with:
21+
files: 'composer.json'
22+
23+
- name: Install composer dependencies
24+
if: steps.check_composer.outputs.files_exists == 'true'
25+
run: composer install --no-dev
26+
27+
- name: Read package.json node and npm engines version
28+
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
29+
id: versions
30+
with:
31+
fallbackNode: '^20'
32+
fallbackNpm: '^10'
33+
34+
- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
35+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
36+
with:
37+
node-version: ${{ steps.versions.outputs.nodeVersion }}
38+
39+
- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
40+
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"
41+
42+
- name: Install node dependencies & build app
43+
run: |
44+
npm ci
45+
TESTING=true npm run build --if-present
46+
47+
- name: Install Playwright Browsers
48+
run: npx playwright install chromium --only-shell
49+
50+
- name: Run Playwright tests
51+
run: npx playwright test
52+
53+
- uses: actions/upload-artifact@v5
54+
if: always()
55+
with:
56+
name: playwright-report
57+
path: playwright-report/
58+
retention-days: 30

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ cypress/snapshots/actual
88
cypress/snapshots/diff
99
cypress/videos/
1010
cypress/downloads/
11+
/playwright-report/
1112
.php-cs-fixer.cache
13+
/test-results/
1214
/tests/clover.xml
1315
/tests/.phpunit.result.cache
1416
dist/

cypress/e2e/offline.spec.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

package-lock.json

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
"scripts": {
1313
"build": "NODE_ENV=production NODE_OPTIONS='--max-old-space-size=4096' vite --mode production build",
1414
"dev": "NODE_ENV=development NODE_OPTIONS='--max-old-space-size=4096' vite --mode development build",
15-
"lint": "tsc && ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.ts,.vue src cypress",
16-
"lint:fix": "tsc && ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.ts,.vue src cypress --fix",
15+
"lint": "tsc && ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.ts,.vue src cypress playwright",
16+
"lint:fix": "tsc && ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.ts,.vue src cypress playwright --fix",
1717
"prettier": "prettier --check .",
1818
"prettier:change": "git diff HEAD --name-only | xargs prettier --write --no-error-on-unmatched-pattern",
1919
"prettier:fix": "prettier --write .",
2020
"serve": "BASE=${BASE:-/apps/text} NODE_ENV=development vite --mode development serve --host",
21+
"start:nextcloud": "node playwright/start-nextcloud-server.mjs",
2122
"test": "NODE_ENV=test vitest run",
2223
"test:coverage": "NODE_ENV=test vitest run --coverage",
2324
"test:cypress": "cd cypress && ./runLocal.sh run",
@@ -116,6 +117,7 @@
116117
"@nextcloud/eslint-config": "^8.4.2",
117118
"@nextcloud/prettier-config": "^1.2.0",
118119
"@nextcloud/vite-config": "^1.7.2",
120+
"@playwright/test": "^1.56.1",
119121
"@types/markdown-it": "^14.1.2",
120122
"@vitejs/plugin-vue2": "^2.3.4",
121123
"@vitest/coverage-v8": "^4.0.3",

playwright.config.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { defineConfig, devices } from '@playwright/test'
7+
8+
/**
9+
* See https://playwright.dev/docs/test-configuration.
10+
*/
11+
export default defineConfig({
12+
testDir: './playwright',
13+
14+
/* Run tests in files in parallel */
15+
fullyParallel: true,
16+
/* Fail the build on CI if you accidentally left test.only in the source code. */
17+
forbidOnly: !!process.env.CI,
18+
/* Retry on CI only */
19+
retries: process.env.CI ? 2 : 0,
20+
/* Opt out of parallel tests on CI. */
21+
workers: process.env.CI ? 1 : undefined,
22+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23+
reporter: process.env.CI ? 'github' : 'list',
24+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25+
use: {
26+
/* Base URL to use in actions like `await page.goto('./')`. */
27+
baseURL: process.env.baseURL ?? 'http://localhost:8089/index.php/',
28+
29+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30+
trace: 'on-first-retry',
31+
},
32+
33+
projects: [
34+
// Our global setup to configure the Nextcloud docker container
35+
{
36+
name: 'setup',
37+
testMatch: /setup\.ts$/,
38+
},
39+
40+
{
41+
name: 'chromium',
42+
use: {
43+
...devices['Desktop Chrome'],
44+
},
45+
dependencies: ['setup'],
46+
},
47+
],
48+
49+
webServer: {
50+
// Starts the Nextcloud docker container
51+
command: 'npm run start:nextcloud',
52+
reuseExistingServer: !process.env.CI,
53+
url: 'http://127.0.0.1:8089',
54+
stderr: 'pipe',
55+
stdout: 'pipe',
56+
timeout: 5 * 60 * 1000, // max. 5 minutes for creating the container
57+
},
58+
})

0 commit comments

Comments
 (0)