Skip to content

Commit eda8982

Browse files
committed
refactor(auth): migrate fxa-auth-server tests from sinon/proxyquire to jest
Because: - sinon/proxyquire is legacy and Jest is the preferred test framework - Jest mocking (jest.mock/jest.fn) provides better TypeScript integration This commit: - Replaces sinon stubs/spies with jest.fn/jest.spyOn across 110+ spec files - Replaces proxyquire with jest.mock for module mocking - Removes jest.setup-proxyquire.js in favor of jest.setup-resolve.js - Removes sinon, proxyquire, and @types/sinon from devDependencies
1 parent ed4693b commit eda8982

120 files changed

Lines changed: 13721 additions & 12617 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/fxa-auth-server/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
maxWorkers: 4,
3030
clearMocks: true,
3131
workerIdleMemoryLimit: '512MB',
32-
setupFiles: ['<rootDir>/jest.setup.js', '<rootDir>/jest.setup-proxyquire.js'],
32+
setupFiles: ['<rootDir>/jest.setup.js', '<rootDir>/jest.setup-resolve.js'],
3333
testPathIgnorePatterns: ['\\.in\\.spec\\.ts$'],
3434
// Coverage configuration (enabled via --coverage flag)
3535
collectCoverageFrom: [

packages/fxa-auth-server/jest.setup-proxyquire.js renamed to packages/fxa-auth-server/jest.setup-resolve.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
/**
6-
* Fix for proxyquire not finding .ts files under Jest/ts-jest.
7-
* proxyquire uses resolve.sync() which defaults to only .js extensions.
6+
* Fix for module resolution not finding .ts files under Jest/ts-jest.
7+
* resolve.sync() defaults to only .js extensions, which breaks jest.mock()
8+
* for modules that resolve to .ts index files (e.g. fxa-shared/db/models/auth).
89
* This patches resolve.sync to also look for .ts files.
910
*/
1011

1112
const resolve = require('resolve');
1213
const originalSync = resolve.sync;
13-
resolve.sync = function(id, opts) {
14+
resolve.sync = function (id, opts) {
1415
opts = opts || {};
1516
if (!opts.extensions || opts.extensions.length === 0) {
1617
opts.extensions = ['.ts', '.tsx', '.js', '.json', '.node'];

0 commit comments

Comments
 (0)