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

[AC-1743] pt. 2.5 ⮕ Fix the unit tests for good #398

Merged
merged 10 commits into from
Jan 12, 2024
Merged

Conversation

addisonbeck
Copy link
Contributor

@addisonbeck addisonbeck commented Jan 10, 2024

[AC-1743] pt. 2.5 ⮕ Fix the unit tests for good

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

🏁 Objective

As part of an initiative to audit dependencies across this project we have been blocked by issues running tests. We need tests to consistently pass to audit used vs unused test dependencies.

🚩 The Problem

Oscar helped get tests passing at the start of this effort, but I broke them when merging the first part of the work to unpackage jslib. This went unnoticed until yesterday, and is blocking the next phase of doing a thorough dependency audit.

🏃The Solution

It was difficult to tell what exactly was going wrong with these tests. Any curious jest experts that want to take a better stab at understanding the break can run npm test from main to observe the current behavior. The core issue, to me, seems to have been the change to tsconfig.paths structures leading to jest not properly mapping imports. This theory has holes in it, since that configuration is automated by a ts-jest helper, but the first batch of errors on main does point in the same direction.

Regardless, I dove through a few sets of errors and ultimately just decided to rebuild the jest config from scratch. I used the documentation for ts-jest, angular-preset-jest, and jest as guidelines, as well as the current clients config and the existing config in directory-connector main.

The end result produces a fully passing test suite. I deleted a few suites that were failing at the end of the work, but only after confirming those suites did not have relevant code for Directory Connector and were instead leftovers from the clients monorepo split and jslib orphaning. These included WebCryptoFunctionService tests, which are used to compare encryption keys, and this is not relevant to Directory Connector. It also includes utils tests for domain matching, which again is only relevant to the core Bitwarden product line.

In addition I went ahead and added a Github workflow for running tests in CI. This was a quick copy/paste/prune job from clients, but it seems to cover our needs for this project.

⏭️ What's next?

Next up in this dependency upgrade effort I'll be:

  1. Removing unused packages.
  2. Performing any patch upgrades for outdated packages
  3. Performing any minor upgrades for outdated packages
  4. Performing any "safe" major upgrades for outdated packages
  5. Upgrading Angular, Webpack, Node, and npm to their latest LTS versions
  6. Handling the remaining major upgrades for outdated packages on a case-by-case basis
  7. Checking in with renovate to see what is still missing

Testing requirements

There are no specific testing requirements for this. QA will be doing a regression run of Directory Connector at the end of this effort.

Before you submit

  • I have checked for linting errors (npm run lint) (required)
  • I have added unit tests where it makes sense to do so (encouraged but not required)
  • This change requires a documentation update (notify the documentation team)
  • This change has particular deployment requirements (notify the DevOps team)

@addisonbeck addisonbeck marked this pull request as ready for review January 10, 2024 20:50
@addisonbeck addisonbeck requested review from a team as code owners January 10, 2024 20:50
mimartin12
mimartin12 previously approved these changes Jan 10, 2024
@addisonbeck addisonbeck changed the title Fix tests [AC-1743] pt. 2.5 ⮕ Fix the unit tests for good Jan 11, 2024
@addisonbeck addisonbeck enabled auto-merge (squash) January 11, 2024 01:10
@addisonbeck addisonbeck requested a review from eliykat January 11, 2024 01:15
es2020-transformer.ts Outdated Show resolved Hide resolved
jest.config.js Outdated Show resolved Hide resolved
jest.config.js Outdated Show resolved Hide resolved
jest.config.js Outdated Show resolved Hide resolved
jest.config.js Show resolved Hide resolved
test.setup.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
tsconfig.eslint.json Outdated Show resolved Hide resolved
@addisonbeck addisonbeck force-pushed the FixTests branch 2 times, most recently from 7416d80 to 9f8be98 Compare January 11, 2024 18:03
Copy link
Member

@eliykat eliykat left a comment

Choose a reason for hiding this comment

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

Great work!

@addisonbeck addisonbeck merged commit 39ed935 into main Jan 12, 2024
13 checks passed
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.

4 participants