diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-14 17:17:01 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-14 17:17:01 +0100 |
commit | 3cf68b869decf07ff7435fe1436d4f3134df1bf4 (patch) | |
tree | 836efe5ddc626fef3ba4c96269efbca305f46256 /client/e2e/src/utils | |
parent | a6f919e455f2c6ae8f2194da4aa66824a6bfd09e (diff) | |
download | PeerTube-3cf68b869decf07ff7435fe1436d4f3134df1bf4.tar.gz PeerTube-3cf68b869decf07ff7435fe1436d4f3134df1bf4.tar.zst PeerTube-3cf68b869decf07ff7435fe1436d4f3134df1bf4.zip |
Ability for admins to set default upload values
Diffstat (limited to 'client/e2e/src/utils')
-rw-r--r-- | client/e2e/src/utils/hooks.ts | 64 | ||||
-rw-r--r-- | client/e2e/src/utils/index.ts | 2 | ||||
-rw-r--r-- | client/e2e/src/utils/server.ts | 63 |
3 files changed, 129 insertions, 0 deletions
diff --git a/client/e2e/src/utils/hooks.ts b/client/e2e/src/utils/hooks.ts new file mode 100644 index 000000000..e42c6a5d8 --- /dev/null +++ b/client/e2e/src/utils/hooks.ts | |||
@@ -0,0 +1,64 @@ | |||
1 | import { ChildProcessWithoutNullStreams } from 'child_process' | ||
2 | import { basename } from 'path' | ||
3 | import { runCommand, runServer } from './server' | ||
4 | |||
5 | let appInstance: string | ||
6 | let app: ChildProcessWithoutNullStreams | ||
7 | |||
8 | async function beforeLocalSuite (suite: any) { | ||
9 | const config = buildConfig(suite.file) | ||
10 | |||
11 | await runCommand('npm run clean:server:test -- ' + appInstance) | ||
12 | app = runServer(appInstance, config) | ||
13 | } | ||
14 | |||
15 | function afterLocalSuite () { | ||
16 | app.kill() | ||
17 | app = undefined | ||
18 | } | ||
19 | |||
20 | function beforeLocalSession (config: { baseUrl: string }, capabilities: { browserName: string }) { | ||
21 | appInstance = capabilities['browserName'] === 'chrome' ? '1' : '2' | ||
22 | config.baseUrl = 'http://localhost:900' + appInstance | ||
23 | } | ||
24 | |||
25 | async function onBrowserStackPrepare () { | ||
26 | const appInstance = '1' | ||
27 | |||
28 | await runCommand('npm run clean:server:test -- ' + appInstance) | ||
29 | app = runServer(appInstance) | ||
30 | } | ||
31 | |||
32 | function onBrowserStackComplete () { | ||
33 | app.kill() | ||
34 | app = undefined | ||
35 | } | ||
36 | |||
37 | export { | ||
38 | beforeLocalSession, | ||
39 | afterLocalSuite, | ||
40 | beforeLocalSuite, | ||
41 | onBrowserStackPrepare, | ||
42 | onBrowserStackComplete | ||
43 | } | ||
44 | |||
45 | // --------------------------------------------------------------------------- | ||
46 | |||
47 | function buildConfig (suiteFile: string = undefined) { | ||
48 | const filename = basename(suiteFile) | ||
49 | |||
50 | if (filename === 'custom-server-defaults.e2e-spec.ts') { | ||
51 | return { | ||
52 | defaults: { | ||
53 | publish: { | ||
54 | download_enabled: false, | ||
55 | comments_enabled: false, | ||
56 | privacy: 4, | ||
57 | licence: 4 | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | return {} | ||
64 | } | ||
diff --git a/client/e2e/src/utils/index.ts b/client/e2e/src/utils/index.ts index 5da1ad517..354352ee2 100644 --- a/client/e2e/src/utils/index.ts +++ b/client/e2e/src/utils/index.ts | |||
@@ -1,3 +1,5 @@ | |||
1 | export * from './common' | 1 | export * from './common' |
2 | export * from './elements' | 2 | export * from './elements' |
3 | export * from './hooks' | ||
4 | export * from './server' | ||
3 | export * from './urls' | 5 | export * from './urls' |
diff --git a/client/e2e/src/utils/server.ts b/client/e2e/src/utils/server.ts new file mode 100644 index 000000000..7089a5c9c --- /dev/null +++ b/client/e2e/src/utils/server.ts | |||
@@ -0,0 +1,63 @@ | |||
1 | import { exec, spawn } from 'child_process' | ||
2 | import { join, resolve } from 'path' | ||
3 | |||
4 | function runServer (appInstance: string, config: any = {}) { | ||
5 | const env = Object.create(process.env) | ||
6 | env['NODE_ENV'] = 'test' | ||
7 | env['NODE_APP_INSTANCE'] = appInstance | ||
8 | |||
9 | env['NODE_CONFIG'] = JSON.stringify({ | ||
10 | rates_limit: { | ||
11 | api: { | ||
12 | max: 5000 | ||
13 | }, | ||
14 | login: { | ||
15 | max: 5000 | ||
16 | } | ||
17 | }, | ||
18 | log: { | ||
19 | level: 'warn' | ||
20 | }, | ||
21 | signup: { | ||
22 | enabled: false | ||
23 | }, | ||
24 | transcoding: { | ||
25 | enabled: false | ||
26 | }, | ||
27 | |||
28 | ...config | ||
29 | }) | ||
30 | |||
31 | const forkOptions = { | ||
32 | env, | ||
33 | cwd: getRootCWD(), | ||
34 | detached: false | ||
35 | } | ||
36 | |||
37 | const p = spawn('node', [ join('dist', 'server.js') ], forkOptions) | ||
38 | p.stderr.on('data', data => console.error(data.toString())) | ||
39 | p.stdout.on('data', data => console.error(data.toString())) | ||
40 | |||
41 | return p | ||
42 | } | ||
43 | |||
44 | function runCommand (command: string) { | ||
45 | return new Promise<void>((res, rej) => { | ||
46 | const p = exec(command, { cwd: getRootCWD() }) | ||
47 | |||
48 | p.stderr.on('data', data => console.error(data.toString())) | ||
49 | p.on('error', err => rej(err)) | ||
50 | p.on('exit', () => res()) | ||
51 | }) | ||
52 | } | ||
53 | |||
54 | export { | ||
55 | runServer, | ||
56 | runCommand | ||
57 | } | ||
58 | |||
59 | // --------------------------------------------------------------------------- | ||
60 | |||
61 | function getRootCWD () { | ||
62 | return resolve('../..') | ||
63 | } | ||