Skip to content

Commit ba045ef

Browse files
authored
Merge pull request #2484 from nextcloud/test/playwright-use-nc-docker-functions
Tests: use nc docker functions in playwright
2 parents 9349516 + 37e3bb5 commit ba045ef

File tree

3 files changed

+8
-76
lines changed

3 files changed

+8
-76
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@mdi/js": "^7.4.47",
5757
"@mdi/svg": "^7.4.47",
5858
"@nextcloud/browserslist-config": "^3.0.1",
59-
"@nextcloud/cypress": "^1.0.0-beta.12",
59+
"@nextcloud/cypress": "^1.0.0-beta.13",
6060
"@nextcloud/eslint-config": "^8.4.1",
6161
"@nextcloud/prettier-config": "^1.1.0",
6262
"@nextcloud/stylelint-config": "^3.0.1",

playwright/support/utils/session.ts

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,14 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { getContainer } from '@nextcloud/cypress/docker'
6+
import { runExec, addUser } from '@nextcloud/cypress/docker'
77
import { expect, type APIRequestContext } from '@playwright/test'
88

9-
/**
10-
* Run a shell command on the docker container
11-
* @param command The command to run on the docker container
12-
* @param options Options to pass
13-
* @param options.env Process environment to pass
14-
* @param options.user User to use for executing the command
15-
* @param options.rejectOnError Reject the returned promise in case of non-zero exit code
16-
*/
17-
export async function runShell(
18-
command: string,
19-
options?: {
20-
user?: string
21-
rejectOnError?: boolean
22-
env?: Record<string, string | number>
23-
},
24-
) {
25-
const container = getContainer()
26-
27-
const exec = await container.exec({
28-
Cmd: ['sh', '-c', command],
29-
Env: Object.entries(options?.env ?? {}).map(
30-
([name, value]) => `${name}=${value}`,
31-
),
32-
User: options?.user,
33-
AttachStderr: true,
34-
AttachStdout: true,
35-
})
36-
37-
const stream = await exec.start({})
38-
return new Promise((resolve, reject) => {
39-
let data = ''
40-
stream.on('data', (chunk: string) => {
41-
data += chunk
42-
})
43-
stream.on('error', (error: unknown) => reject(error))
44-
stream.on('end', async () => {
45-
const inspect = await exec.inspect({})
46-
if (options?.rejectOnError !== false && inspect.ExitCode) {
47-
reject(data)
48-
} else {
49-
resolve(data)
50-
}
51-
})
52-
})
53-
}
54-
55-
/**
56-
* Run an OCC command
57-
* @param command OCC command to run
58-
* @param options Options to pass
59-
* @param options.env Process environment to pass
60-
* @param options.rejectOnError Reject the returned promise in case of non-zero exit code
61-
*/
62-
export async function runOCC(
63-
command: string,
64-
options?: {
65-
env?: Record<string, string | number>
66-
rejectOnError?: boolean
67-
},
68-
) {
69-
return await runShell(`php ./occ ${command}`, {
70-
...options,
71-
user: 'www-data',
72-
})
73-
}
74-
759
/**
7610
* Restore database and data folder for tests
7711
*/
7812
export function restoreDatabase() {
79-
runShell('rm -rf data && tar -xf backup.tar')
13+
runExec('rm -rf data && tar -xf backup.tar')
8014
}
8115

8216
/**
@@ -116,8 +50,6 @@ export async function login(
11650
*/
11751
export async function createRandomUser(): Promise<string> {
11852
const uid = (Math.random() + 1).toString(36).substring(7)
119-
await runOCC(`user:add --password-from-env ${uid}`, {
120-
env: { OC_PASS: uid },
121-
})
53+
await addUser(uid)
12254
return uid
12355
}

0 commit comments

Comments
 (0)