feat(profile-server): add Jest config, test infra, and migrated test files#20212
feat(profile-server): add Jest config, test infra, and migrated test files#20212
Conversation
a98eb5b to
68c5750
Compare
There was a problem hiding this comment.
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.jsonto enable TypeScript Jest tests infxa-profile-server. - Migrated Mocha test suites to Jest TypeScript specs and introduced shared test helpers under
test/lib/. - Updated
package.jsonscripts and CircleCI workflow filters to run Jest unit/integration tests forfxa-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('/'); |
| "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" |
| }, | ||
| "devDependencies": { | ||
| "@types/jest": "^29.5.14", | ||
| "@types/node": "^22.0.0", |
There was a problem hiding this comment.
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", |
ce935db to
a87a6be
Compare
| 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' |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
| expect(body.locale).toBe('en-US'); | ||
| expect(body.amrValues).toEqual(['pwd']); | ||
| expect(body.twoFactorAuthentication).toBe(false); | ||
| expect(typeof body.subscriptions).toBe('undefined'); |
| import path from 'path'; | ||
| import sinon from 'sinon'; | ||
| import checksum from 'checksum'; | ||
| import P from '../lib/promise'; |
There was a problem hiding this comment.
I'd be really easy to phase this out...
| "stream-to-array": "2.3.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/jest": "^29.5.14", |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Calling this out for future work. It'd be greate to use jest fake timers.
dschom
left a comment
There was a problem hiding this comment.
Looks good. Most important feed back is about packages in package.json.
730af2d to
e4a5f30
Compare
Because
.js), inconsistent with the repo-wide Jest migrationThis pull request
jest.config.tsandtsconfig.jsonfor profile-server Jest/TypeScript supporttest/lib/util.tswith sharedassertSecurityHeadershelper for Jest specstest/lib/mock.jswith try/catch in log filter and clear-before-iterate indone()test-integration-jest,test-jest, andtest-jest-unitscripts withNODE_ENV=testtopackage.jsontest-unitscript (runs after Mocha)fxa-profile-server(PR and tag deploy workflows)Migration verification
api.js→api.in.spec.tsassertSecurityHeadersevents.js→events.in.spec.tsmysql.js→mysql.spec.tsrejects.toThrowreplacesassert.fail+assert.equalprofileCache.js→profileCache.in.spec.tsserver.js→server.in.spec.ts_shared.js→_shared.spec.tsIssue
Closes: https://mozilla-hub.atlassian.net/browse/FXA-12618
Checklist
Other Information
How to test locally:
CI wiring:
test-unitscripttest-integration-jestfxa-profile-server