Skip to content

feat(babel-jest): support collecting coverage from .mts, .cts (and other) files#15994

Open
domarmstrong wants to merge 1 commit intojestjs:mainfrom
domarmstrong:istanbul-extension-handling
Open

feat(babel-jest): support collecting coverage from .mts, .cts (and other) files#15994
domarmstrong wants to merge 1 commit intojestjs:mainfrom
domarmstrong:istanbul-extension-handling

Conversation

@domarmstrong
Copy link

Summary

nyc will only collect coverage for files that are located under cwd, and then only files with extensions listed in the extension array.

Istanbul only collects coverage from files listed in the 'extension'. option. If not provided it has a default list of .js, .cjs, .mjs, .ts, .tsx, .jsx. Any other files are ignored. As babel-jest doesn't provide the extension prop, or a way to provide it yourself, there is currently no way to collect coverage from .mts, .cts files. I've proposed adding them to the default Istanbul list. But in the same fashion that Jest removes all exclusions, it could also provide the extension of the file being transformed to allow Istanbul to collect it's coverage.

I can't think of a situation where you would want a file transformed by babel, but not to be instrumented that wouldn't already be handled by jests coverage include/exclude config.

Test plan

I've confirmed it's now possible to collect coverage from .mts files with this change. (Screenshots from use on own codebase)

Before:
Screenshot 2026-03-10 at 12 02 26

After:
Screenshot 2026-03-10 at 12 02 29

@netlify
Copy link

netlify bot commented Mar 10, 2026

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8ca879c
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/69b00fcc7a29e90008cd4035
😎 Deploy Preview https://deploy-preview-15994--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 10, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: domarmstrong / name: Dom Armstrong (8ca879c)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 10, 2026

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15994

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15994

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15994

create-jest

npm i https://pkg.pr.new/create-jest@15994

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15994

expect

npm i https://pkg.pr.new/expect@15994

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15994

jest

npm i https://pkg.pr.new/jest@15994

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15994

jest-circus

npm i https://pkg.pr.new/jest-circus@15994

jest-cli

npm i https://pkg.pr.new/jest-cli@15994

jest-config

npm i https://pkg.pr.new/jest-config@15994

@jest/console

npm i https://pkg.pr.new/@jest/console@15994

@jest/core

npm i https://pkg.pr.new/@jest/core@15994

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15994

jest-diff

npm i https://pkg.pr.new/jest-diff@15994

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15994

jest-each

npm i https://pkg.pr.new/jest-each@15994

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15994

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15994

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15994

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15994

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15994

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15994

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15994

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15994

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15994

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15994

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15994

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15994

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15994

jest-mock

npm i https://pkg.pr.new/jest-mock@15994

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15994

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15994

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15994

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15994

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15994

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15994

jest-runner

npm i https://pkg.pr.new/jest-runner@15994

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15994

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15994

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15994

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15994

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15994

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15994

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15994

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15994

@jest/types

npm i https://pkg.pr.new/@jest/types@15994

jest-util

npm i https://pkg.pr.new/jest-util@15994

jest-validate

npm i https://pkg.pr.new/jest-validate@15994

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15994

jest-worker

npm i https://pkg.pr.new/jest-worker@15994

pretty-format

npm i https://pkg.pr.new/pretty-format@15994

commit: 98b4f69

Istanbul only collects coverage from files listed in 'extension'. It has a [default list](https://github.com/istanbuljs/schema/blob/master/default-extension.js) of
`.js, .cjs, .mjs, .ts, .tsx, .jsx`. Any other files are ignored. As babel-jest doesn't provide the extension, or a way to provide it yourself, there is currently
no way to collect coverage from .mts, .cts files. I've [proposed adding them to the default Istanbul list](istanbuljs/schema#22). But in the
same fashion that Jest removes all exclusions, it could also provide the extension of the file being transformed to allow Istanbul to collect it's coverage.

I can't think of a situation where you would want a file transformed by babel, but not to be instrumented that wouldn't already be handled by jests coverage include/exclude config.
@domarmstrong domarmstrong force-pushed the istanbul-extension-handling branch from 2c23656 to 8ca879c Compare March 10, 2026 12:34
@domarmstrong domarmstrong changed the title Add support for collecting coverage from .mts, .cts (and other) files feat(babel-jest): support collecting coverage from .mts, .cts (and other) files Mar 10, 2026
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