Skip to content

Test: adds 'mocha' and 'chai' as types for tsconfig#22889

Merged
leekelleher merged 1 commit into
mainfrom
v18/bugfix/missing-mocha-types
May 20, 2026
Merged

Test: adds 'mocha' and 'chai' as types for tsconfig#22889
leekelleher merged 1 commit into
mainfrom
v18/bugfix/missing-mocha-types

Conversation

@iOvergaard

Copy link
Copy Markdown
Contributor

Description

This adds 'mocha' and 'chai' as explicit types for the Backoffice Client project in the generated tsconfig.json.

For some reason, the types have changed, and you must explicitly add these. I discovered this fact when I tried to run a base npx tsc in the src/Umbraco.Web.UI.Client folder. It didn't work right out of the box. It is a useful command to run if you want to ensure that the project builds correctly.

Copilot AI review requested due to automatic review settings May 19, 2026 11:10
@iOvergaard iOvergaard added javascript Pull requests that update Javascript code internal labels May 19, 2026
@claude

claude Bot commented May 19, 2026

Copy link
Copy Markdown

Claude finished @iOvergaard's task in 1m 49s —— View job


PR Review

Target: origin/main · Based on commit: 7a993052 · Classified as: Config-only

Adds mocha and chai to the compilerOptions.types array in the root tsconfig so that npx tsc resolves Mocha/Chai globals without relying on implicit @types auto-inclusion.


Suggestions

  • src/Umbraco.Web.UI.Client/devops/tsconfig/index.js:43: tsConfigBase is the ancestor of src/tsconfig.build.json (the production build config, which extends ../tsconfig.json). Adding types: ['mocha', 'chai'] here makes Mocha/Chai globals (describe, it, expect, assert, etc.) available in production TypeScript source files. TypeScript won't flag accidental test-symbol usage in non-test code. A cleaner long-term approach would be a test-only tsconfig override that inherits from the base and adds the types only for test/e2e file patterns — but given the current monolithic tsconfig structure this is a non-trivial refactor and outside this PR's scope.

  • src/Umbraco.Web.UI.Client/devops/tsconfig/index.js:43: Setting types to an explicit list restricts TypeScript to only globally including those two @types packages. If any other @types/* package was previously providing global augmentations relied upon implicitly, those will now be silently dropped. Worth a quick sanity check that nothing else depended on auto-included globals (given the project uses verbatimModuleSyntax: true and explicit imports everywhere, this is likely a non-issue).


Approved with Suggestions for improvement

Good to go, but please carefully consider the importance of the suggestions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds explicit mocha and chai type entries to the Backoffice Client TypeScript configuration so that npx tsc works out of the box in src/Umbraco.Web.UI.Client.

Changes:

  • Add types: ['mocha', 'chai'] to the tsconfig generator (devops/tsconfig/index.js).
  • Regenerate tsconfig.json with the new types entry.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Umbraco.Web.UI.Client/devops/tsconfig/index.js Adds mocha and chai to the types compiler option in the generator.
src/Umbraco.Web.UI.Client/tsconfig.json Regenerated config reflecting the added types array.

@claude claude Bot added the area/frontend label May 19, 2026
@iOvergaard

Copy link
Copy Markdown
Contributor Author

@claude can you check to see why the default @types/*packages won't just work out of the box?

@claude

claude Bot commented May 19, 2026

Copy link
Copy Markdown

Review

This is a clean, minimal fix that makes npx tsc work for the backoffice client. Both the generator (devops/tsconfig/index.js) and the generated file (tsconfig.json) are updated consistently — that's exactly right since the generator is the source of truth.

One thing worth noting

When you set "types": [...] in compilerOptions, TypeScript stops auto-including all @types/* packages and only includes the ones you list. Looking at the installed @types/* packages, there are three: @types/mocha, @types/chai, and @types/eslint__js. The first two are now explicit; the third (@types/eslint__js) is now excluded from global inclusion. Since ESLint types are consumed via tsconfig.node.json (for the build tooling side), this is almost certainly fine — but worth a quick sanity check that ESLint configs still type-check correctly under tsconfig.node.json.

Why this was needed

This is consistent with the @types/chai v5 transition, where Chai moved to proper ES module exports. Ambient/global types that previously auto-loaded now need explicit types entries to be globally available during tsc. The fix is correct.

tsconfig.build.json inherits these types

The build tsconfig (src/tsconfig.build.json) extends the root tsconfig.json and therefore inherits types: ['mocha', 'chai']. This means the TypeScript build for the production bundle has Mocha/Chai globals in scope (even though test files are excluded). In practice this is low-risk since production code is unlikely to accidentally call describe() and still pass review — but a long-term improvement would be moving the test types into a dedicated tsconfig.test.json that extends the base and adding only that to test tooling config. That's a nice-to-have, not a blocker.

Overall: the fix is correct and necessary. Good change. ✅

@leekelleher leekelleher merged commit b9c4c5b into main May 20, 2026
33 checks passed
@leekelleher leekelleher deleted the v18/bugfix/missing-mocha-types branch May 20, 2026 09:59
iOvergaard added a commit that referenced this pull request May 21, 2026
fix(test): adds 'mocha' and 'chai' as types for tsconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants