Skip to content

refactor(test): import Mocha as default export - #329

Merged
pascalre merged 1 commit into
masterfrom
feat/mocha-default-import
Nov 20, 2026
Merged

pascalre merged 1 commit into
masterfrom
feat/mocha-default-import

Conversation

@pascalre

Copy link
Copy Markdown
Owner

What changed

  • src/test/suite/index.ts: import * as Mocha from "mocha" replaced by import Mocha from "mocha".
  • tsconfig.json: enabled esModuleInterop.

Why

DeepSource reported "Explicitly import the specific method needed" for the namespace import introduced in #328. A named import is not possible because @types/mocha declares the module with export = Mocha.

With esModuleInterop, the generated __importDefault helper returns the module's default export if it is an ES module namespace, and the module itself otherwise. The runner therefore works whether VS Code loads mocha 12 as ES module (as Node 22 does) or as its CommonJS build. The previous new Mocha() on the result of require() only worked for the latter.

Testing

  • Compared all compiled files in out/ before and after: only out/test/suite/index.js differs, so esModuleInterop has no effect on the extension code.
  • Verified the helper with both shapes of the mocha module (ES module namespace and CommonJS class): both construct a working Mocha instance.
  • tsc, eslint, dependency-cruiser and 207 tests pass locally.
  • CI is the relevant check here: this file starts the Electron test suite.

Generated by Claude Code

DeepSource reported "Explicitly import the specific method needed" for
the namespace import `import * as Mocha from "mocha"` in the test
runner. A named import is not possible, because @types/mocha declares
the module with `export = Mocha`.

Import the class as default export and enable esModuleInterop. The
generated helper returns the module's default export if it is an ES
module namespace and the module itself otherwise, so the runner works
whether VS Code loads mocha 12 as ES module (as Node 22 does) or as
its CommonJS build. The previous `new Mocha()` on the result of
require() only worked for the latter.

esModuleInterop changes no other compiled file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jdb5is9YsMnteaxHryN26M
@pascalre
pascalre merged commit 0cfc4e4 into master Nov 20, 2026
6 of 7 checks passed
@pascalre
pascalre deleted the feat/mocha-default-import branch November 20, 2026 08:45
@sonarqubecloud

Copy link
Copy Markdown

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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