feat(no-template-literal-title): disallow template literals in titles - #500
Open
unlikelyzero wants to merge 1 commit into
Open
feat(no-template-literal-title): disallow template literals in titles#500unlikelyzero wants to merge 1 commit into
unlikelyzero wants to merge 1 commit into
Conversation
A test title is an identifier: reporters group by it, --grep matches it, and flake dashboards key on it. Interpolating a value into the title of test, test.describe, or test.step means the name only exists once the data does and changes when the data changes, so grep stops working and result history fragments across runs. Report interpolated titles with no autofix, since choosing a stable replacement is the author's call. Report template literals with no interpolation separately and fix them to string literals, escaping quotes and backslashes and bailing on multiline or invalid-escape titles so the reported name cannot change. An ignore option skips test, test.describe, or test.step individually, mirroring prefer-lowercase-title, so suites that deliberately parameterize test names can keep the rule for describes and steps. Not enabled in the recommended config.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #499
Adds
no-template-literal-title, which reports a template literal used as thetitle of
test,test.describe, ortest.step.A test title is an identifier — reporters group by it,
--grepmatches it, andflake dashboards key on it. Interpolating a value means the title only exists
once the data does, and changes when the data changes:
--grep "login as admin"matches nothing predictable from the source, and a title that reads
upload invoice-8842.pdfon one run is a different test to anything trackingresults over time.
The rule splits that into two reports, because the two cases deserve different
treatment:
test(`login as ${role}`)interpolatedTitletest(`checkout completes`)staticTemplateLiteral'checkout completes'The fixer escapes
\and', and declines to fix multiline titles or oneswhose cooked value is
null(invalid escape sequence), so it can never changethe name that ends up in a report.
Options
ignore: Array<'test' | 'test.describe' | 'test.step'>skips the listedcallers, mirroring the
ignoreoption onprefer-lowercase-title. A suite thatdeliberately generates parameterized test names can set
{ ignore: ['test'] }and still get stable
test.describeandtest.steptitles.Not added to the
recommendedconfig — parameterized titles are an establishedPlaywright pattern, so whether to forbid them is a project-level policy choice.
Tests
34 cases covering modifiers (
.only,.skip,.fixme,.describe.only),globalAliases, fixer escaping of backticks/quotes/backslashes, the unfixablemultiline case, both option paths, and the negatives — anonymous
test.describe(() => {}), string concatenation, and template literals inlocators or
test.describe.configure().