jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: Custom `testEnvironment` in TypeScript is not transformed with ESM

Open ahnpnl opened this issue 1 year ago • 4 comments

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

ahnpnl avatar Aug 19 '24 22:08 ahnpnl

@SimenB if you can shine me a bit how to fix it, I can make a PR :)

ahnpnl avatar Aug 20 '24 09:08 ahnpnl

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.

kenmuse avatar Aug 25 '24 19:08 kenmuse

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.

github-actions[bot] avatar Sep 24 '24 20:09 github-actions[bot]

Issue is still present

kenmuse avatar Oct 19 '24 16:10 kenmuse

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.

github-actions[bot] avatar Nov 18 '24 17:11 github-actions[bot]

Still an issue.

craigcrawfordcts avatar Dec 13 '24 11:12 craigcrawfordcts

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.

github-actions[bot] avatar Jan 12 '25 13:01 github-actions[bot]

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.

github-actions[bot] avatar Feb 11 '25 13:02 github-actions[bot]

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.

github-actions[bot] avatar Feb 11 '25 13:02 github-actions[bot]

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.

github-actions[bot] avatar Mar 14 '25 00:03 github-actions[bot]