]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/e2e/src/utils/hooks.ts
Create screenshots directory when needed
[github/Chocobozzz/PeerTube.git] / client / e2e / src / utils / hooks.ts
CommitLineData
3cf68b86
C
1import { ChildProcessWithoutNullStreams } from 'child_process'
2import { basename } from 'path'
5bdfa604 3import { setValue } from '@wdio/shared-store-service'
1ec4835d
C
4import { createScreenshotsDirectory } from './files'
5import { runCommand, runServer } from './server'
3cf68b86 6
5bdfa604 7let appInstance: number
3cf68b86
C
8let app: ChildProcessWithoutNullStreams
9
5bdfa604
C
10let emailPort: number
11
3cf68b86
C
12async 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
19function afterLocalSuite () {
20 app.kill()
21 app = undefined
22}
23
5bdfa604 24async function beforeLocalSession (config: { baseUrl: string }, capabilities: { browserName: string }) {
1ec4835d
C
25 await createScreenshotsDirectory()
26
5bdfa604
C
27 appInstance = capabilities['browserName'] === 'chrome'
28 ? 1
29 : 2
30
31 emailPort = 1025 + appInstance
32
3cf68b86 33 config.baseUrl = 'http://localhost:900' + appInstance
5bdfa604
C
34
35 await setValue('emailPort', emailPort)
3cf68b86
C
36}
37
38async function onBrowserStackPrepare () {
5bdfa604 39 const appInstance = 1
3cf68b86
C
40
41 await runCommand('npm run clean:server:test -- ' + appInstance)
42 app = runServer(appInstance)
43}
44
45function onBrowserStackComplete () {
46 app.kill()
47 app = undefined
48}
49
50export {
51 beforeLocalSession,
52 afterLocalSuite,
53 beforeLocalSuite,
54 onBrowserStackPrepare,
55 onBrowserStackComplete
56}
57
58// ---------------------------------------------------------------------------
59
60function 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
a9bfa85d
C
71 },
72 p2p: {
b65de1be
C
73 webapp: {
74 enabled: false
75 },
76 embed: {
77 enabled: false
78 }
3cf68b86
C
79 }
80 }
81 }
82 }
83
814e9e07
C
84 if (filename === 'signup.e2e-spec.ts') {
85 return {
86 signup: {
5bdfa604
C
87 limit: -1
88 },
89 smtp: {
90 hostname: '127.0.0.1',
91 port: emailPort
814e9e07
C
92 }
93 }
94 }
95
3cf68b86
C
96 return {}
97}