From 4679cfaeb9145e68a31e2be9005edc17575414c3 Mon Sep 17 00:00:00 2001 From: Shubham Kanodia Date: Thu, 1 Dec 2022 23:35:15 +0530 Subject: [PATCH] fix: Fixes #19169 Issue with moving up a directory in snapshotPathTemplate (#19170) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #19169 Note, I'm not sure why it was done this way before — e.g. Why `testDir` were considered for resolution, but `testFileDir` wasn't. Looking for guidance on the approach here, because there are still some template tokens outside `path.resolve` Co-authored-by: Shubham Kanodia --- packages/playwright-test/src/testInfo.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/playwright-test/src/testInfo.ts b/packages/playwright-test/src/testInfo.ts index a582b8fd1d..35e24792bd 100644 --- a/packages/playwright-test/src/testInfo.ts +++ b/packages/playwright-test/src/testInfo.ts @@ -246,19 +246,20 @@ export class TestInfoImpl implements TestInfo { const parsedRelativeTestFilePath = path.parse(relativeTestFilePath); const projectNamePathSegment = sanitizeForFilePath(this.project.name); - const snapshotPath = path.resolve(this.config._configDir, this.project.snapshotPathTemplate + const snapshotPath = this.project.snapshotPathTemplate .replace(/\{(.)?testDir\}/g, '$1' + this.project.testDir) .replace(/\{(.)?snapshotDir\}/g, '$1' + this.project.snapshotDir) - .replace(/\{(.)?snapshotSuffix\}/g, this.snapshotSuffix ? '$1' + this.snapshotSuffix : '')) + .replace(/\{(.)?snapshotSuffix\}/g, this.snapshotSuffix ? '$1' + this.snapshotSuffix : '') + .replace(/\{(.)?testFileDir\}/g, '$1' + parsedRelativeTestFilePath.dir) .replace(/\{(.)?platform\}/g, '$1' + process.platform) .replace(/\{(.)?projectName\}/g, projectNamePathSegment ? '$1' + projectNamePathSegment : '') .replace(/\{(.)?testName\}/g, '$1' + this._fsSanitizedTestName()) - .replace(/\{(.)?testFileDir\}/g, '$1' + parsedRelativeTestFilePath.dir) .replace(/\{(.)?testFileName\}/g, '$1' + parsedRelativeTestFilePath.base) .replace(/\{(.)?testFilePath\}/g, '$1' + relativeTestFilePath) .replace(/\{(.)?arg\}/g, '$1' + path.join(parsedSubPath.dir, parsedSubPath.name)) .replace(/\{(.)?ext\}/g, parsedSubPath.ext ? '$1' + parsedSubPath.ext : ''); - return path.normalize(snapshotPath); + + return path.normalize(path.resolve(this.config._configDir, snapshotPath)); } skip(...args: [arg?: any, description?: string]) {