From 5d0b4672fd8182ee3743008e71f8fbf8cf74efde Mon Sep 17 00:00:00 2001 From: Pascal Reitermann Date: Fri, 20 Nov 2026 08:36:15 +0000 Subject: [PATCH] refactor(test): import Mocha as default export 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 Claude-Session: https://claude.ai/code/session_01Jdb5is9YsMnteaxHryN26M --- src/test/suite/index.ts | 2 +- tsconfig.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index 70d8e7b..dd50fa5 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -1,7 +1,7 @@ import { join, resolve} from "path" import { sync } from "glob" -import * as Mocha from "mocha" +import Mocha from "mocha" // nyc ships no type definitions, so it cannot be imported with an import statement // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires diff --git a/tsconfig.json b/tsconfig.json index 198cad2..b105c7a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,8 @@ ], "sourceMap": true, "rootDir": "src", - "strict": true /* enable all strict type-checking options */ + "strict": true, /* enable all strict type-checking options */ + "esModuleInterop": true /* Additional Checks */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */