From 64da74fba8b2e6f8647f52849570e22131016087 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Wed, 11 Aug 2021 00:24:35 -0400 Subject: [PATCH] feat(test-runner): allow non-ascii characters in the output dir path (#8093) --- src/test/util.ts | 4 ++++ src/test/workerRunner.ts | 6 +----- tests/playwright-test/test-output-dir.spec.ts | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/test/util.ts b/src/test/util.ts index 72bad72737..4f5523e3e1 100644 --- a/src/test/util.ts +++ b/src/test/util.ts @@ -215,3 +215,7 @@ export function expectType(receiver: any, type: string, matcherName: string) { if (typeof receiver !== 'object' || receiver.constructor.name !== type) throw new Error(`${matcherName} can be only used with ${type} object`); } + +export function sanitizeForFilePath(s: string) { + return s.replace(/[\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-'); +} diff --git a/src/test/workerRunner.ts b/src/test/workerRunner.ts index 831a62104b..7e4e3662dd 100644 --- a/src/test/workerRunner.ts +++ b/src/test/workerRunner.ts @@ -19,7 +19,7 @@ import path from 'path'; import rimraf from 'rimraf'; import util from 'util'; import { EventEmitter } from 'events'; -import { monotonicTime, DeadlineRunner, raceAgainstDeadline, serializeError } from './util'; +import { monotonicTime, DeadlineRunner, raceAgainstDeadline, serializeError, sanitizeForFilePath } from './util'; import { TestBeginPayload, TestEndPayload, RunPayload, TestEntry, DonePayload, WorkerInitParams, StepBeginPayload, StepEndPayload } from './ipc'; import { setCurrentTestInfo } from './globals'; import { Loader } from './loader'; @@ -547,7 +547,3 @@ function modifier(testInfo: TestInfo, type: 'skip' | 'fail' | 'fixme' | 'slow', class SkipError extends Error { } - -function sanitizeForFilePath(s: string) { - return s.replace(/[^\w\d]+/g, '-'); -} diff --git a/tests/playwright-test/test-output-dir.spec.ts b/tests/playwright-test/test-output-dir.spec.ts index dfdb4366d8..a67601cf41 100644 --- a/tests/playwright-test/test-output-dir.spec.ts +++ b/tests/playwright-test/test-output-dir.spec.ts @@ -256,3 +256,17 @@ test('should accept a relative path for outputDir', async ({ runInlineTest }, te }, {usesCustomOutputDir: true}); expect(result.exitCode).toBe(0); }); + + +test('should allow nonAscii characters in the output dir', async ({ runInlineTest }, testInfo) => { + const result = await runInlineTest({ + 'my-test.spec.js': ` + const { test } = pwt; + test('こんにちは世界', async ({}, testInfo) => { + console.log('\\n%%' + testInfo.outputDir); + }); + `, + }); + const outputDir = result.output.split('\n').filter(x => x.startsWith('%%'))[0].slice('%%'.length); + expect(outputDir).toBe(path.join(testInfo.outputDir, 'test-results', 'my-test-こんにちは世界')); +});