From 674988c633fb39b1d66a6bda55e96aaaa172dde5 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 19 Jan 2024 10:27:15 -0800 Subject: [PATCH] chore: add quotes to the path only when necessary (#29057) This is a follow-up to c76f5294cea1b98fc667b677d042d28d3e4b5bb7 Reference https://github.com/microsoft/playwright/issues/29039 --- packages/playwright/src/reporters/base.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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[] = [];