From bd2e2f11d09aa015125e5b5b05ca57a44b6f2d32 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 30 Nov 2020 14:47:54 +0100 Subject: Add inspect to test script --- server/tools/test.ts | 2 +- shared/extra-utils/server/servers.ts | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/tools/test.ts b/server/tools/test.ts index 23bf0120f..fc7f8d769 100644 --- a/server/tools/test.ts +++ b/server/tools/test.ts @@ -39,7 +39,7 @@ async function run () { console.log('Starting server.') - const server = await flushAndRunServer(1, {}, [], false) + const server = await flushAndRunServer(1, {}, [], { hideLogs: false, execArgv: [ '--inspect' ] }) const cleanup = () => { console.log('Killing server') diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 1126a7d93..4ad3eb14a 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -104,7 +104,12 @@ function randomRTMP () { return randomInt(low, high) } -async function flushAndRunServer (serverNumber: number, configOverride?: Object, args = [], silent = true) { +type RunServerOptions = { + hideLogs?: boolean + execArgv?: string[] +} + +async function flushAndRunServer (serverNumber: number, configOverride?: Object, args = [], options: RunServerOptions = {}) { const parallel = parallelTests() const internalServerNumber = parallel ? randomServer() : serverNumber @@ -133,10 +138,10 @@ async function flushAndRunServer (serverNumber: number, configOverride?: Object, } } - return runServer(server, configOverride, args, silent) + return runServer(server, configOverride, args, options) } -async function runServer (server: ServerInfo, configOverrideArg?: any, args = [], silent?: boolean) { +async function runServer (server: ServerInfo, configOverrideArg?: any, args = [], options: RunServerOptions = {}) { // These actions are async so we need to be sure that they have both been done const serverRunString = { 'Server listening': false @@ -208,14 +213,15 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] env['NODE_APP_INSTANCE'] = server.internalServerNumber.toString() env['NODE_CONFIG'] = JSON.stringify(configOverride) - const options = { + const forkOptions = { silent: true, env, - detached: true + detached: true, + execArgv: options.execArgv || [] } return new Promise(res => { - server.app = fork(join(root(), 'dist', 'server.js'), args, options) + server.app = fork(join(root(), 'dist', 'server.js'), args, forkOptions) server.app.stdout.on('data', function onStdout (data) { let dontContinue = false @@ -240,7 +246,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] // If no, there is maybe one thing not already initialized (client/user credentials generation...) if (dontContinue === true) return - if (silent === false) { + if (options.hideLogs === false) { console.log(data.toString()) } else { server.app.stdout.removeListener('data', onStdout) -- cgit v1.2.3