Skip to content

Port remaining test in module and context dir to vitest#3880

Merged
eemeli merged 12 commits intomozilla:mainfrom
nishitmistry:port-remaining-test-in-module-and-context-dir-to-vitest
Jan 5, 2026
Merged

Port remaining test in module and context dir to vitest#3880
eemeli merged 12 commits intomozilla:mainfrom
nishitmistry:port-remaining-test-in-module-and-context-dir-to-vitest

Conversation

@nishitmistry
Copy link
Copy Markdown
Collaborator

@nishitmistry nishitmistry commented Dec 30, 2025

In continuation of the previous Mr #3877 for task #3768

  • This Mr includes porting of broken test to vitest under context and modules directory

  • moved useActiveTranslation test to separate file as the mock of react affected all the imports in EntityView.test.jsx, and i found no workaround to keep both test in same file.

  • Changed the test-ownership file to just ignore two test files in vitest and to be ran by jest
    'src/utils/message/getEmptyMessage.test.js',
    and
    'src/modules/entitieslist/components/EntitiesList.test.js',

  • The getEmptyMessage test has been failing since before the transition. I’m currently looking into what needs to be done here. @eemeli , your guidance would be helpful.

  • EntitiesList uses react-intersection-observer which has some ESM issue with vitest, and newer version which might solve this requires react^17.0.0 || ^18.0.0 || ^19.0.0"

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 0% with 93 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.48%. Comparing base (969d1ab) to head (39b0637).
⚠️ Report is 1 commits behind head on main.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nishitmistry nishitmistry force-pushed the port-remaining-test-in-module-and-context-dir-to-vitest branch from e1d33c8 to 32c5e2d Compare December 30, 2025 15:51
@nishitmistry nishitmistry marked this pull request as ready for review December 30, 2025 16:31
@nishitmistry nishitmistry marked this pull request as draft December 30, 2025 17:21
@nishitmistry nishitmistry marked this pull request as ready for review December 31, 2025 06:22
@nishitmistry nishitmistry force-pushed the port-remaining-test-in-module-and-context-dir-to-vitest branch from 7c11b07 to ab7e80c Compare December 31, 2025 06:43
Copy link
Copy Markdown
Member

@eemeli eemeli left a comment

Choose a reason for hiding this comment

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

Looks like we're nearly done with this! See inline for a few tweaks.

The getEmptyMessage test has been failing since before the transition. I’m currently looking into what needs to be done here.

This test suite works for me locally with both Jest and Vitest as-is. How is it failing for you, and what's your OS & Node.js version?

EntitiesList uses react-intersection-observer which has some ESM issue with vitest, and newer version which might solve this requires react^17.0.0 || ^18.0.0 || ^19.0.0"

Let's disable this test suite for now, and add a GitHub issue about it rather than trying to hack together a solution. Because of the enzyme dependency, we're stuck on React 16, which doesn't provide a package.json exports mapping that Vitest expects to resolve the import in the version of react-intersection-observer we're stuck on because, again, we're stuck on React 16.

I think the next PR in this sequence should let us drop Jest, make npm test run Vitest, and drop the test-ownership.js file, yes?

Comment thread translate/test-ownership.js Outdated
Comment thread translate/src/modules/notification/components/NotificationPanel.test.jsx Outdated
@nishitmistry
Copy link
Copy Markdown
Collaborator Author

nishitmistry commented Dec 31, 2025

i am currently on node js v22.20.0 and mac OS 26.1.
getEmptyMessage fails with this message. if you check the Jest pipeline the test fails there too recent jest job

AssertionError: expected 'my-entry =\n    { $num ->\n        [0…' to be 'my-entry =\n    { $num ->\n        [0…' // Object.is equality

- Expected
+ Received

  my-entry =
      { $num ->
          [0] { "" }
-         [one] { "" }
+         [few] { "" }
-         [two] { "" }
+         [one] { "" }
-         [few] { "" }
+         [two] { "" }
         *[other] { "" }
      }


 ❯ src/utils/message/getEmptyMessage.test.js:97:35
     95|     );
     96|     const entry = getEmptyMessageEntry(source, LOCALE);
     97|     expect(serializeEntry(entry)).toBe(ftl`
       |                                   ^
     98|       my-entry =
     99|           { $num ->

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯

 FAIL  src/utils/message/getEmptyMessage.test.js > getEmptyMessage > handles messages with multiple selectors correctly
AssertionError: expected 'selector-multi =\n    { $num ->\n    …' to be 'selector-multi =\n    { $num ->\n    …' // Object.is equality

- Expected
+ Received

@@ -1,18 +1,18 @@
  selector-multi =
      { $num ->
-         [one]
+         [few]
              { $gender ->
                 *[masculine] { "" }
                  [feminine] { "" }
              }
-         [two]
+         [one]
              { $gender ->
                 *[masculine] { "" }
                  [feminine] { "" }
              }
-         [few]
+         [two]
              { $gender ->
                 *[masculine] { "" }
                  [feminine] { "" }
              }
         *[other]

 ❯ src/utils/message/getEmptyMessage.test.js:125:35
    123|     );
    124|     const entry = getEmptyMessageEntry(source, LOCALE);
    125|     expect(serializeEntry(entry)).toBe(ftl`
       |                                   ^
    126|       selector-multi =
    127|           { $num ->
    ```

@nishitmistry
Copy link
Copy Markdown
Collaborator Author

Yes, next Pr will totally drop the jest, test-ownership.js file and will configure vitest as our only test runner.
i will create a github issue for EntitiesList with the jest removal PR such that the issue get documented.

Are we planning to drop sinon, currently the it's not causing any trouble but i think it would be great if we rely just on vitest which provides its mock tools and methods?

@nishitmistry nishitmistry requested a review from eemeli December 31, 2025 14:54
Copy link
Copy Markdown
Member

@eemeli eemeli left a comment

Choose a reason for hiding this comment

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

It looks like the getEmptyMessage test failure is a regression from #3874, as Node.js 22 and earlier don't sort the plural keys like I'd presumed. I'll submit a separate PR fixing my mistake there.

I am quite confused though by why this isn't getting classified as a CI failure, which it ought to do. But that's a separate matter from the changes here, which look good!

Yes, next Pr will totally drop the jest, test-ownership.js file and will configure vitest as our only test runner. i will create a github issue for EntitiesList with the jest removal PR such that the issue get documented.

Excellent!

Are we planning to drop sinon, currently the it's not causing any trouble but i think it would be great if we rely just on vitest which provides its mock tools and methods?

Yeah, it'd be good to drop Sinon once we can. Vitest mocking ought to be enough for us.

@eemeli eemeli merged commit 225b58a into mozilla:main Jan 5, 2026
7 checks passed
@nishitmistry nishitmistry deleted the port-remaining-test-in-module-and-context-dir-to-vitest branch January 6, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants