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