aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/server/servers.ts76
1 files changed, 37 insertions, 39 deletions
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 480d12330..add738056 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -87,12 +87,14 @@ function randomServer () {
87 return Math.floor(Math.random() * (high - low) + low) 87 return Math.floor(Math.random() * (high - low) + low)
88} 88}
89 89
90function flushAndRunServer (serverNumber: number, configOverrideArg?: Object, args = []) { 90async function flushAndRunServer (serverNumber: number, configOverrideArg?: Object, args = []) {
91 const parallel = process.env.MOCHA_PARALLEL === 'true' 91 const parallel = process.env.MOCHA_PARALLEL === 'true'
92 92
93 const internalServerNumber = parallel ? randomServer() : serverNumber 93 const internalServerNumber = parallel ? randomServer() : serverNumber
94 const port = 9000 + internalServerNumber 94 const port = 9000 + internalServerNumber
95 95
96 await flushTests(serverNumber)
97
96 const server: ServerInfo = { 98 const server: ServerInfo = {
97 app: null, 99 app: null,
98 port, 100 port,
@@ -175,45 +177,41 @@ function flushAndRunServer (serverNumber: number, configOverrideArg?: Object, ar
175 } 177 }
176 178
177 return new Promise<ServerInfo>(res => { 179 return new Promise<ServerInfo>(res => {
178 flushTests(internalServerNumber) 180 server.app = fork(join(root(), 'dist', 'server.js'), args, options)
179 .then(() => { 181 server.app.stdout.on('data', function onStdout (data) {
180 182 let dontContinue = false
181 server.app = fork(join(root(), 'dist', 'server.js'), args, options) 183
182 server.app.stdout.on('data', function onStdout (data) { 184 // Capture things if we want to
183 let dontContinue = false 185 for (const key of Object.keys(regexps)) {
184 186 const regexp = regexps[ key ]
185 // Capture things if we want to 187 const matches = data.toString().match(regexp)
186 for (const key of Object.keys(regexps)) { 188 if (matches !== null) {
187 const regexp = regexps[ key ] 189 if (key === 'client_id') server.client.id = matches[ 1 ]
188 const matches = data.toString().match(regexp) 190 else if (key === 'client_secret') server.client.secret = matches[ 1 ]
189 if (matches !== null) { 191 else if (key === 'user_username') server.user.username = matches[ 1 ]
190 if (key === 'client_id') server.client.id = matches[ 1 ] 192 else if (key === 'user_password') server.user.password = matches[ 1 ]
191 else if (key === 'client_secret') server.client.secret = matches[ 1 ] 193 }
192 else if (key === 'user_username') server.user.username = matches[ 1 ] 194 }
193 else if (key === 'user_password') server.user.password = matches[ 1 ] 195
194 } 196 // Check if all required sentences are here
195 } 197 for (const key of Object.keys(serverRunString)) {
196 198 if (data.toString().indexOf(key) !== -1) serverRunString[ key ] = true
197 // Check if all required sentences are here 199 if (serverRunString[ key ] === false) dontContinue = true
198 for (const key of Object.keys(serverRunString)) { 200 }
199 if (data.toString().indexOf(key) !== -1) serverRunString[ key ] = true 201
200 if (serverRunString[ key ] === false) dontContinue = true 202 // If no, there is maybe one thing not already initialized (client/user credentials generation...)
201 } 203 if (dontContinue === true) return
202 204
203 // If no, there is maybe one thing not already initialized (client/user credentials generation...) 205 server.app.stdout.removeListener('data', onStdout)
204 if (dontContinue === true) return 206
205 207 process.on('exit', () => {
206 server.app.stdout.removeListener('data', onStdout) 208 try {
207 209 process.kill(server.app.pid)
208 process.on('exit', () => { 210 } catch { /* empty */ }
209 try {
210 process.kill(server.app.pid)
211 } catch { /* empty */ }
212 })
213
214 res(server)
215 })
216 }) 211 })
212
213 res(server)
214 })
217 }) 215 })
218} 216}
219 217