[Bug]: Custom `testEnvironment` in TypeScript is not transformed with ESM
Version
29.7.0
Steps to reproduce
Original reported at https://github.com/kulshekhar/ts-jest/issues/4195
Expected behavior
The custom testEnvironment in TypeScript should be passed to processAsync so ts-jest can properly transform it
Actual behavior
Debugging ts-jest and I found out that the custom testEnvironment in TypeScript is passed to process instead of processAsync. This makes ts-jest to transform into CJS.
Additional context
The issue is with this line https://github.com/jestjs/jest/blob/4e56991693da7cd4c3730dc3579a1dd1403ee630/packages/jest-runner/src/runTest.ts#L109
Environment
System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M3 Pro
Binaries:
Node: 20.16.0 - /opt/homebrew/opt/nvm/versions/node/v20.16.0/bin/node
Yarn: 1.22.22 - /opt/homebrew/opt/nvm/versions/node/v20.16.0/bin/yarn
npm: 10.8.1 - /opt/homebrew/opt/nvm/versions/node/v20.16.0/bin/npm
pnpm: 9.5.0 - /opt/homebrew/opt/nvm/versions/node/v20.16.0/bin/pnpm
npmPackages:
jest: ^29.7.0 => 29.7.0
@SimenB if you can shine me a bit how to fix it, I can make a PR :)
I think I see the same path @ahnpnl is referencing. I've had the same issue.
The code he references is called to load the TestEnvironment and then calls this:
https://github.com/jestjs/jest/blob/4e56991693da7cd4c3730dc3579a1dd1403ee630/packages/jest-transform/src/ScriptTransformer.ts#L773
That ultimately calls back to:
https://github.com/jestjs/jest/blob/4e56991693da7cd4c3730dc3579a1dd1403ee630/packages/jest-transform/src/ScriptTransformer.ts#L792
Which ultimately calls process:
https://github.com/jestjs/jest/blob/4e56991693da7cd4c3730dc3579a1dd1403ee630/packages/jest-transform/src/ScriptTransformer.ts#L516
Although there is a check during loadTransformers to ensure that the transformer exposes process or processAsync to make sure it's valid, I'm not seeing a path through the code which would call processAsync for this case.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Issue is still present
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Still an issue.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.