-
Notifications
You must be signed in to change notification settings - Fork 6.2k
fix: do not collide with other tests when test names have special chars #23414
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -195,8 +195,18 @@ export function expectTypes(receiver: any, types: string[], matcherName: string) | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| export function sanitizeForFilePath(s: string) { | ||||||
| return s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-'); | ||||||
| export function sanitizeForFilePath(input: string) { | ||||||
| let nonTrivialSubstitute = false; | ||||||
| let sanitized = input.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F\x2A\-\*]+/g, substring => { | ||||||
| if (substring !== ' ') | ||||||
| nonTrivialSubstitute = true; | ||||||
| return '-'; | ||||||
| }); | ||||||
| if (!nonTrivialSubstitute) | ||||||
| return sanitized; | ||||||
| // If we sanitized the beginning or end, remove it for cosmetic reasons. | ||||||
| sanitized = sanitized.replace(/^-/, '').replace(/-$/, ''); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the regex already matches more than one character and combines it into a single -, so it should be fine. Added a test to cover this. |
||||||
| return sanitized + '-' + calculateSha1(input).substring(0, 6); | ||||||
| } | ||||||
|
|
||||||
| export function trimLongString(s: string, length = 100) { | ||||||
|
|
@@ -209,14 +219,6 @@ export function trimLongString(s: string, length = 100) { | |||||
| return s.substring(0, start) + middle + s.slice(-end); | ||||||
| } | ||||||
|
|
||||||
| export function addSuffixToFilePath(filePath: string, suffix: string, customExtension?: string, sanitize = false): string { | ||||||
| const dirname = path.dirname(filePath); | ||||||
| const ext = path.extname(filePath); | ||||||
| const name = path.basename(filePath, ext); | ||||||
| const base = path.join(dirname, name); | ||||||
| return (sanitize ? sanitizeForFilePath(base) : base) + suffix + (customExtension || ext); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Returns absolute path contained within parent directory. | ||||||
| */ | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -235,7 +235,7 @@ test(`testInfo.attach name should be sanitized`, async ({ runInlineTest }) => { | |||||||||||||||||||||||||||
| expect(result.failed).toBe(1); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| expect(result.output).toContain('attachment #1: ../../../test (text/plain)'); | ||||||||||||||||||||||||||||
| expect(result.output).toContain(`attachments${path.sep}-test`); | ||||||||||||||||||||||||||||
| expect(result.output).toContain(`attachments${path.sep}test-8d909b-`); | ||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why dash at the end?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A sha1 gets calculated and its separated by a dash. playwright/packages/playwright-test/src/util.ts Lines 269 to 281 in e966b82
|
||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| test(`testInfo.attach name can be empty string`, async ({ runInlineTest }) => { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.