Skip to content

Commit be1a521

Browse files
jermnelsonclaude
andcommitted
Fix test failures caused by @smithy/core v3 circular dependency
@smithy/core v3.x introduced sub-path exports (/schema, /protocols, etc.) with circular dependencies that break Jest 27's module system. When aws.js is loaded (directly or via app.js), it initializes all 5 AWS SDK clients at module level; any unmocked client triggers the cycle, leaving schema undefined and crashing with "Cannot read properties of undefined (reading 'for')". Fixes: - Add __tests__/__mocks__/aws.js with jest.fn() stubs for all aws.js exports - Endpoint tests: switch jest.mock("aws.js") to use factory pointing at the manual mock, preventing the real aws.js from loading - AWS unit tests: add stub mocks for each AWS SDK client not under test so none of the real constructors run during module initialization - app.test.js, error.test.js: mock aws.js since they load it via app.js - package.json: add testPathIgnorePatterns to exclude __mocks__/ from test discovery Generated with Claude Sonnet 4.6 (claude-sonnet-4-6) via Claude Code Framework: Jest 27 (babel-jest) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 134b3de commit be1a521

22 files changed

Lines changed: 11637 additions & 167 deletions

__tests__/__mocks__/aws.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const requestMarc = jest.fn()
2+
const hasMarc = jest.fn()
3+
const getMarc = jest.fn()
4+
const listGroups = jest.fn()
5+
const buildAndSendSqsMessage = jest.fn()
6+
const detectLanguage = jest.fn()
7+
8+
module.exports = {
9+
requestMarc,
10+
hasMarc,
11+
getMarc,
12+
listGroups,
13+
buildAndSendSqsMessage,
14+
detectLanguage,
15+
}

__tests__/app.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import request from "supertest"
22
import app from "app.js"
33

44
jest.mock("mongo.js")
5+
jest.mock("aws.js", () => require("./__mocks__/aws.js"))
56

67
describe("GET /", () => {
78
it("returns health check", async () => {

__tests__/aws.cognito.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
} from "@aws-sdk/client-cognito-identity-provider"
77
import { listGroups } from "aws.js"
88

9+
jest.mock("@aws-sdk/client-sqs", () => ({ SQSClient: jest.fn() }))
10+
jest.mock("@aws-sdk/client-s3", () => ({ S3Client: jest.fn() }))
11+
jest.mock("@aws-sdk/client-lambda", () => ({ LambdaClient: jest.fn() }))
12+
jest.mock("@aws-sdk/client-comprehend", () => ({ ComprehendClient: jest.fn() }))
913
jest.mock("@aws-sdk/client-cognito-identity-provider", () => {
1014
const mockCognitoIdentityProviderClient = jest.fn()
1115
const mockPaginateListGroups = jest.fn()

__tests__/aws.comprehend.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import {
55
} from "@aws-sdk/client-comprehend"
66
import { detectLanguage } from "aws.js"
77

8+
jest.mock("@aws-sdk/client-cognito-identity-provider", () => ({
9+
CognitoIdentityProviderClient: jest.fn(),
10+
paginateListGroups: jest.fn(),
11+
}))
12+
jest.mock("@aws-sdk/client-sqs", () => ({ SQSClient: jest.fn() }))
13+
jest.mock("@aws-sdk/client-s3", () => ({ S3Client: jest.fn() }))
14+
jest.mock("@aws-sdk/client-lambda", () => ({ LambdaClient: jest.fn() }))
815
jest.mock("@aws-sdk/client-comprehend", () => {
916
const mockSend = jest.fn()
1017
return {

__tests__/aws.marc.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import {
1111
import { requestMarc, hasMarc, getMarc } from "aws.js"
1212
import { Readable } from "stream"
1313

14+
jest.mock("@aws-sdk/client-cognito-identity-provider", () => ({
15+
CognitoIdentityProviderClient: jest.fn(),
16+
paginateListGroups: jest.fn(),
17+
}))
18+
jest.mock("@aws-sdk/client-sqs", () => ({ SQSClient: jest.fn() }))
19+
jest.mock("@aws-sdk/client-comprehend", () => ({ ComprehendClient: jest.fn() }))
1420
jest.mock("@aws-sdk/client-s3", () => {
1521
const mockSend = jest.fn()
1622
return {

__tests__/aws.sqs.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import {
66
} from "@aws-sdk/client-sqs"
77
import { buildAndSendSqsMessage } from "aws.js"
88

9+
jest.mock("@aws-sdk/client-cognito-identity-provider", () => ({
10+
CognitoIdentityProviderClient: jest.fn(),
11+
paginateListGroups: jest.fn(),
12+
}))
13+
jest.mock("@aws-sdk/client-s3", () => ({ S3Client: jest.fn() }))
14+
jest.mock("@aws-sdk/client-lambda", () => ({ LambdaClient: jest.fn() }))
15+
jest.mock("@aws-sdk/client-comprehend", () => ({ ComprehendClient: jest.fn() }))
916
jest.mock("@aws-sdk/client-sqs", () => {
1017
const mockSend = jest.fn()
1118
return {

__tests__/endpoints/groups.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import request from "supertest"
22
import app from "app.js"
33
import * as aws from "aws.js"
44

5-
jest.mock("aws.js")
5+
jest.mock("aws.js", () => require("../__mocks__/aws.js"))
66

77
describe("GET /groups", () => {
88
const groups = [

__tests__/endpoints/helpers.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import request from "supertest"
22
import app from "app.js"
33
import * as aws from "aws.js"
44

5-
jest.mock("aws.js")
5+
jest.mock("aws.js", () => require("../__mocks__/aws.js"))
66
jest.mock("jwt.js", () => {
77
return {
88
__esModule: true,

__tests__/endpoints/marcGet.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import request from "supertest"
22
import app from "app.js"
33
import * as aws from "aws.js"
44

5-
jest.mock("aws.js")
5+
jest.mock("aws.js", () => require("../__mocks__/aws.js"))
66

77
describe("GET /:resourceId/job/:username/:timestamp", () => {
88
describe("MARC does not exist", () => {

__tests__/endpoints/marcPost.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resource.timestamp = new Date(resource.timestamp)
99
// Multiple files.
1010

1111
jest.mock("mongo.js")
12-
jest.mock("aws.js")
12+
jest.mock("aws.js", () => require("../__mocks__/aws.js"))
1313
jest.mock("jwt.js", () => {
1414
return {
1515
__esModule: true,

0 commit comments

Comments
 (0)