]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/utils/hooks.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / client / e2e / src / utils / hooks.ts
1 import { ChildProcessWithoutNullStreams } from 'child_process'
2 import { basename } from 'path'
3 import { runCommand, runServer } from './server'
4 import { setValue } from '@wdio/shared-store-service'
5
6 let appInstance: number
7 let app: ChildProcessWithoutNullStreams
8
9 let emailPort: number
10
11 async function beforeLocalSuite (suite: any) {
12 const config = buildConfig(suite.file)
13
14 await runCommand('npm run clean:server:test -- ' + appInstance)
15 app = runServer(appInstance, config)
16 }
17
18 function afterLocalSuite () {
19 app.kill()
20 app = undefined
21 }
22
23 async function beforeLocalSession (config: { baseUrl: string }, capabilities: { browserName: string }) {
24 appInstance = capabilities['browserName'] === 'chrome'
25 ? 1
26 : 2
27
28 emailPort = 1025 + appInstance
29
30 config.baseUrl = 'http://localhost:900' + appInstance
31
32 await setValue('emailPort', emailPort)
33 }
34
35 async function onBrowserStackPrepare () {
36 const appInstance = 1
37
38 await runCommand('npm run clean:server:test -- ' + appInstance)
39 app = runServer(appInstance)
40 }
41
42 function onBrowserStackComplete () {
43 app.kill()
44 app = undefined
45 }
46
47 export {
48 beforeLocalSession,
49 afterLocalSuite,
50 beforeLocalSuite,
51 onBrowserStackPrepare,
52 onBrowserStackComplete
53 }
54
55 // ---------------------------------------------------------------------------
56
57 function buildConfig (suiteFile: string = undefined) {
58 const filename = basename(suiteFile)
59
60 if (filename === 'custom-server-defaults.e2e-spec.ts') {
61 return {
62 defaults: {
63 publish: {
64 download_enabled: false,
65 comments_enabled: false,
66 privacy: 4,
67 licence: 4
68 },
69 p2p: {
70 webapp: {
71 enabled: false
72 },
73 embed: {
74 enabled: false
75 }
76 }
77 }
78 }
79 }
80
81 if (filename === 'signup.e2e-spec.ts') {
82 return {
83 signup: {
84 limit: -1
85 },
86 smtp: {
87 hostname: '127.0.0.1',
88 port: emailPort
89 }
90 }
91 }
92
93 return {}
94 }