Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(test info): Add possibility to use test file name without extenson in snapshotPathTemplate #33420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', ''))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also at least *.spec.js, *.spec.tsx, *.spec.jsx, and same with .test. in the name.

.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}',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual expects need to be extended too to cover various use cases of the new token.

}, {
name: 'snapshotDir',
snapshotDir: './a-snapshot-dir',
Expand Down