Skip to content

feat(profile-server): add Jest config, test infra, and migrated test files#20212

Merged
vbudhram merged 1 commit intomainfrom
test-updates
Mar 23, 2026
Merged

feat(profile-server): add Jest config, test infra, and migrated test files#20212
vbudhram merged 1 commit intomainfrom
test-updates

Conversation

@vbudhram
Copy link
Copy Markdown
Contributor

@vbudhram vbudhram commented Mar 18, 2026

Because

  • Profile server tests were Mocha-only (.js), inconsistent with the repo-wide Jest migration
  • Migrated Jest tests had no CI wiring, so they would not run in the pipeline

This pull request

  • Adds jest.config.ts and tsconfig.json for profile-server Jest/TypeScript support
  • Migrates 6 Mocha test files to TypeScript Jest specs (75/75 test cases, 286/287 assertions preserved)
  • Adds test/lib/util.ts with shared assertSecurityHeaders helper for Jest specs
  • Updates test/lib/mock.js with try/catch in log filter and clear-before-iterate in done()
  • Adds test-integration-jest, test-jest, and test-jest-unit scripts with NODE_ENV=test to package.json
  • Appends Jest unit test run to existing test-unit script (runs after Mocha)
  • Widens CircleCI "Integration Test Jest - Servers - Auth" job filter to include fxa-profile-server (PR and tag deploy workflows)

Migration verification

File Mocha Jest Mocha Asserts Jest Asserts Notes
api.jsapi.in.spec.ts 53 53 204 204 Includes assertSecurityHeaders
events.jsevents.in.spec.ts 7 7 19 19
mysql.jsmysql.spec.ts 3 3 13 12 rejects.toThrow replaces assert.fail+assert.equal
profileCache.jsprofileCache.in.spec.ts 7 7 43 43
server.jsserver.in.spec.ts 4 4 7 7
_shared.js_shared.spec.ts 1 1 1 1
Total 75 75 287 286

Issue

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

Checklist

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

Other Information

How to test locally:

cd packages/fxa-profile-server

# Unit tests (no infrastructure needed)
yarn test-jest-unit

# Integration tests (requires yarn start infrastructure)
yarn test-integration-jest

# Via Nx
npx nx run fxa-profile-server:test-jest-unit
npx nx run fxa-profile-server:test-integration-jest

CI wiring:

  • Jest unit tests run in the existing "Unit Test" job via the updated test-unit script
  • Jest integration tests run in the existing "Integration Test Jest - Servers - Auth" job via test-integration-jest
  • No new CI jobs added; the auth Jest job filter was widened to include fxa-profile-server

@vbudhram vbudhram self-assigned this Mar 18, 2026
@vbudhram vbudhram force-pushed the test-updates branch 6 times, most recently from a98eb5b to 68c5750 Compare March 19, 2026 02:07
@vbudhram vbudhram marked this pull request as ready for review March 19, 2026 17:46
@vbudhram vbudhram requested a review from a team as a code owner March 19, 2026 17:46
Copilot AI review requested due to automatic review settings March 19, 2026 17:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Jest-based TypeScript test infrastructure for fxa-profile-server, migrating existing Mocha tests and wiring them into existing Nx/CircleCI pipelines so they run in CI.

Changes:

  • Added jest.config.ts + tsconfig.json to enable TypeScript Jest tests in fxa-profile-server.
  • Migrated Mocha test suites to Jest TypeScript specs and introduced shared test helpers under test/lib/.
  • Updated package.json scripts and CircleCI workflow filters to run Jest unit/integration tests for fxa-profile-server.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
yarn.lock Adds/updates dev dependency resolutions for Jest + TS support.
packages/fxa-profile-server/tsconfig.json Package-level TS config for compiling tests (and JS interop).
packages/fxa-profile-server/jest.config.ts Jest/ts-jest configuration for unit + integration specs.
packages/fxa-profile-server/package.json Adds Jest/Nx scripts and new devDependencies needed for TS Jest runs.
.circleci/config.yml Expands auth-server Jest integration workflow filter to include fxa-profile-server.
packages/fxa-profile-server/test/server.in.spec.ts Jest migration of server integration tests.
packages/fxa-profile-server/test/routes/avatar/_shared.spec.ts Jest migration of avatar shared-route unit tests.
packages/fxa-profile-server/test/profileCache.in.spec.ts Jest migration of profile cache integration tests.
packages/fxa-profile-server/test/mysql.spec.ts Jest migration of mysql backend unit tests.
packages/fxa-profile-server/test/lib/util.ts New shared Jest assertion helper(s).
packages/fxa-profile-server/test/lib/static.ts New helper for static server inject requests.
packages/fxa-profile-server/test/lib/server.ts New helper to create/inject profile server requests under Jest.
packages/fxa-profile-server/test/lib/mock.ts New shared mocking utilities (nock/worker/img/log) for Jest specs.
packages/fxa-profile-server/test/lib/inject.ts Helper to inject and stream worker responses in tests.
packages/fxa-profile-server/test/events.in.spec.ts Jest migration of events integration tests.
packages/fxa-profile-server/test/api.in.spec.ts Jest migration of API integration suite (largest coverage surface).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

});

