mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(test runner): add --trace cli option (#16277)
This commit is contained in:
parent
e424a36945
commit
cb30cb4eb7
@ -26,6 +26,7 @@ import { stopProfiling, startProfiling } from './profiler';
|
|||||||
import type { TestFileFilter } from './util';
|
import type { TestFileFilter } from './util';
|
||||||
import { showHTMLReport } from './reporters/html';
|
import { showHTMLReport } from './reporters/html';
|
||||||
import { baseFullConfig, defaultTimeout, fileIsModule } from './loader';
|
import { baseFullConfig, defaultTimeout, fileIsModule } from './loader';
|
||||||
|
import type { TraceMode } from './types';
|
||||||
|
|
||||||
export function addTestCommands(program: Command) {
|
export function addTestCommands(program: Command) {
|
||||||
addTestCommand(program);
|
addTestCommand(program);
|
||||||
@ -56,6 +57,7 @@ function addTestCommand(program: Command) {
|
|||||||
command.option('--shard <shard>', `Shard tests and execute only the selected shard, specify in the form "current/all", 1-based, for example "3/5"`);
|
command.option('--shard <shard>', `Shard tests and execute only the selected shard, specify in the form "current/all", 1-based, for example "3/5"`);
|
||||||
command.option('--project <project-name...>', `Only run tests from the specified list of projects (default: run all projects)`);
|
command.option('--project <project-name...>', `Only run tests from the specified list of projects (default: run all projects)`);
|
||||||
command.option('--timeout <timeout>', `Specify test timeout threshold in milliseconds, zero for unlimited (default: ${defaultTimeout})`);
|
command.option('--timeout <timeout>', `Specify test timeout threshold in milliseconds, zero for unlimited (default: ${defaultTimeout})`);
|
||||||
|
command.option('--trace <mode>', `Force tracing mode, can be ${kTraceModes.map(mode => `"${mode}"`).join(', ')}`);
|
||||||
command.option('-u, --update-snapshots', `Update snapshots with actual results (default: only create missing snapshots)`);
|
command.option('-u, --update-snapshots', `Update snapshots with actual results (default: only create missing snapshots)`);
|
||||||
command.option('-x', `Stop after the first failure`);
|
command.option('-x', `Stop after the first failure`);
|
||||||
command.action(async (args, opts) => {
|
command.action(async (args, opts) => {
|
||||||
@ -130,6 +132,12 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
|
|||||||
overrides.workers = 1;
|
overrides.workers = 1;
|
||||||
process.env.PWDEBUG = '1';
|
process.env.PWDEBUG = '1';
|
||||||
}
|
}
|
||||||
|
if (opts.trace) {
|
||||||
|
if (!kTraceModes.includes(opts.trace))
|
||||||
|
throw new Error(`Unsupported trace mode "${opts.trace}", must be one of ${kTraceModes.map(mode => `"${mode}"`).join(', ')}`);
|
||||||
|
overrides.use = overrides.use || {};
|
||||||
|
overrides.use.trace = opts.trace;
|
||||||
|
}
|
||||||
|
|
||||||
// When no --config option is passed, let's look for the config file in the current directory.
|
// When no --config option is passed, let's look for the config file in the current directory.
|
||||||
const configFileOrDirectory = opts.config ? path.resolve(process.cwd(), opts.config) : process.cwd();
|
const configFileOrDirectory = opts.config ? path.resolve(process.cwd(), opts.config) : process.cwd();
|
||||||
@ -250,3 +258,5 @@ function restartWithExperimentalTsEsm(configFile: string | null): boolean {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const kTraceModes: TraceMode[] = ['on', 'off', 'on-first-retry', 'retain-on-failure'];
|
||||||
|
@ -267,6 +267,20 @@ test('should retain traces for interrupted tests', async ({ runInlineTest }, tes
|
|||||||
expect(fs.existsSync(testInfo.outputPath('test-results', 'b-test-2', 'trace.zip'))).toBeTruthy();
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'b-test-2', 'trace.zip'))).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should respect --trace', async ({ runInlineTest }, testInfo) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.spec.ts': `
|
||||||
|
pwt.test('test 1', async ({ page }) => {
|
||||||
|
await page.goto('about:blank');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { trace: 'on' });
|
||||||
|
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-test-1', 'trace.zip'))).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
async function parseTrace(file: string): Promise<Map<string, Buffer>> {
|
async function parseTrace(file: string): Promise<Map<string, Buffer>> {
|
||||||
const zipFS = new ZipFile(file);
|
const zipFS = new ZipFile(file);
|
||||||
const resources = new Map<string, Buffer>();
|
const resources = new Map<string, Buffer>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user