这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@pcan
Copy link
Contributor

@pcan pcan commented Dec 21, 2024

I tested the hook in a Typescript project, using Typescript 5.7 (w/tsx), Mocha v.10, Sinon v.17, and most important Chai v.5. Many old CommonJS projects are barred from moving to Chai v.5 if they use nyc for coverage, because Chai v.5 is ESM only. For me moving to c8 is a no-no, because there are cases in which the coverage is not as accurate as istanbul/nyc (tbh I don't remember the exact scenarios, I tested it a while ago).

My working configuration is as follows.

  • "type" : "module" in package.json
  • Mocha config in package.json:
    • "mocha": {
        "require": [
          "./test/register-loader.js",  // this would just register `esm-loader-hook`, see my snippet below.
          "tsx"
        ],
        "color": true,
        "full-trace": true,
        "bail": true,
        "spec": [
          "test/**/*.test.ts"
        ],
        "enable-source-maps": true
      }
  • nyc config in package.json:
    • "nyc": {
        "include": [
          "src/**/*.ts"
        ],
        "reporter": [
          "text-summary",
          "lcov"
        ],
        "sourceMap": true,
        "instrument": true,
        "check-coverage": true,
        "lines": 100,
        "statements": 100,
        "functions": 100,
        "branches": 100
      }
  • ./test/register-loader.js
    • import { register } from "node:module"; 
      import { pathToFileURL } from "node:url"; 
      register("./test/esm-loader-hook-edited.js", pathToFileURL("./"));  // this should point to the library once this PR is merged
  • added "allowSyntheticDefaultImports": true, in tsconfig.json for babel compatibility

With the above, just running npx nyc mocha gives me the correct coverage output, and works with decorators as well.

@bcoe
Copy link
Member

bcoe commented Dec 21, 2024

@pcan looks like you just need to run lint locally.

@pcan
Copy link
Contributor Author

pcan commented Dec 21, 2024

Done! just right now 😄

@pcan
Copy link
Contributor Author

pcan commented Dec 23, 2024

Hi @bcoe, are we good merging this? let me know if there's anything more needed from my side 🙏

@bcoe bcoe merged commit 4c18cf8 into istanbuljs:master Dec 27, 2024
3 checks passed
@bcoe
Copy link
Member

bcoe commented Dec 27, 2024

@pcan published + @istanbuljs/esm-loader-hook@0.3.0, see: #13

Please let me know if you bump into any issues.

@pcan
Copy link
Contributor Author

pcan commented Dec 27, 2024

thanks! 🙏

@pcan pcan deleted the fix/add-ts-support branch January 4, 2025 15:03
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.

2 participants