async function checkVersionAndHeaders(_path: string) {
const res = await Server.get('/');
Comment on lines +17 to +22
"test-unit": "MOCHA_FILE=../../artifacts/tests/$npm_package_name/fxa-profile-server-mocha-unit-results.xml node ./scripts/mocha-coverage.js --recursive test/*.js test/routes/*/*.js -g '#integration' --invert && npx jest --no-coverage --forceExit --testPathPattern='spec\\.ts$' --testPathIgnorePatterns='in\\.spec\\.ts$'",
"test-integration": "MOCHA_FILE=../../artifacts/tests/$npm_package_name/fxa-profile-server-mocha-integration-results.xml node ./scripts/mocha-coverage.js --recursive test/*.js test/routes/*/*.js -g '#integration'",
"test-jest": "jest --no-coverage --forceExit",
"test-jest-unit": "jest --no-coverage --forceExit --testPathPattern='spec\\.ts$' --testPathIgnorePatterns='in\\.spec\\.ts$'",
"test-jest-integration": "jest --no-coverage --forceExit --testPathPattern='in\\.spec\\.ts$'",
"test-integration-jest": "npx jest --no-coverage --forceExit --testPathPattern='in\\.spec\\.ts$'",
"through": "2.3.8"
"through": "2.3.8",
"ts-jest": "^29.1.1",
"typescript": "~5.5.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same. In package root.

},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.0.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is also defined in the root package.json. I doubt we need it here.

"@types/jest": "^29.5.14",
"@types/node": "^22.0.0",
"@types/sharp": "^0",
"@types/sinon": "^17.0.0",
@vbudhram vbudhram force-pushed the test-updates branch 8 times, most recently from ce935db to a87a6be Compare March 20, 2026 19:09
Comment thread .circleci/config.yml
name: Integration Test Jest - Servers - Auth (PR)
nx_run: affected --base=main --head=$CIRCLE_SHA1
projects: --exclude '*,!tag:scope:server:auth'
projects: --exclude '*,!tag:scope:server:auth,!fxa-profile-server'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to do this over on Integration Test Jest - Servers - Auth (Nightly)?

};

for (const [header, value] of Object.entries(expected)) {
expect(res.headers[header]).toBeTruthy();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems redundant... we already check the value is correct.

try {
await db._teardown();
} catch (_e) {
// _clear may not be available depending on db backend
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's _clear?

expect(body.locale).toBe('en-US');
expect(body.amrValues).toEqual(['pwd']);
expect(body.twoFactorAuthentication).toBe(false);
expect(typeof body.subscriptions).toBe('undefined');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use toBeUndefined?

import path from 'path';
import sinon from 'sinon';
import checksum from 'checksum';
import P from '../lib/promise';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd be really easy to phase this out...

"stream-to-array": "2.3.0"
},
"devDependencies": {
"@types/jest": "^29.5.14",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is already defined in the root package.json

expect(res2.headers['last-modified']).toBeTruthy();
expect(res2.headers['last-modified']).toBe(lastModified);

await P.delay(1000);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Calling this out for future work. It'd be greate to use jest fake timers.

Copy link
Copy Markdown
Contributor

@dschom dschom left a comment

Choose a reason for hiding this comment

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

Looks good. Most important feed back is about packages in package.json.

@vbudhram vbudhram force-pushed the test-updates branch 2 times, most recently from 730af2d to e4a5f30 Compare March 23, 2026 13:35
@vbudhram vbudhram merged commit 48c9dc7 into main Mar 23, 2026
22 checks passed
@vbudhram vbudhram deleted the test-updates branch March 23, 2026 14:26
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