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

[PM-16917] Remove jest-extended dependency #12798

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

eliykat
Copy link
Member

@eliykat eliykat commented Jan 10, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-16917

📔 Objective

@Hinton requested that we reconsider whether we need the jest-extended dependency.

We only use 2 matchers from it:

  • tobeTrue() - trivially rewritten as expect().toBe(true).
  • toIncludeAllPartialMembers - this checks that all the expected objects appear in the array using a partial match (e.g. objectContaining). This is useful but was easy enough to implement our own version of.

I have made these changes and removed jest-extended.

Unfortunately I did need to add jest-diff to present a readable error message if the custom matcher fails. However, this is already used by jest so it's not net new. Also, it's officially maintained by jest rather than the community. So overall I still think this is an improvement.

I made SM Team the owner of jest-diff for renovate purposes, just to keep it grouped with the existing configuration for jest packages.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@eliykat eliykat requested a review from Hinton January 10, 2025 04:07
@eliykat eliykat requested review from a team as code owners January 10, 2025 04:07
@eliykat eliykat requested review from JimmyVo16 and Jingo88 January 10, 2025 04:07
Copy link
Contributor

github-actions bot commented Jan 10, 2025

Logo
Checkmarx One – Scan Summary & Details4645af35-0290-4ef1-bbed-50424331c568

New Issues (2)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Client_Privacy_Violation /apps/cli/src/commands/get.command.ts: 162
detailsMethod getCipher at line 162 of /apps/cli/src/commands/get.command.ts sends user information outside the application. This may constitute a Privacy...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/cli/src/vault/models/cipher.response.ts: 34
detailsMethod CipherResponse at line 34 of /apps/cli/src/vault/models/cipher.response.ts sends user information outside the application. This may constitu...
Attack Vector
Fixed Issues (1)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM Client_Privacy_Violation /apps/cli/src/commands/get.command.ts: 331

Copy link
Member

@audreyality audreyality left a comment

Choose a reason for hiding this comment

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

Looking good!

I'll approve once the failing tests and other reviewers' feedback have been addressed.

) {
const pass = this.equals(
received,
expect.arrayContaining(expected.map((e) => expect.objectContaining(e))),
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻 TIL about expect.arrayContaining! I've been doing this the hard way. 😬

Copy link
Member

Choose a reason for hiding this comment

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

👍🏻 Yo dawg! I put a test in your test so you could test your tests...

Copy link
Member Author

Choose a reason for hiding this comment

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

Always! You test your code but who will test the tests??

Copy link
Member

Choose a reason for hiding this comment

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

♻️ We have enough extensions to jest now that we might want to consider creating our own spec module (e.g. @bitwarden/jest-extensions) and updating jest's configurations to load it. (Not in this PR.)

@JimmyVo16
Copy link
Contributor

This is essentially approved. I'll revisit it once the pipeline passes.

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 34.13%. Comparing base (4c8565f) to head (01518ba).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12798      +/-   ##
==========================================
- Coverage   34.14%   34.13%   -0.01%     
==========================================
  Files        2936     2936              
  Lines       90435    90435              
  Branches    16989    16989              
==========================================
- Hits        30876    30869       -7     
- Misses      57102    57109       +7     
  Partials     2457     2457              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@eliykat
Copy link
Member Author

eliykat commented Jan 13, 2025

I've fixed the failing tests, there were a few places that were still using jest-extended matches that I missed. The change was mostly toHaveBeenCalledOnce() -> toHaveBeenCalledTimes(1). I'm not convinced the syntactic sugar is super useful there, if people want it we could write our own matcher for it fairly trivially, but I assume devs were just using what intellisense was suggesting.

I also had to tweak the matcher itself to not use a generic signature as this is not supported by the jest type package.

EDIT: I've also added more helpful error messages for the positive & negative (expect().not.toContainPartialObjects) cases.

@eliykat eliykat requested a review from Hinton January 13, 2025 03:34
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.

5 participants