Skip to content

WIP test(fxa-auth-server): migrate 16 OAuth Mocha test files to Jest PART 5#20146

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

WIP test(fxa-auth-server): migrate 16 OAuth Mocha test files to Jest PART 5#20146
vbudhram wants to merge 1 commit intomainfrom
fxa-12565

Conversation

@vbudhram
Copy link
Contributor

@vbudhram vbudhram commented Mar 5, 2026

Because

  • The auth-server OAuth tests used Mocha/Chai/Proxyquire while the rest of the test suite is migrating to Jest
  • Mixed test frameworks increase maintenance burden and prevent unified test infrastructure (shared global setup/teardown, consistent mocking patterns)
  • Jest co-located .spec.ts files improve discoverability and align with project conventions

This pull request

  • Migrates all 16 OAuth test files from test/oauth/ to Jest with full test parity (337 tests preserved)
  • Adds 13 co-located unit test .spec.ts files next to source in lib/
  • Adds 5 integration test .in.spec.ts files in test/remote/
  • Splits 2 mixed files (grant.js, routes/token.js) into separate unit and integration test files
  • Adds '^fxa-shared$' moduleNameMapper to jest.integration.config.js to prevent ScopeSet class identity mismatch
  • Adds CORS_ORIGIN env var to jest-setup-env.ts and jest-global-setup.ts for test parity with CI
  • Mocks ESM-only packages (@octokit/rest, p-queue) in oauth_api.in.spec.ts via jest.mock()

Issue

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

Checklist

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

Other Information

Test Parity

337 old → 337 new (336 active + 1 skipped)

Unit Tests (co-located .spec.ts)

Old File New File Tests Status
test/oauth/util.js lib/oauth/util.spec.ts 1 Exact
test/oauth/token.js lib/oauth/token.spec.ts 1 Exact
test/oauth/assertion.js lib/oauth/assertion.spec.ts 11 Exact
test/oauth/jwt.js lib/oauth/jwt.spec.ts 11 Exact
test/oauth/jwt_access_token.js lib/oauth/jwt_access_token.spec.ts 11 Exact
test/oauth/jwt_id_token.js lib/oauth/jwt_id_token.spec.ts 12 Exact
test/oauth/jwt_sub.js lib/oauth/jwt_sub.spec.ts 10 Exact
test/oauth/keys.js lib/oauth/keys.spec.ts 15 Exact
test/oauth/routes/authorization.js lib/routes/oauth/authorization.spec.ts 16 Exact
test/oauth/routes/jwks.js lib/routes/oauth/jwks.spec.ts 1 Exact
test/oauth/routes/verify.js lib/routes/oauth/verify.spec.ts 6 Exact

Split Files (unit + integration)

Old File Unit Integration Tests Status
test/oauth/grant.js lib/oauth/grant.spec.ts test/remote/oauth_grant.in.spec.ts 13+3=16 Exact
test/oauth/routes/token.js lib/routes/oauth/token.spec.ts test/remote/oauth_token_route.in.spec.ts 29+4=33 Exact

Integration Tests (test/remote/*.in.spec.ts)

Old File New File Tests Status
test/oauth/api.js test/remote/oauth_api.in.spec.ts 163 1 skip*
test/oauth/db/index.js test/remote/oauth_db.in.spec.ts 29 Exact
test/oauth/key-management-scripts.js test/remote/oauth_key_management.in.spec.ts 1 Exact

How to test

cd packages/fxa-auth-server

# Unit tests (13 files, 138 tests)
npx jest --no-coverage --forceExit lib/oauth/*.spec.ts lib/routes/oauth/*.spec.ts

# Integration tests (5 files, 200 tests — requires infrastructure)
yarn start infrastructure  # in separate terminal
npx jest --config jest.integration.config.js --forceExit test/remote/oauth_*.in.spec.ts

@vbudhram vbudhram requested a review from a team as a code owner March 5, 2026 19:56
for (const { label, script, env } of keyScripts) {
console.log(`[Jest Global Setup] Checking/generating ${label}...`);
try {
execSync(`node -r esbuild-register ${script}`, {

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium test

This shell command depends on an uncontrolled
absolute path
.
@vbudhram vbudhram force-pushed the fxa-12565 branch 6 times, most recently from 785d526 to 226c60c Compare March 5, 2026 21:03
@vbudhram vbudhram changed the title test(fxa-auth-server): migrate 16 OAuth Mocha test files to Jest PART 5 WIP test(fxa-auth-server): migrate 16 OAuth Mocha test files to Jest PART 5 Mar 5, 2026
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