Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export default defineConfig({
url: "http://127.0.0.1:8089/index.php/apps/notes/",
timeout: 5 * 60 * 1000, // max. 5 minutes for creating the container
wait: {
// we wait for this line to appear in the output of the webserver until consider it done
stdout: /Nextcloud is now ready to use/,
// the start script prints this line once the Notes API answers requests
stdout: /Notes API is ready/,
},
},

Expand Down
30 changes: 30 additions & 0 deletions playwright/start-nextcloud-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ async function start() {
})
}

/**
* Poll the Notes API until it answers. The web workers cache the app config and
* the compiled routes in APCu for a few seconds, and `occ app:enable` runs in a
* separate process that cannot invalidate them, so requests sent right after
* enabling the app are answered with 404 until those caches expire.
*
* @param {string} ip Host and port the Nextcloud container is reachable at
*/
async function waitOnNotesApi(ip) {
const user = process.env.NC_USER ?? 'admin'
const password = process.env.NC_PASS ?? 'admin'
const headers = { Authorization: `Basic ${btoa(`${user}:${password}`)}` }
const deadline = Date.now() + 60_000

process.stdout.write('\nWaiting for the Notes API… ⏳\n')
while (true) {
const status = await fetch(`http://${ip}/index.php/apps/notes/api/v1/settings`, { headers })
.then((response) => response.status, () => 0)
if (status === 200) {
break
}
if (Date.now() > deadline) {
throw new Error(`Notes API is not reachable, last status: ${status}`)
}
await new Promise((resolve) => setTimeout(resolve, 500))
}
process.stdout.write('└─ Notes API is ready 🎉\n')
}

async function stop() {
process.stderr.write('Stopping Nextcloud server…\n')
await stopNextcloud()
Expand All @@ -44,6 +73,7 @@ process.on('SIGINT', stop)
const ip = await start()
await waitOnNextcloud(ip)
await configureNextcloud(['notes'])
await waitOnNotesApi(ip)

// Idle to wait for shutdown
while (true) {
Expand Down
Loading