From 3cf68b869decf07ff7435fe1436d4f3134df1bf4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Dec 2021 17:17:01 +0100 Subject: Ability for admins to set default upload values --- client/e2e/src/utils/hooks.ts | 64 ++++++++++++++++++++++++++++++++++++++++++ client/e2e/src/utils/index.ts | 2 ++ client/e2e/src/utils/server.ts | 63 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 client/e2e/src/utils/hooks.ts create mode 100644 client/e2e/src/utils/server.ts (limited to 'client/e2e/src/utils') diff --git a/client/e2e/src/utils/hooks.ts b/client/e2e/src/utils/hooks.ts new file mode 100644 index 000000000..e42c6a5d8 --- /dev/null +++ b/client/e2e/src/utils/hooks.ts @@ -0,0 +1,64 @@ +import { ChildProcessWithoutNullStreams } from 'child_process' +import { basename } from 'path' +import { runCommand, runServer } from './server' + +let appInstance: string +let app: ChildProcessWithoutNullStreams + +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 +} + +function beforeLocalSession (config: { baseUrl: string }, capabilities: { browserName: string }) { + appInstance = capabilities['browserName'] === 'chrome' ? '1' : '2' + config.baseUrl = 'http://localhost:900' + appInstance +} + +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 + } + } + } + } + + return {} +} diff --git a/client/e2e/src/utils/index.ts b/client/e2e/src/utils/index.ts index 5da1ad517..354352ee2 100644 --- a/client/e2e/src/utils/index.ts +++ b/client/e2e/src/utils/index.ts @@ -1,3 +1,5 @@ export * from './common' export * from './elements' +export * from './hooks' +export * from './server' export * from './urls' 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 @@ +import { exec, spawn } from 'child_process' +import { join, resolve } from 'path' + +function runServer (appInstance: string, config: any = {}) { + const env = Object.create(process.env) + env['NODE_ENV'] = 'test' + env['NODE_APP_INSTANCE'] = appInstance + + env['NODE_CONFIG'] = JSON.stringify({ + rates_limit: { + api: { + max: 5000 + }, + login: { + max: 5000 + } + }, + log: { + level: 'warn' + }, + signup: { + enabled: false + }, + transcoding: { + enabled: false + }, + + ...config + }) + + const forkOptions = { + env, + cwd: getRootCWD(), + detached: false + } + + const p = spawn('node', [ join('dist', 'server.js') ], forkOptions) + p.stderr.on('data', data => console.error(data.toString())) + p.stdout.on('data', data => console.error(data.toString())) + + return p +} + +function runCommand (command: string) { + return new Promise((res, rej) => { + const p = exec(command, { cwd: getRootCWD() }) + + p.stderr.on('data', data => console.error(data.toString())) + p.on('error', err => rej(err)) + p.on('exit', () => res()) + }) +} + +export { + runServer, + runCommand +} + +// --------------------------------------------------------------------------- + +function getRootCWD () { + return resolve('../..') +} -- cgit v1.2.3