use runInlineTest, make outputlines local
This commit is contained in:
parent
02284ed4aa
commit
5ae52f072f
|
|
@ -151,17 +151,9 @@ export class TestChildProcess {
|
||||||
this.exitCode = this.exited.then(r => r.exitCode);
|
this.exitCode = this.exited.then(r => r.exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
outputLines(options: { prefix?: string } = {}): string[] {
|
outputLines(): string[] {
|
||||||
const strippedOutput = stripAnsi(this.output);
|
const strippedOutput = stripAnsi(this.output);
|
||||||
return strippedOutput
|
return strippedOutput.split('\n').filter(line => line.startsWith('%%')).map(line => line.substring(2).trim());
|
||||||
.split('\n')
|
|
||||||
.map(line => {
|
|
||||||
if (options.prefix && line.startsWith(options.prefix))
|
|
||||||
return line.substring(options.prefix.length);
|
|
||||||
return line;
|
|
||||||
})
|
|
||||||
.filter(line => line.startsWith('%%'))
|
|
||||||
.map(line => line.substring(2).trim());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async kill(signal: 'SIGINT' | 'SIGKILL' = 'SIGKILL') {
|
async kill(signal: 'SIGINT' | 'SIGKILL' = 'SIGKILL') {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
import type http from 'http';
|
import type http from 'http';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { test, expect, parseTestRunnerOutput } from './playwright-test-fixtures';
|
import { test, expect, parseTestRunnerOutput } from './playwright-test-fixtures';
|
||||||
|
import type { RunResult } from './playwright-test-fixtures';
|
||||||
import { createHttpServer } from '../../packages/playwright-core/lib/utils/network';
|
import { createHttpServer } from '../../packages/playwright-core/lib/utils/network';
|
||||||
|
|
||||||
const SIMPLE_SERVER_PATH = path.join(__dirname, 'assets', 'simple-server.js');
|
const SIMPLE_SERVER_PATH = path.join(__dirname, 'assets', 'simple-server.js');
|
||||||
|
|
@ -775,40 +776,29 @@ test.describe('kill option', () => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
test('sends SIGKILL by default', async ({ interactWithTestRunner }) => {
|
function parseOutputLines(result: RunResult): string[] {
|
||||||
const testProcess = await interactWithTestRunner(files(), { workers: 1 });
|
const prefix = '[WebServer] %%';
|
||||||
|
return result.output.split('\n').filter(line => line.startsWith(prefix)).map(line => line.substring(prefix.length));
|
||||||
|
}
|
||||||
|
|
||||||
await testProcess.waitForOutput('webserver started');
|
test('sends SIGKILL by default', async ({ runInlineTest }) => {
|
||||||
process.kill(testProcess.process.pid!, 'SIGINT');
|
const result = await runInlineTest(files(), { workers: 1 });
|
||||||
await testProcess.exited;
|
expect(parseOutputLines(result)).toEqual([]);
|
||||||
|
|
||||||
expect(testProcess.outputLines({ prefix: '[WebServer] ' })).toEqual([]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can be configured to send SIGTERM', async ({ interactWithTestRunner }) => {
|
test('can be configured to send SIGTERM', async ({ runInlineTest }) => {
|
||||||
const testProcess = await interactWithTestRunner(files({ kill: { SIGTERM: 500 } }), { workers: 1 });
|
const result = await runInlineTest(files({ kill: { SIGTERM: 500 } }), { workers: 1 });
|
||||||
|
expect(parseOutputLines(result)).toEqual(['webserver received SIGTERM but stubbornly refuses to wind down']);
|
||||||
await testProcess.waitForOutput('webserver started');
|
|
||||||
process.kill(testProcess.process.pid!, 'SIGINT');
|
|
||||||
await testProcess.exited;
|
|
||||||
|
|
||||||
expect(testProcess.outputLines({ prefix: '[WebServer] ' })).toEqual(['webserver received SIGTERM but stubbornly refuses to wind down']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can be configured to send SIGINT', async ({ interactWithTestRunner }) => {
|
test('can be configured to send SIGINT', async ({ runInlineTest }) => {
|
||||||
const testProcess = await interactWithTestRunner(files({ kill: { SIGINT: 500 } }), { workers: 1 });
|
const result = await runInlineTest(files({ kill: { SIGINT: 500 } }), { workers: 1 });
|
||||||
|
expect(parseOutputLines(result)).toEqual(['webserver received SIGINT but stubbornly refuses to wind down']);
|
||||||
await testProcess.waitForOutput('webserver started');
|
|
||||||
process.kill(testProcess.process.pid!, 'SIGINT');
|
|
||||||
await testProcess.exited;
|
|
||||||
|
|
||||||
expect(testProcess.outputLines({ prefix: '[WebServer] ' })).toEqual(['webserver received SIGINT but stubbornly refuses to wind down']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throws when mixed', async ({ interactWithTestRunner }) => {
|
test('throws when mixed', async ({ runInlineTest }) => {
|
||||||
const testProcess = await interactWithTestRunner(files({ kill: { SIGINT: 500, SIGTERM: 500 } }), { workers: 1 });
|
const result = await runInlineTest(files({ kill: { SIGINT: 500, SIGTERM: 500 } }), { workers: 1 });
|
||||||
await testProcess.exited;
|
expect(result.exitCode).toBe(1);
|
||||||
|
expect(result.output).toContain('Only one of SIGINT or SIGTERM can be specified in config.webServer.kill');
|
||||||
expect(testProcess.output).toContain('Only one of SIGINT or SIGTERM can be specified in config.webServer.kill');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue