Skip to content

fix: Add named createWrapper exports - #143

Draft
amanabiy wants to merge 1 commit into
mainfrom
fix/native-esm-create-wrapper
Draft

amanabiy wants to merge 1 commit into
mainfrom
fix/native-esm-create-wrapper

Conversation

@amanabiy

Copy link
Copy Markdown
Member

Description of changes:

Problem: In a native ES module, import createWrapper from '@cloudscape-design/components/test-utils/selectors' gives an object, not the function, so createWrapper() throws TypeError: createWrapper is not a function. The same happens for test-utils/dom.

Root cause: The generated test-utils/{dom,selectors}/index.js files are CommonJS and export the function only as exports.default. When an ES module imports a CommonJS file, Node maps the default import to the whole module.exports object, so the function ends up at createWrapper.default.

Fix: The generated index files also export the function by name:

export { wrapper as createWrapper };

This compiles to exports.createWrapper = wrapper, which Node detects as a named export. ESM code can then write:

import { createWrapper } from '@cloudscape-design/components/test-utils/selectors';

The default export does not change, so existing imports keep working.

How has this been tested?

  • Updated the generator unit test and the generated index snapshots.
  • The generated-test-utils functional tests now import createWrapper by name for both dom and selectors.
  • Compiled the generated dom and selectors index files to CommonJS and imported them from native ESM in Node 22: createWrapper is a function in both.
  • npm run build, npm run lint and npm test (including verify-typescript) pass.

Issue #, if available:

Related: cloudscape-design/components#5261

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.08%. Comparing base (7e82c1e) to head (33dc0c3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #143   +/-   ##
=======================================
  Coverage   97.08%   97.08%           
=======================================
  Files           9        9           
  Lines         343      343           
  Branches       73       73           
=======================================
  Hits          333      333           
  Misses         10       10           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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