aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/utils/hooks.ts
blob: e57584b44d73b0878c1eeae37d60ebc043a21832 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { ChildProcessWithoutNullStreams } from 'child_process'
import { basename } from 'path'
import { setValue } from '@wdio/shared-store-service'
import { createScreenshotsDirectory } from './files'
import { runCommand, runServer } from './server'

let appInstance: number
let app: ChildProcessWithoutNullStreams

let emailPort: number

async function beforeLocalSuite (suite: any) {
  const config = buildConfig(suite.file)

  await runCommand('npm run clean:server:test -- ' + appInstance)
  app = runServer(appInstance, config)
}

function afterLocalSuite () {
  app.kill()
  app = undefined
}

async function beforeLocalSession (config: { baseUrl: string }, capabilities: { browserName: string }) {
  createScreenshotsDirectory()

  appInstance = capabilities['browserName'] === 'chrome'
    ? 1
    : 2

  emailPort = 1025 + appInstance

  config.baseUrl = 'http://localhost:900' + appInstance

  await setValue('emailPort', emailPort)
}

async function onBrowserStackPrepare () {
  const appInstance = 1

  await runCommand('npm run clean:server:test -- ' + appInstance)
  app = runServer(appInstance)
}

function onBrowserStackComplete () {
  app.kill()
  app = undefined
}

export {
  beforeLocalSession,
  afterLocalSuite,
  beforeLocalSuite,
  onBrowserStackPrepare,
  onBrowserStackComplete
}

// ---------------------------------------------------------------------------

function buildConfig (suiteFile: string = undefined) {
  const filename = basename(suiteFile)

  if (filename === 'custom-server-defaults.e2e-spec.ts') {
    return {
      defaults: {
        publish: {
          download_enabled: false,
          comments_enabled: false,
          privacy: 4,
          licence: 4
        },
        p2p: {
          webapp: {
            enabled: false
          },
          embed: {
            enabled: false
          }
        }
      }
    }
  }

  if (filename === 'signup.e2e-spec.ts') {
    return {
      signup: {
        limit: -1
      },
      smtp: {
        hostname: '127.0.0.1',
        port: emailPort
      }
    }
  }

  return {}
}