Skip to content

Commit c2694dc

Browse files
committed
fix: Add playwright server setup for CI
Signed-off-by: Enjeck C. <patrathewhiz@gmail.com>
1 parent 511ffb7 commit c2694dc

3 files changed

Lines changed: 78 additions & 7 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"build": "webpack --node-env production --progress",
88
"dev": "webpack --node-env development --progress",
99
"watch": "webpack --node-env development --progress --watch",
10-
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.vue src",
11-
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.vue src --fix",
10+
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.vue src playwright",
11+
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.vue src playwright --fix",
1212
"stylelint": "stylelint 'src/**/*.vue' 'css/**/*.css'",
1313
"stylelint:fix": "stylelint 'src/**/*.vue' 'css/**/*.css' --fix"
1414
},

‎playwright.config.ts‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,40 @@ export default defineConfig({
2424
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2525
use: {
2626
/* Base URL to use in actions like `await page.goto('./')`. */
27-
baseURL: process.env.BASE_URL ?? 'http://nextcloud.local',
27+
baseURL: process.env.BASE_URL ?? "http://localhost:8089",
2828

2929
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30-
trace: 'on-first-retry',
30+
trace: "on-first-retry",
3131

3232
/* Capture screenshot on failure */
33-
screenshot: 'only-on-failure',
33+
screenshot: "only-on-failure",
34+
},
35+
36+
webServer: {
37+
// Starts the Nextcloud docker container
38+
command: "npm run start:nextcloud",
39+
// we use sigterm to notify the script to stop the container
40+
// if it does not respond, we force kill it after 10 seconds
41+
gracefulShutdown: {
42+
signal: "SIGTERM",
43+
timeout: 10000,
44+
},
45+
reuseExistingServer: !process.env.CI,
46+
stderr: "pipe",
47+
stdout: "pipe",
48+
url: "http://127.0.0.1:8089",
49+
timeout: 5 * 60 * 1000, // max. 5 minutes for creating the container
50+
wait: {
51+
// we wait for this line to appear in the output of the webserver until consider it done
52+
stdout: /Nextcloud is now ready to use/,
53+
},
3454
},
3555

3656
projects: [
3757
{
38-
name: 'chromium',
58+
name: "chromium",
3959
use: {
40-
...devices['Desktop Chrome'],
60+
...devices["Desktop Chrome"],
4161
},
4262
},
4363
],
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
6+
import {
7+
configureNextcloud,
8+
startNextcloud,
9+
stopNextcloud,
10+
waitOnNextcloud,
11+
} from '@nextcloud/e2e-test-server/docker'
12+
import { readFileSync } from 'fs'
13+
import { execSync } from 'node:child_process'
14+
15+
async function start() {
16+
const appinfo = readFileSync('appinfo/info.xml').toString()
17+
const maxVersion = appinfo.match(
18+
/<nextcloud min-version="\d+" max-version="(\d\d+)" \/>/,
19+
)?.[1]
20+
21+
let branch = 'master'
22+
if (maxVersion) {
23+
const refs = execSync('git ls-remote --refs').toString('utf-8')
24+
branch = refs.includes(`refs/heads/stable${maxVersion}`)
25+
? `stable${maxVersion}`
26+
: branch
27+
}
28+
29+
return await startNextcloud(branch, true, {
30+
exposePort: 8089,
31+
})
32+
}
33+
34+
async function stop() {
35+
process.stderr.write('Stopping Nextcloud server…\n')
36+
await stopNextcloud()
37+
process.exit(0)
38+
}
39+
40+
process.on('SIGTERM', stop)
41+
process.on('SIGINT', stop)
42+
43+
// Start the Nextcloud docker container
44+
const ip = await start()
45+
await waitOnNextcloud(ip)
46+
await configureNextcloud(['notes'])
47+
48+
// Idle to wait for shutdown
49+
while (true) {
50+
await new Promise((resolve) => setTimeout(resolve, 5000))
51+
}

0 commit comments

Comments
 (0)