]>
Commit | Line | Data |
---|---|---|
3cf68b86 C |
1 | import { ChildProcessWithoutNullStreams } from 'child_process' |
2 | import { basename } from 'path' | |
3 | import { runCommand, runServer } from './server' | |
5bdfa604 | 4 | import { setValue } from '@wdio/shared-store-service' |
3cf68b86 | 5 | |
5bdfa604 | 6 | let appInstance: number |
3cf68b86 C |
7 | let app: ChildProcessWithoutNullStreams |
8 | ||
5bdfa604 C |
9 | let emailPort: number |
10 | ||
3cf68b86 C |
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 | ||
5bdfa604 C |
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 | ||
3cf68b86 | 30 | config.baseUrl = 'http://localhost:900' + appInstance |
5bdfa604 C |
31 | |
32 | await setValue('emailPort', emailPort) | |
3cf68b86 C |
33 | } |
34 | ||
35 | async function onBrowserStackPrepare () { | |
5bdfa604 | 36 | const appInstance = 1 |
3cf68b86 C |
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 | |
a9bfa85d C |
68 | }, |
69 | p2p: { | |
b65de1be C |
70 | webapp: { |
71 | enabled: false | |
72 | }, | |
73 | embed: { | |
74 | enabled: false | |
75 | } | |
3cf68b86 C |
76 | } |
77 | } | |
78 | } | |
79 | } | |
80 | ||
814e9e07 C |
81 | if (filename === 'signup.e2e-spec.ts') { |
82 | return { | |
83 | signup: { | |
5bdfa604 C |
84 | limit: -1 |
85 | }, | |
86 | smtp: { | |
87 | hostname: '127.0.0.1', | |
88 | port: emailPort | |
814e9e07 C |
89 | } |
90 | } | |
91 | } | |
92 | ||
3cf68b86 C |
93 | return {} |
94 | } |