Skip to content

Commit

Permalink
feat(testInfo): add possibility to use test file name without extensi…
Browse files Browse the repository at this point in the history
…on in snapshotPathTemplate
  • Loading branch information
MichaelSafonov committed Nov 4, 2024
1 parent abcd1ff commit 8b64b1a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/api/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@ The list of supported tokens:
* Value: `page`
* `{testFileName}` - Test file name with extension.
* Value: `page-click.spec.ts`
* `{testFileNameWithoutExtension}` - Test file name without extension.
* Value: `page-click`
* `{testFilePath}` - Relative path from `testDir` to **test file**
* Value: `page/page-click.spec.ts`
* `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.
Expand Down
1 change: 1 addition & 0 deletions packages/playwright/src/worker/testInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ export class TestInfoImpl implements TestInfo {
.replace(/\{(.)?projectName\}/g, projectNamePathSegment ? '$1' + projectNamePathSegment : '')
.replace(/\{(.)?testName\}/g, '$1' + this._fsSanitizedTestName())
.replace(/\{(.)?testFileName\}/g, '$1' + parsedRelativeTestFilePath.base)
.replace(/\{(.)?testFileNameWithoutExtension\}/g, '$1' + parsedRelativeTestFilePath.base.replace(".spec", "").replace(".ts", ""))

Check failure on line 457 in packages/playwright/src/worker/testInfo.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Strings must use singlequote

Check failure on line 457 in packages/playwright/src/worker/testInfo.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Strings must use singlequote

Check failure on line 457 in packages/playwright/src/worker/testInfo.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Strings must use singlequote

Check failure on line 457 in packages/playwright/src/worker/testInfo.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Strings must use singlequote
.replace(/\{(.)?testFilePath\}/g, '$1' + relativeTestFilePath)
.replace(/\{(.)?arg\}/g, '$1' + path.join(parsedSubPath.dir, parsedSubPath.name))
.replace(/\{(.)?ext\}/g, parsedSubPath.ext ? '$1' + parsedSubPath.ext : '');
Expand Down
4 changes: 4 additions & 0 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ interface TestProject<TestArgs = {}, WorkerArgs = {}> {
* - Value: `page`
* - `{testFileName}` - Test file name with extension.
* - Value: `page-click.spec.ts`
* - `{testFileNameWithoutExtension}` - Test file name without extension.
* - Value: `page-click`
* - `{testFilePath}` - Relative path from `testDir` to **test file**
* - Value: `page/page-click.spec.ts`
* - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.
Expand Down Expand Up @@ -1531,6 +1533,8 @@ interface TestConfig<TestArgs = {}, WorkerArgs = {}> {
* - Value: `page`
* - `{testFileName}` - Test file name with extension.
* - Value: `page-click.spec.ts`
* - `{testFileNameWithoutExtension}` - Test file name without extension.
* - Value: `page-click`
* - `{testFilePath}` - Relative path from `testDir` to **test file**
* - Value: `page/page-click.spec.ts`
* - `{testName}` - File-system-sanitized test title, including parent describes but excluding file name.
Expand Down
3 changes: 3 additions & 0 deletions tests/playwright-test/snapshot-path-template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ test('tokens should expand property', async ({ runInlineTest }, testInfo) => {
}, {
name: 'testFileName',
snapshotPathTemplate: '{testFileName}',
}, {
name: 'testFileNameWithoutExtension',
snapshotPathTemplate: '{testFileNameWithoutExtension}',
}, {
name: 'snapshotDir',
snapshotDir: './a-snapshot-dir',
Expand Down

0 comments on commit 8b64b1a

Please sign in to comment.