chore: be able to hide webServer stderr (#23063)

Follow-up to https://github.com/microsoft/playwright/pull/22564.
This commit is contained in:
Max Schmitt 2023-05-17 00:46:59 +02:00 committed by GitHub
parent ed19e5403b
commit 89f1940509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 2 deletions

View File

@ -571,6 +571,7 @@ export default defineConfig({
- `timeout` ?<[int]> How long to wait for the process to start up and be available in milliseconds. Defaults to 60000.
- `reuseExistingServer` ?<[boolean]> If true, it will re-use an existing server on the `port` or `url` when available. If no server is running on that `port` or `url`, it will run the command to start a new server. If `false`, it will throw if an existing process is listening on the `port` or `url`. This should be commonly set to `!process.env.CI` to allow the local dev server when running tests locally.
- `stdout` ?<["pipe"|"ignore"]> If `"pipe"`, it will pipe the stdout of the command to the process stdout. If `"ignore"`, it will ignore the stdout of the command. Default to `"ignore"`.
- `stderr` ?<["pipe"|"ignore"]> Whether to pipe the stderr of the command to the process stderr or ignore it. Defaults to `"pipe"`.
- `cwd` ?<[string]> Current working directory of the spawned process, defaults to the directory of the configuration file.
- `env` ?<[Object]<[string], [string]>> Environment variables to set for the command, `process.env` by default.

View File

@ -29,6 +29,7 @@ export default defineConfig({
| `url`| URL of your http server that is expected to return a 2xx, 3xx, 400, 401, 402, or 403 status code when the server is ready to accept connections. |
| `reuseExistingServer`| If `true`, it will re-use an existing server on the url when available. If no server is running on that url, it will run the command to start a new server. If `false`, it will throw if an existing process is listening on the url. To see the stdout, you can set the `DEBUG=pw:webserver` environment variable. |
| `stdout` | If `"pipe"`, it will pipe the stdout of the command to the process stdout. If `"ignore"`, it will ignore the stdout of the command. Default to `"ignore"`. |
| `stderr` | Whether to pipe the stderr of the command to the process stderr or ignore it. Defaults to `"pipe"`. |
## Adding a server timeout

View File

@ -35,6 +35,7 @@ export type WebServerPluginOptions = {
cwd?: string;
env?: { [key: string]: string; };
stdout?: 'pipe' | 'ignore';
stderr?: 'pipe' | 'ignore';
};
const DEFAULT_ENVIRONMENT_VARIABLES = {
@ -107,7 +108,10 @@ export class WebServerPlugin implements TestRunnerPlugin {
debugWebServer(`Process started`);
launchedProcess.stderr!.on('data', line => this._reporter!.onStdErr?.('[WebServer] ' + line.toString()));
launchedProcess.stderr!.on('data', line => {
if (debugWebServer.enabled || (this._options.stderr === 'pipe' || !this._options.stderr))
this._reporter!.onStdErr?.('[WebServer] ' + line.toString());
});
launchedProcess.stdout!.on('data', line => {
if (debugWebServer.enabled || this._options.stdout === 'pipe')
this._reporter!.onStdOut?.('[WebServer] ' + line.toString());

View File

@ -6504,6 +6504,11 @@ interface TestConfigWebServer {
*/
stdout?: "pipe"|"ignore";
/**
* Whether to pipe the stderr of the command to the process stderr or ignore it. Defaults to `"pipe"`.
*/
stderr?: "pipe"|"ignore";
/**
* Current working directory of the spawned process, defaults to the directory of the configuration file.
*/

View File

@ -679,5 +679,27 @@ test('should forward stdout when set to "pipe"', async ({ runInlineTest }, { wor
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
expect(result.output).toContain('[WebServer] listening');
expect(result.output).toContain('[WebServer] error from server'); // stderr is always getting forwarded
expect(result.output).toContain('[WebServer] error from server'); // stderr is piped by default
});
test('should be able to ignore "stderr"', async ({ runInlineTest }, { workerIndex }) => {
const port = workerIndex * 2 + 10500;
const result = await runInlineTest({
'test.spec.ts': `
import { test, expect } from '@playwright/test';
test('pass', async ({}) => {});
`,
'playwright.config.ts': `
module.exports = {
webServer: {
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}',
port: ${port},
stderr: 'ignore',
}
};
`,
}, undefined);
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
expect(result.output).not.toContain('error from server');
});