这是indexloc提供的服务,不要输入任何密码
Skip to content

fix(tests): fix i18n tests [skip ci] #2950

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

Merged
merged 1 commit into from
May 15, 2025
Merged

Conversation

markrickert
Copy link
Member

Description

The tests were failing on #2924 but i thought it was just the CI being flaky… surely changing one word in a comment wouldn’t cause the entire test suite to hang! So i merged it.

Boy was I wrong. Turns out that the i18n tests actually greps the filesystem looking for instances of the translate() function, extracts their keys, and then compares those keys to the list inside the translation files.

This grep command doesn’t take commented code into consideration so it sees these blocks of code as equally valid instances of the translate()function:

translate("key1")

// translate("key2")

/**
  * translate("key3")
  */

So the test will look for ["key1", "key2", "key3"] and make sure the translations exist instead of just ["key1"] like we'd expect.

To solve this, I added the key ”hello” to the EXCEPTIONS list with a large comment above it about why... so that this comment will no longer cause the test suite to hang and eventually fail.

Checklist

  • I have manually tested this, including by generating a new app locally (see docs).

The tests were failing on #2924 but i thought it was just the CI being flaky… surely changing one word in a comment wouldn’t cause the entire test suite to hang!

Boy was I wrong. Turns out that the i18n tests actually greps the filesystem looking for instances of the translate() function, extracts their keys, and then compares those keys to the list inside the translation files.

Well, this grep command doesn’t take commented code into account so it sees these blocks of code as equally valid:

translate(‘key1’)

// translate(‘key2’)

/**
  * translate(‘key3’)
  */

So the test will look for [key1, key2, key3] and make sure the translations exist.

To solve this, I added the key `”hello”` to the EXCEPTIONS list so that this comment will no longer cause the test suite to hang and eventually fail.
@markrickert markrickert requested a review from frankcalise May 15, 2025 03:31
@markrickert markrickert changed the title fix(tests): fix i18n tests fix(tests): fix i18n tests [skip ci] May 15, 2025
Copy link
Contributor

@frankcalise frankcalise left a comment

Choose a reason for hiding this comment

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

I'd love to fix the grep one day but I gave it an ole GPT and didn't have much luck.

At least git blame points to Jamon

@markrickert
Copy link
Member Author

Yeah, until the grep is fixed, tests would fail if both of the following happen:

  1. user comments out a block of code with a translate("key") function
  2. user removes that key from their translations but leaves the commented code in place

@markrickert markrickert merged commit 17dd1a4 into master May 15, 2025
3 checks passed
@markrickert markrickert deleted the mrickert/i18ntests branch May 15, 2025 03:48
infinitered-circleci pushed a commit that referenced this pull request May 20, 2025
## [10.4.1](v10.4.0...v10.4.1) (2025-05-20)

### Bug Fixes

* **cli:** correct mobx removal when using prompts ([#2949](#2949) by [@frankcalise](https://github.com/frankcalise)) ([73e9809](73e9809))
* **docs:** updated the doc for i18n translate to reflect proper usage of the translation keys ([#2924](#2924)) [skip ci] ([7bb8c5c](7bb8c5c))
* **Header:** change Header's pointerEvents="none" from a prop to a style ([#2933](#2933)) [skip ci] ([a0d305f](a0d305f))
* **tests:** fix i18n tests failing because of a rogue grep and regex not understanding comments ([#2950](#2950)) [skip ci] ([17dd1a4](17dd1a4)), closes [#2924](#2924)
@infinitered-circleci
Copy link
Contributor

🎉 This PR is included in version 10.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

3 participants