Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes Mocha-based tests and tooling from fxa-auth-server, standardizing on Jest for running unit/integration/script tests.
Changes:
- Deleted legacy Mocha test suites, helpers, and coverage tooling (nyc/mocha-coverage).
- Updated test runner scripts/CI and VS Code tasks/launch configs to use Jest.
- Adjusted a few Jest integration tests/utilities (Redis scoped cleanup; DB closes knex; some script specs updated to Jest assertions).
Reviewed changes
Copilot reviewed 75 out of 372 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/fxa-auth-server/test/local/metrics/client-tags.ts | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/l10n/index.ts | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/ip_profiling.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/inactive-accounts/index.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/google-maps-services.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/getRemoteAddressChain.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/geodb.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/features.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/error.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/email/utils.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/email/notifications.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/email/delivery.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/email/delivery-delay.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/email-cloud-tasks.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/crypto/scrypt.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/crypto/random.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/crypto/pbkdf2.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/crypto/hkdf.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/crypto/butil.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/config/index.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/cad-reminders.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/bounces.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/authMethods.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/account-events.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/local/account-delete.js | Removed Mocha local test file. |
| packages/fxa-auth-server/test/lib/util.ts | Removed Mocha-era test util. |
| packages/fxa-auth-server/test/lib/util.js | Removed Mocha-era test util. |
| packages/fxa-auth-server/test/lib/server.ts | Removed Mocha-era server harness. |
| packages/fxa-auth-server/test/lib/server.js | Removed Mocha-era server harness. |
| packages/fxa-auth-server/test/lib/oauth-test.json | Removed Mocha-era OAuth test config. |
| packages/fxa-auth-server/test/lib/mocks.js | Removed Mocha-era dependency mocking helper. |
| packages/fxa-auth-server/test/key_server_stub.js | Removed Mocha-era server stub. |
| packages/fxa-auth-server/test/e2e/push_tests.js | Removed Mocha e2e test that hits external services. |
| packages/fxa-auth-server/test/e2e/README.txt | Removed Mocha e2e README. |
| packages/fxa-auth-server/test/chaiWithoutTruncation.ts | Removed Chai-specific configuration helper. |
| packages/fxa-auth-server/test/bench/index.js | Removed Mocha-era benchmark harness. |
| packages/fxa-auth-server/test/bench/bot.js | Removed Mocha-era benchmark client. |
| packages/fxa-auth-server/test/assert.js | Removed Chai/Sinon combined assert helper. |
| packages/fxa-auth-server/test/.eslintrc | Removed Mocha-specific ESLint config. |
| packages/fxa-auth-server/scripts/update-subscriptions-to-new-plan/update-subscriptions-to-new-plan.spec.ts | Updated script spec to Jest expectations & adjusted fixture imports. |
| packages/fxa-auth-server/scripts/test-remote-quick.js | Removed Mocha remote test runner script. |
| packages/fxa-auth-server/scripts/test-local.sh | Switched local test entrypoint to Jest-only. |
| packages/fxa-auth-server/scripts/test-ci.sh | Removed Mocha execution; CI now runs Jest unit/integration suites. |
| packages/fxa-auth-server/scripts/stripe-products-and-plans-to-firestore-documents/plan-language-tags-guesser.spec.ts | Updated script spec to Jest expectations and local imports. |
| packages/fxa-auth-server/scripts/recorded-future/lib.spec.ts | Updated script spec to Jest expectations and local imports. |
| packages/fxa-auth-server/scripts/prune-tokens.ts | Avoid Redis setup for --help; close Redis after pruning. |
| packages/fxa-auth-server/scripts/move-customers-to-new-plan/move-customers-to-new-plan.spec.ts | Updated script spec to Jest expectations and added Container reset. |
| packages/fxa-auth-server/scripts/mocha-coverage.js | Removed Mocha+nyc coverage runner. |
| packages/fxa-auth-server/scripts/delete-inactive-accounts/lib.spec.ts | Updated script spec to Jest expectations and local imports. |
| packages/fxa-auth-server/scripts/convert-customers-to-stripe-automatic-tax/helpers.spec.ts | Updated script spec to Jest expectations and local imports. |
| packages/fxa-auth-server/scripts/cleanup-old-carts/cleanup-old-carts.spec.ts | Updated script spec typings/expectations for Jest. |
| packages/fxa-auth-server/scripts/check-firestore-stripe-sync/check-firestore-stripe-sync.spec.ts | Updated script spec for Jest + formatting cleanup. |
| packages/fxa-auth-server/scripts/cancel-subscriptions-to-plan/cancel-subscriptions-to-plan.spec.ts | Updated script spec for Jest assertions and async rejection checks. |
| packages/fxa-auth-server/package.json | Removed Mocha/Chai/nyc deps and scripts; streamlined test scripts. |
| packages/fxa-auth-server/lib/subscription-account-reminders.in.spec.ts | Minor Jest integration test updates + more isolated Redis key cleanup. |
| packages/fxa-auth-server/lib/redis.in.spec.ts | Replaced flushall() with scoped cleanup to reduce parallel-test flake risk. |
| packages/fxa-auth-server/lib/db.ts | DB now tracks/destroys knex on close. |
| packages/fxa-auth-server/lib/cad-reminders.in.spec.ts | Renamed Redis prefix to avoid collisions. |
| packages/fxa-auth-server/jest.config.js | Expanded Jest default testMatch to include scripts specs; adjusted transformIgnorePatterns. |
| packages/fxa-auth-server/.vscode/tasks.json | Updated VS Code task to run Jest current file. |
| packages/fxa-auth-server/.vscode/launch.json | Replaced Mocha debug configs with Jest debug configs. |
| packages/fxa-auth-server/.mocharc.js | Removed Mocha config file. |
| nx.json | Removed Nx targets related to Mocha-based integration variants. |
| .circleci/config.yml | Removed CircleCI workflows/jobs related to removed Mocha integration variants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "name": "Jest Current File", | ||
| "program": "${workspaceFolder}/node_modules/.bin/jest", | ||
| "args": [ | ||
| "--require", | ||
| "esbuild-register", | ||
| "--recursive", | ||
| "--timeout", | ||
| "999999", | ||
| "--colors", | ||
| "${workspaceFolder}/test/local" | ||
| "--no-coverage", | ||
| "--forceExit", | ||
| "${relativeFile}" | ||
| ], |
There was a problem hiding this comment.
${workspaceFolder}/node_modules/.bin/jest is likely incorrect in a monorepo where dependencies live at the repo root (the old Mocha config referenced ../../node_modules/...). This will break debugging unless packages/fxa-auth-server/node_modules exists. Consider pointing program at the workspace root’s Jest binary (e.g. ../../node_modules/.bin/jest) or using a runtimeExecutable of npx with jest in args.
| // keys('*') returns fully-prefixed keys, so strip the prefix before del() to avoid | ||
| // double-prefixing. | ||
| const keys = await redis.redis.keys('*'); | ||
| if (keys.length) { | ||
| await redis.redis.del( | ||
| ...keys.map((k: string) => k.replace(prefix, '')) | ||
| ); |
There was a problem hiding this comment.
KEYS * is an O(N) operation and can become slow/non-deterministic if the prefixed keyspace grows (even in tests, this can introduce flakiness). Also, replace(prefix, '') is not anchored; if prefix appears later in a key, it will strip the wrong segment. Prefer iterating via SCAN and stripping only when k.startsWith(prefix) (e.g., k.slice(prefix.length)), and consider chunking deletes to avoid huge DEL argument lists.
| // keys('*') returns fully-prefixed keys, so strip the prefix before del() to avoid | |
| // double-prefixing. | |
| const keys = await redis.redis.keys('*'); | |
| if (keys.length) { | |
| await redis.redis.del( | |
| ...keys.map((k: string) => k.replace(prefix, '')) | |
| ); | |
| // scan('*') returns fully-prefixed keys, so strip the prefix before del() to avoid | |
| // double-prefixing. Use SCAN instead of KEYS to avoid blocking the Redis server, | |
| // and delete in chunks to avoid huge DEL argument lists. | |
| const keysToDelete: string[] = []; | |
| let cursor = '0'; | |
| do { | |
| const result = await redis.redis.scan(cursor, 'MATCH', '*', 'COUNT', '100'); | |
| cursor = result[0]; | |
| const keys = result[1]; | |
| for (const k of keys) { | |
| if (k.startsWith(prefix)) { | |
| keysToDelete.push(k.slice(prefix.length)); | |
| } | |
| } | |
| } while (cursor !== '0'); | |
| for (let i = 0; i < keysToDelete.length; i += 100) { | |
| await redis.redis.del(...keysToDelete.slice(i, i + 100)); |
| const shouldPrintHelp = | ||
| process.argv.includes('--help') || process.argv.includes('-h'); | ||
| program | ||
| .version(pckg.version) |
There was a problem hiding this comment.
init() previously behaved like a Promise<void>; returning 0 changes its inferred return type to Promise<number | void>, which can break callers expecting void (and makes the function’s contract ambiguous). If the goal is to avoid side effects on --help, consider either (1) making init consistently return an exit code (Promise<number>) and updating its callers accordingly, or (2) keeping init(): Promise<void> and simply return; here (Commander will typically print help/exit on its own).
| .parse(process.argv); | ||
|
|
||
| if (shouldPrintHelp) { | ||
| return 0; |
There was a problem hiding this comment.
init() previously behaved like a Promise<void>; returning 0 changes its inferred return type to Promise<number | void>, which can break callers expecting void (and makes the function’s contract ambiguous). If the goal is to avoid side effects on --help, consider either (1) making init consistently return an exit code (Promise<number>) and updating its callers accordingly, or (2) keeping init(): Promise<void> and simply return; here (Commander will typically print help/exit on its own).
| return 0; | |
| return; |
| testMatch: [ | ||
| '<rootDir>/lib/**/*.spec.ts', | ||
| '<rootDir>/config/**/*.spec.ts', | ||
| '<rootDir>/scripts/**/*.spec.ts', | ||
| ], |
There was a problem hiding this comment.
Including <rootDir>/scripts/**/*.spec.ts in the default Jest config will also match *.in.spec.ts files (since they still end with .spec.ts). If .in.spec.ts are intended to run only under jest.integration.config.js, consider excluding them from the default run (e.g. via testPathIgnorePatterns for \\.in\\.spec\\.ts$) to keep TEST_TYPE=unit fast and hermetic.
bc626c7 to
acf8a5f
Compare
| "request": "launch", | ||
| "name": "Mocha All (local)", | ||
| "program": "${workspaceFolder}/../../node_modules/mocha/bin/_mocha", | ||
| "name": "Jest Current File", |
There was a problem hiding this comment.
I'll be honest, I didn't even know these existed! I think the only way vscode would pick this up or use it is if you open just the fxa-auth-server folder so these might not even be necessary... but we can leave it for now!
|
|
||
| elif [ "$TEST_TYPE" == 'scripts' ]; then | ||
| echo -e "\n\nRunning Jest script integration tests (test/scripts/**/*.in.spec.ts)" | ||
| JEST_JUNIT_OUTPUT_DIR="../../artifacts/tests/fxa-auth-server-scripts" \ |
There was a problem hiding this comment.
The test metrics dashboards that these are piped into will probably need adjusting after all of this lands. Not something that needs addressed here, just making note so more than one person knows 😄
| extends: ../.eslintrc | ||
|
|
||
| env: | ||
| mocha: true |
nshirley
left a comment
There was a problem hiding this comment.
So long, Mocha!
One thing of note, and maybe doesn't need to be done here but the README still references mocha. It would be nice to update the readme with new changes and requirements. Also, several of the new Jest files have a comment at the top like
/** Migrated from test/local/payments/iap/apple-app-store/purchase-manager.js (Mocha → Jest). */
Maybe a quick follow up to delete those once this lands?
Remove Mocha test runner and migrate all remaining integration tests to Jest. Split the single CI integration job into separate integration and scripts jobs. Clean up dead code, migration comments, and stale frozen-file rules for deleted Mocha tests.
Because
/password/forgot/status) accumulated over yearsThis pull request
test/local/,test/remote/,test/oauth/, andtest/scripts/(all previously migrated to Jest)mocha,chai,sinontest helpers,.mocharc.js,test/assert.js,test/setup.js)jest.scripts.config.jsfor script integration tests (test/scripts/**/*.in.spec.ts)test-integrationinto two jobs:test-integration(remote + lib tests) andtest-scripts(script tests)scripts/test-ci.shandscripts/test-local.shto support the newscriptstest typepasswordForgotStatusclient method and emptyit.skipstubs for the removed/password/forgot/statusendpointnx.jsontarget defaults withtest-scriptsbuild/gen-keys dependenciesChecklist
Put an
xin the boxes that applyOther information
265 files changed, 125 insertions, 116,747 deletions.
This is a large deletion-heavy PR. The Mocha test files were already fully migrated to co-located Jest specs in prior PRs. This PR removes the originals and cleans up the CI configuration.