Skip to content

fix: Stop importing the generated test-utils barrel from two wrappers - #4949

Merged
gethinwebster merged 2 commits into
cloudscape-design:mainfrom
TrevorBurnham:fix-test-utils-barrel-imports
Sep 3, 2026
Merged

fix: Stop importing the generated test-utils barrel from two wrappers#4949
gethinwebster merged 2 commits into
cloudscape-design:mainfrom
TrevorBurnham:fix-test-utils-barrel-imports

Conversation

@TrevorBurnham

@TrevorBurnham TrevorBurnham commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

While working on #4948, I noticed that the ban-files rule defined in the build-tools repo has a bug that's causing it to miss two existing violations in this repo. This PR fixes those violations, before I fix the rule itself.

The violation

src/test-utils/dom/index.ts imports every component wrapper. A wrapper importing it back is therefore circular, which is what ban-files is configured to prevent. The two import createWrapper from '../index.js' lines removed by this PR should have triggered a rule violation like this:

Do not import from the augmented ElementWrapper barrel 'src/test-utils/dom/index.ts'.
Use @cloudscape-design/test-utils-core/dom instead.

The reason they didn't trigger it is that they include the .js extension, which ban-files doesn't expect. The rule only probed extensions appended to the literal path, so it tested src/test-utils/dom/index.js and src/test-utils/dom/index.js.ts rather than matching the banned src/test-utils/dom/index.ts.

The fix

@cloudscape-design/test-utils-core already exports createWrapper from both its /dom and /selectors entry points, and its implementation is the same one the generated barrel copies:

// test-utils-core/dom            // the generated barrel
createWrapper(root = document.body)   wrapper(root: Element = document.body)

So swapping the import is behaviour-identical, and the call sites are untouched. Importing from test-utils-core/dom also means the selectors converter rewrites the path to /selectors for free, so the generated selectors output stops importing its barrel too.

@TrevorBurnham
TrevorBurnham marked this pull request as ready for review August 30, 2026 15:30
@TrevorBurnham
TrevorBurnham requested a review from a team as a code owner August 30, 2026 15:30
@TrevorBurnham
TrevorBurnham requested review from gethinwebster and removed request for a team August 30, 2026 15:30
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 August 31, 2026 06:04 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 August 31, 2026 06:04 Inactive
gethinwebster
gethinwebster previously approved these changes Aug 31, 2026
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 August 31, 2026 08:07 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 August 31, 2026 08:07 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 August 31, 2026 12:36 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 August 31, 2026 12:37 Inactive
@SpyZzey
SpyZzey force-pushed the fix-test-utils-barrel-imports branch from 73eedb5 to 834d76b Compare August 31, 2026 13:19
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 August 31, 2026 13:33 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 August 31, 2026 13:34 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 September 1, 2026 08:33 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 September 1, 2026 08:34 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 September 1, 2026 12:11 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 September 1, 2026 12:12 Inactive
@SpyZzey
SpyZzey force-pushed the fix-test-utils-barrel-imports branch from 5db3603 to 98dba76 Compare September 2, 2026 09:37
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 September 2, 2026 10:15 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 September 2, 2026 10:16 Inactive
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.76%. Comparing base (dec0201) to head (e005fcd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4949      +/-   ##
==========================================
- Coverage   97.66%   93.76%   -3.91%     
==========================================
  Files         959      958       -1     
  Lines       31342    27136    -4206     
  Branches    11577     9761    -1816     
==========================================
- Hits        30611    25443    -5168     
+ Misses        724      613     -111     
- Partials        7     1080    +1073     

☔ 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.

TrevorBurnham and others added 2 commits September 3, 2026 11:10
`src/test-utils/dom/index.ts` is generated and gitignored, and it imports every
component wrapper, so a wrapper importing it back is circular. `ban-files`
already bans it, and these two files are the only importers left.

They escaped the ban by writing `'../index.js'` rather than `'../index'`. The
rule resolves a specifier against the files on disk and only probed extensions
appended to the literal path, so `src/test-utils/dom/index.js` and
`index.js.ts` never matched the banned `src/test-utils/dom/index.ts`.

`@cloudscape-design/test-utils-core` exports `createWrapper` from both its `/dom`
and `/selectors` entry points, with the same implementation the generated barrel
copies, so this is behaviour-identical in both variants. Importing it from
`test-utils-core/dom` also lets the selectors converter rewrite the path, which
drops the barrel import from the generated selectors output as well.

547 test-utils tests pass with 3 unchanged snapshots, plus 165 popover and
button-group tests. Lint is unchanged at 0 errors.
@gethinwebster
gethinwebster added this pull request to the merge queue Sep 3, 2026
Merged via the queue into cloudscape-design:main with commit cbb9292 Sep 3, 2026
52 checks passed
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.

3 participants