fix(webserver): prefix each line of webserver output (#32286)

This unflakes various `web-server.spec.ts` tests and makes the output
more consistent.
This commit is contained in:
Dmitry Gozman 2024-08-23 03:52:27 -07:00 committed by GitHub
parent 8c0e173d6c
commit 785ca19e51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -113,13 +113,13 @@ export class WebServerPlugin implements TestRunnerPlugin {
debugWebServer(`Process started`); debugWebServer(`Process started`);
launchedProcess.stderr!.on('data', line => { launchedProcess.stderr!.on('data', data => {
if (debugWebServer.enabled || (this._options.stderr === 'pipe' || !this._options.stderr)) if (debugWebServer.enabled || (this._options.stderr === 'pipe' || !this._options.stderr))
this._reporter!.onStdErr?.(colors.dim('[WebServer] ') + line.toString()); this._reporter!.onStdErr?.(prefixOutputLines(data.toString()));
}); });
launchedProcess.stdout!.on('data', line => { launchedProcess.stdout!.on('data', data => {
if (debugWebServer.enabled || this._options.stdout === 'pipe') if (debugWebServer.enabled || this._options.stdout === 'pipe')
this._reporter!.onStdOut?.(colors.dim('[WebServer] ') + line.toString()); this._reporter!.onStdOut?.(prefixOutputLines(data.toString()));
}); });
} }
@ -201,3 +201,14 @@ export const webServerPluginsForConfig = (config: FullConfigInternal): TestRunne
return webServerPlugins; return webServerPlugins;
}; };
function prefixOutputLines(output: string) {
const lastIsNewLine = output[output.length - 1] === '\n';
let lines = output.split('\n');
if (lastIsNewLine)
lines.pop();
lines = lines.map(line => colors.dim('[WebServer] ') + line);
if (lastIsNewLine)
lines.push('');
return lines.join('\n');
}