diff --git a/packages/playwright/src/reporters/base.ts b/packages/playwright/src/reporters/base.ts index 2c6600f1b0..81d0fa567e 100644 --- a/packages/playwright/src/reporters/base.ts +++ b/packages/playwright/src/reporters/base.ts @@ -331,7 +331,7 @@ export function formatFailure(config: FullConfig, test: TestCase, options: {inde const packageManagerCommand = getPackageManagerExecCommand(); resultLines.push(colors.cyan(` Usage:`)); resultLines.push(''); - resultLines.push(colors.cyan(` ${packageManagerCommand} playwright show-trace "${relativePath}"`)); + resultLines.push(colors.cyan(` ${packageManagerCommand} playwright show-trace ${quotePathIfNeeded(relativePath)}`)); resultLines.push(''); } } else { @@ -373,6 +373,12 @@ export function formatFailure(config: FullConfig, test: TestCase, options: {inde }; } +function quotePathIfNeeded(path: string): string { + if (/\W/.test(path)) + return `"${path}"`; + return path; +} + export function formatResultFailure(test: TestCase, result: TestResult, initialIndent: string, highlightCode: boolean): ErrorDetails[] { const errorDetails: ErrorDetails[] = [];