Skip to content

fix(test): add moduleNameMapper for @smithy/core subpath exports#1167

Open
davidhessler wants to merge 2 commits into
cdklabs:mainfrom
davidhessler:fix/jest-smithy-subpath-exports
Open

fix(test): add moduleNameMapper for @smithy/core subpath exports#1167
davidhessler wants to merge 2 commits into
cdklabs:mainfrom
davidhessler:fix/jest-smithy-subpath-exports

Conversation

@davidhessler

Copy link
Copy Markdown
Contributor

Problem

The dependency upgrade in #1166 (@aws-sdk/client-codedeploy 3.1045.0 → 3.1053.0) pulls in @smithy/core@3.24.3 which uses self-referencing subpath exports. For example, @smithy/core/protocols requires @smithy/core/schema internally.

Jest's module resolver (with ts-jest/CommonJS) does not properly handle these self-referencing package exports, causing schema.TypeRegistry to be undefined when the HttpProtocol constructor runs:

TypeError: Cannot read properties of undefined (reading 'for')
  at new HttpProtocol (node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js:121:59)
  at new CodeDeployClient

This breaks all tests that instantiate CodeDeployClient (19 of 39 tests fail).

Fix

Add moduleNameMapper entries in .projenrc.tsjestOptions.jestConfig to explicitly resolve @smithy/core/* and @aws-sdk/core/* subpath imports to their CJS entry points:

moduleNameMapper: {
  '^@smithy/core/(.*)$': '<rootDir>/node_modules/@smithy/core/dist-cjs/submodules/$1/index.js',
  '^@aws-sdk/core/(.*)$': '<rootDir>/node_modules/@aws-sdk/core/dist-cjs/submodules/$1/index.js',
},

Verification

All 39 tests pass after this change. This unblocks #1166.

Related

  • Fixes build failure in fix(deps): upgrade dependencies #1166
  • Upstream issue: aws-sdk-client-mock v4.1.0 doesn't yet handle the new protocol-based client architecture in @smithy/core 3.24.x

github-actions Bot and others added 2 commits May 25, 2026 18:33
Upgrades project dependencies. See details in [workflow run].

[Workflow Run]: https://github.com/cdklabs/cdk-ecs-codedeploy/actions/runs/26414586495

------

*Automatically created by projen via the "upgrade-main" workflow*

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@aws-sdk/client-codedeploy@3.1053.0 pulls in @smithy/core@3.24.3 which
uses self-referencing subpath exports (e.g. @smithy/core/protocols
requires @smithy/core/schema). Jest's module resolver does not properly
handle these self-references with ts-jest/CommonJS, causing
schema.TypeRegistry to be undefined in the HttpProtocol constructor.

Add moduleNameMapper entries for @smithy/core/* and @aws-sdk/core/*
subpath exports to resolve them directly to their CJS entry points.

This fixes all 39 test failures introduced by the dependency upgrade.
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.

1 participant