feat(testInfo): add possibility to use test file name without extension in snapshotPathTemplate

This commit is contained in:
Michael Safonov 2024-11-04 08:32:48 +01:00
parent abcd1ff201
commit 5eb044db19
4 changed files with 10 additions and 0 deletions

View file

@ -1809,6 +1809,8 @@ The list of supported tokens:
* Value: `page` * Value: `page`
* `{testFileName}` - Test file name with extension. * `{testFileName}` - Test file name with extension.
* Value: `page-click.spec.ts` * Value: `page-click.spec.ts`
* `{testFileNameWithoutExtension}` - Test file name without extension.
* Value: `page-click`
* `{testFilePath}` - Relative path from `testDir` to **test file** * `{testFilePath}` - Relative path from `testDir` to **test file**
* Value: `page/page-click.spec.ts` * Value: `page/page-click.spec.ts`
* `{testName}` - File-system-sanitized test title, including parent describes but excluding file name. * `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.

View file

@ -454,6 +454,7 @@ export class TestInfoImpl implements TestInfo {
.replace(/\{(.)?projectName\}/g, projectNamePathSegment ? '$1' + projectNamePathSegment : '') .replace(/\{(.)?projectName\}/g, projectNamePathSegment ? '$1' + projectNamePathSegment : '')
.replace(/\{(.)?testName\}/g, '$1' + this._fsSanitizedTestName()) .replace(/\{(.)?testName\}/g, '$1' + this._fsSanitizedTestName())
.replace(/\{(.)?testFileName\}/g, '$1' + parsedRelativeTestFilePath.base) .replace(/\{(.)?testFileName\}/g, '$1' + parsedRelativeTestFilePath.base)
.replace(/\{(.)?testFileNameWithoutExtension\}/g, '$1' + parsedRelativeTestFilePath.base.replace('.spec', '').replace('.ts', ''))
.replace(/\{(.)?testFilePath\}/g, '$1' + relativeTestFilePath) .replace(/\{(.)?testFilePath\}/g, '$1' + relativeTestFilePath)
.replace(/\{(.)?arg\}/g, '$1' + path.join(parsedSubPath.dir, parsedSubPath.name)) .replace(/\{(.)?arg\}/g, '$1' + path.join(parsedSubPath.dir, parsedSubPath.name))
.replace(/\{(.)?ext\}/g, parsedSubPath.ext ? '$1' + parsedSubPath.ext : ''); .replace(/\{(.)?ext\}/g, parsedSubPath.ext ? '$1' + parsedSubPath.ext : '');

View file

@ -467,6 +467,8 @@ interface TestProject<TestArgs = {}, WorkerArgs = {}> {
* - Value: `page` * - Value: `page`
* - `{testFileName}` - Test file name with extension. * - `{testFileName}` - Test file name with extension.
* - Value: `page-click.spec.ts` * - Value: `page-click.spec.ts`
* - `{testFileNameWithoutExtension}` - Test file name without extension.
* - Value: `page-click`
* - `{testFilePath}` - Relative path from `testDir` to **test file** * - `{testFilePath}` - Relative path from `testDir` to **test file**
* - Value: `page/page-click.spec.ts` * - Value: `page/page-click.spec.ts`
* - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name. * - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.
@ -1531,6 +1533,8 @@ interface TestConfig<TestArgs = {}, WorkerArgs = {}> {
* - Value: `page` * - Value: `page`
* - `{testFileName}` - Test file name with extension. * - `{testFileName}` - Test file name with extension.
* - Value: `page-click.spec.ts` * - Value: `page-click.spec.ts`
* - `{testFileNameWithoutExtension}` - Test file name without extension.
* - Value: `page-click`
* - `{testFilePath}` - Relative path from `testDir` to **test file** * - `{testFilePath}` - Relative path from `testDir` to **test file**
* - Value: `page/page-click.spec.ts` * - Value: `page/page-click.spec.ts`
* - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name. * - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.

View file

@ -79,6 +79,9 @@ test('tokens should expand property', async ({ runInlineTest }, testInfo) => {
}, { }, {
name: 'testFileName', name: 'testFileName',
snapshotPathTemplate: '{testFileName}', snapshotPathTemplate: '{testFileName}',
}, {
name: 'testFileNameWithoutExtension',
snapshotPathTemplate: '{testFileNameWithoutExtension}',
}, { }, {
name: 'snapshotDir', name: 'snapshotDir',
snapshotDir: './a-snapshot-dir', snapshotDir: './a-snapshot-dir',