fix: Fixes #19169 Issue with moving up a directory in snapshotPathTemplate (#19170)

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 <skanodia@atlassian.com>
pull/19219/head
Shubham Kanodia 2 months ago committed by GitHub
parent 62b28c89b4
commit 4679cfaeb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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]) {

Loading…
Cancel
Save