diff options
Diffstat (limited to 'client/e2e/src/utils/server.ts')
-rw-r--r-- | client/e2e/src/utils/server.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/client/e2e/src/utils/server.ts b/client/e2e/src/utils/server.ts new file mode 100644 index 000000000..7089a5c9c --- /dev/null +++ b/client/e2e/src/utils/server.ts | |||
@@ -0,0 +1,63 @@ | |||
1 | import { exec, spawn } from 'child_process' | ||
2 | import { join, resolve } from 'path' | ||
3 | |||
4 | function runServer (appInstance: string, config: any = {}) { | ||
5 | const env = Object.create(process.env) | ||
6 | env['NODE_ENV'] = 'test' | ||
7 | env['NODE_APP_INSTANCE'] = appInstance | ||
8 | |||
9 | env['NODE_CONFIG'] = JSON.stringify({ | ||
10 | rates_limit: { | ||
11 | api: { | ||
12 | max: 5000 | ||
13 | }, | ||
14 | login: { | ||
15 | max: 5000 | ||
16 | } | ||
17 | }, | ||
18 | log: { | ||
19 | level: 'warn' | ||
20 | }, | ||
21 | signup: { | ||
22 | enabled: false | ||
23 | }, | ||
24 | transcoding: { | ||
25 | enabled: false | ||
26 | }, | ||
27 | |||
28 | ...config | ||
29 | }) | ||
30 | |||
31 | const forkOptions = { | ||
32 | env, | ||
33 | cwd: getRootCWD(), | ||
34 | detached: false | ||
35 | } | ||
36 | |||
37 | const p = spawn('node', [ join('dist', 'server.js') ], forkOptions) | ||
38 | p.stderr.on('data', data => console.error(data.toString())) | ||
39 | p.stdout.on('data', data => console.error(data.toString())) | ||
40 | |||
41 | return p | ||
42 | } | ||
43 | |||
44 | function runCommand (command: string) { | ||
45 | return new Promise<void>((res, rej) => { | ||
46 | const p = exec(command, { cwd: getRootCWD() }) | ||
47 | |||
48 | p.stderr.on('data', data => console.error(data.toString())) | ||
49 | p.on('error', err => rej(err)) | ||
50 | p.on('exit', () => res()) | ||
51 | }) | ||
52 | } | ||
53 | |||
54 | export { | ||
55 | runServer, | ||
56 | runCommand | ||
57 | } | ||
58 | |||
59 | // --------------------------------------------------------------------------- | ||
60 | |||
61 | function getRootCWD () { | ||
62 | return resolve('../..') | ||
63 | } | ||