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

fix(consistent-data-testid): avoid crash for filename with square brackets #643

Conversation

sjarva
Copy link
Collaborator

@sjarva sjarva commented Sep 9, 2022

Checks

  • I have read the contributing guidelines.
  • If some rule is added/updated/removed, I've regenerated the rules list (npm run generate:rules-list)
  • If some rule meta info is changed, I've regenerated the plugin shared configs (npm run generate:configs)

Changes

In the discussion of the issue #509 there hasn't been a consensus how to fix the issue, and this is my suggestion.

It seems that the crash in 509 is caused by several repos using static site generators and their dynamic routing.

Both Gatsby.js and Next.js support square brackets and three periods in filename. However, since the three periods is optional, it makes sense to catch this edge case by looking only at the presence of square brackets.

This PR:

  • makes the consistent-data-testid rule replace {fileName} placeholder with an empty string if the filename gotten from path contains square brackets
  • updates the unit tests to include some edge cases with square brackets
  • updates the rule documentation to mention this edge case

Context

Closes #509.

Comments and thoughts about this PR are welcome.

…name

fileName placeholder will be replaced with an empty string, as dynamic routes cannot be defined
@Belco90 Belco90 changed the title [Fix] consistent-data-testid crashing when filename has square brackets fix(consistent-data-testid): avoid crash for filename with square brackets Sep 9, 2022
@Belco90 Belco90 self-requested a review September 9, 2022 11:33
Copy link
Member

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

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

Amazing contribution! Thank you so much @sjarva

@Belco90 Belco90 merged commit 48b19d5 into testing-library:main Sep 9, 2022
@Belco90
Copy link
Member

Belco90 commented Sep 9, 2022

@all-contributors please add @sjarva for docs

@allcontributors
Copy link
Contributor

@Belco90

I've put up a pull request to add @sjarva! 🎉

@github-actions
Copy link

github-actions bot commented Sep 9, 2022

🎉 This PR is included in version 5.6.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sjarva sjarva deleted the pr/consistent-data-testid-fix-filename-crash branch September 9, 2022 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Results of weekly scheduled smoke test
2 participants