Skip to content

WIP feat(fxa-auth-server): Migrate 19 route unit tests from Mocha to Jest PART 6#20147

Open
vbudhram wants to merge 1 commit intomainfrom
fxa-12610
Open

WIP feat(fxa-auth-server): Migrate 19 route unit tests from Mocha to Jest PART 6#20147
vbudhram wants to merge 1 commit intomainfrom
fxa-12610

Conversation

@vbudhram
Copy link
Contributor

@vbudhram vbudhram commented Mar 5, 2026

Because

  • The auth-server is migrating from Mocha to Jest for unit tests (FXA-12610)
  • Co-located .spec.ts files improve discoverability and reduce deep relative import paths
  • Jest provides better TypeScript support, parallel execution, and modern assertion APIs

This pull request

  • Adds 19 co-located Jest .spec.ts files under lib/routes/, migrating from test/local/routes/
  • Converts all Chai assertions to Jest expect() and preserves sinon spy/stub assertions
  • Replaces proxyquire with jest.mock() where applicable (auth-oauth, cloud-scheduler, oauth utils)
  • Converts Mocha lifecycle hooks (before/after) to Jest equivalents (beforeAll/afterAll)
  • Adds Container cleanup (Container.reset()) for typedi-based tests
  • Original Mocha tests remain in place (coexistence strategy)

Mocha ↔ Jest Parity

File Mocha Source Jest Target Tests
request_helper test/local/routes/request_helper.js lib/routes/utils/request_helper.spec.ts 2
validators test/local/routes/validators.js lib/routes/validators.spec.ts 91
hawk-fxa-token test/local/routes/auth-schemes/hawk-fxa-token.js lib/routes/auth-schemes/hawk-fxa-token.spec.ts 4
shared-secret test/local/routes/auth-schemes/shared-secret.js lib/routes/auth-schemes/shared-secret.spec.ts 3
verified-session-token test/local/routes/auth-schemes/verified-session-token.js lib/routes/auth-schemes/verified-session-token.spec.ts 10
account test/local/routes/utils/account.js lib/routes/utils/account.spec.ts 10
security-event test/local/routes/utils/security-event.ts lib/routes/utils/security-event.spec.ts 8
auth-oauth test/local/routes/auth-schemes/auth-oauth.js lib/routes/auth-schemes/auth-oauth.spec.ts 4
google-oidc test/local/routes/auth-schemes/google-oidc.js lib/routes/auth-schemes/google-oidc.spec.ts 4
refresh-token test/local/routes/auth-schemes/refresh-token.js lib/routes/auth-schemes/refresh-token.spec.ts 8
cloud-scheduler test/local/routes/cloud-scheduler.js lib/routes/cloud-scheduler.spec.ts 1
mfa (auth-scheme) test/local/routes/auth-schemes/mfa.js lib/routes/auth-schemes/mfa.spec.ts 11
cloud-tasks test/local/routes/cloud-tasks.js lib/routes/cloud-tasks.spec.ts 2
oauth test/local/routes/utils/oauth.js lib/routes/utils/oauth.spec.ts 8
signup test/local/routes/utils/signup.js lib/routes/utils/signup.spec.ts 6
clients test/local/routes/utils/clients.js lib/routes/utils/clients.spec.ts 9
localization test/local/routes/utils/cms/localization.js lib/routes/utils/cms/localization.spec.ts 41
signin test/local/routes/utils/signin.js lib/routes/utils/signin.spec.ts 41
mfa (route) test/local/routes/mfa.js lib/routes/mfa.spec.ts 3
Total 266

All 266 tests have 1:1 assertion parity with their Mocha equivalents. Verified with 5 consecutive green runs (0 flaky tests).

Issue

Closes: https://mozilla-hub.atlassian.net/browse/FXA-12610

Checklist

  • My commit is GPG signed
  • Tests pass locally (if applicable)
  • Documentation updated (if applicable)
  • RTL rendering verified (if UI changed)

Other Information

How to verify:

cd packages/fxa-auth-server
npx jest --no-coverage --forceExit --testPathPattern='lib/routes/(auth-schemes|utils|validators|cloud-scheduler|cloud-tasks|mfa).*\.spec\.ts'

All 19 suites (+ existing ip-profiling.spec.ts exemplar = 20 suites, 280 tests) pass. Mocha originals are untouched and continue to pass independently.
``

@vbudhram vbudhram requested a review from a team as a code owner March 5, 2026 20:32
@vbudhram vbudhram changed the title feat(fxa-auth-server): Migrate 19 route unit tests from Mocha to Jest PART 6 WIP feat(fxa-auth-server): Migrate 19 route unit tests from Mocha to Jest PART 6 Mar 5, 2026
…ocated Jest (FXA-12610)

Migrate test files from test/local/routes/ to co-located .spec.ts files
under lib/routes/, following the pattern established by ip-profiling.spec.ts.
Mocha originals are kept in place (coexistence). 280 tests across 19 suites.
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.

1 participant