New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add removeJsExtension
to pathsToModuleNameMapper
#3792
feat: add removeJsExtension
to pathsToModuleNameMapper
#3792
Conversation
Would you please configure and add tests to https://github.com/kulshekhar/ts-jest/tree/main/e2e/native-esm-ts and https://github.com/kulshekhar/ts-jest/tree/main/e2e/native-esm-js as well? |
Pull Request Test Coverage Report for Build 2987031218
|
Pull Request Test Coverage Report for Build 3122453706
|
@ahnpnl Well, I want to ask your(and others) opinion(s).
Though I 100% respect the intention for thorough test, I doubt if it's really worth the effort in this case. How do you think? |
I think we can skip this one
This is the current way how e2e test works. When running ts-jest/e2e/native-esm-ts/package.json Line 10 in 912a3d1
For your case, it would be something like // jest.config.js
import { pathsToModuleNameMapper } from '<path_to_index_file_in_build_folder>'
This way we shouldn't do.
Even though this is a pure function but it still can break stuffs which unit tests can't capture. We try to put everything into e2e tests after unit tests to always have more confidence. |
@ahnpnl Thanks for the comment. Would you check the new commits? |
1749456
to
cf8aea6
Compare
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [ts-jest](https://kulshekhar.github.io/ts-jest) ([source](https://github.com/kulshekhar/ts-jest)) | dependencies | major | [`^27.1.2` -> `^29.0.0`](https://renovatebot.com/diffs/npm/ts-jest/27.1.5/29.1.0) | --- ### Release Notes <details> <summary>kulshekhar/ts-jest</summary> ### [`v29.1.0`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2910-httpsgithubcomkulshekharts-jestcomparev2905v2910-2023-03-26) [Compare Source](kulshekhar/ts-jest@v29.0.5...v29.1.0) ##### Features - Support TypeScript 5.x ([#​4064](kulshekhar/ts-jest#4064)) ([db98cc9](kulshekhar/ts-jest@87f2782)), closes [#​4048](kulshekhar/ts-jest#4048) #### [29.0.5](kulshekhar/ts-jest@v29.0.4...v29.0.5) (2023-01-13) ##### Reverts - Revert "fix(transformer): don't use cache when `tsJestConfig` is different ([#​3966](kulshekhar/ts-jest#3966))" ([185eb18](kulshekhar/ts-jest@185eb18)), closes [#​3966](kulshekhar/ts-jest#3966) #### [29.0.4](kulshekhar/ts-jest@v29.0.3...v29.0.4) (2023-01-10) ##### Bug Fixes - **transformer:** don't use cache when `tsJestConfig` is different ([#​3966](kulshekhar/ts-jest#3966)) ([a445638](kulshekhar/ts-jest@a445638)) - bump `json5` to `2.2.3` ([#​3976](kulshekhar/ts-jest#3976)) #### [29.0.3](kulshekhar/ts-jest@v29.0.2...v29.0.3) (2022-09-28) ##### Bug Fixes - merge config from `globals` with transformer config correctly ([#​3842](kulshekhar/ts-jest#3842)) ([9c9fd60](kulshekhar/ts-jest@9c9fd60)), closes [#​3841](kulshekhar/ts-jest#3841) - **presets:** allow merging transform config when using presets ([#​3833](kulshekhar/ts-jest#3833)) ([afc6a94](kulshekhar/ts-jest@afc6a94)) ##### Features - add `useESM` option to `pathsToModuleNameMapper` options ([#​3792](kulshekhar/ts-jest#3792)) ([eabe906](kulshekhar/ts-jest@eabe906)) #### [29.0.2](kulshekhar/ts-jest@v29.0.1...v29.0.2) (2022-09-23) ##### Bug Fixes - mark `ts-jest` as optional in `ConfigGlobals` ([#​3816](kulshekhar/ts-jest#3816)) ([cbb88bb](kulshekhar/ts-jest@cbb88bb)), closes [#​3815](kulshekhar/ts-jest#3815) - use correct typings for `config:init` command ([#​3825](kulshekhar/ts-jest#3825)) ([21b94db](kulshekhar/ts-jest@21b94db)) #### [29.0.2](kulshekhar/ts-jest@v29.0.1...v29.0.2) (2022-09-22) ##### Bug Fixes - mark `ts-jest` as optional in `ConfigGlobals` ([#​3816](kulshekhar/ts-jest#3816)) ([cbb88bb](kulshekhar/ts-jest@cbb88bb)), closes [#​3815](kulshekhar/ts-jest#3815) #### [29.0.1](kulshekhar/ts-jest@v29.0.0...v29.0.1) (2022-09-13) ##### Bug Fixes - **legacy:** include existing globals config in cached config ([#​3803](kulshekhar/ts-jest#3803)) ([e79be47](kulshekhar/ts-jest@e79be47)) ##### Features - add typings for `ts-jest` options via `transform` config ([#​3805](kulshekhar/ts-jest#3805)) ([664b0f2](kulshekhar/ts-jest@664b0f2)) ### [`v29.0.5`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2905-httpsgithubcomkulshekharts-jestcomparev2904v2905-2023-01-13) [Compare Source](kulshekhar/ts-jest@v29.0.4...v29.0.5) ##### Reverts - Revert "fix(transformer): don't use cache when `tsJestConfig` is different ([#​3966](kulshekhar/ts-jest#3966))" ([185eb18](kulshekhar/ts-jest@185eb18)), closes [#​3966](kulshekhar/ts-jest#3966) ### [`v29.0.4`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2904-httpsgithubcomkulshekharts-jestcomparev2903v2904-2023-01-10) [Compare Source](kulshekhar/ts-jest@v29.0.3...v29.0.4) ##### Bug Fixes - **transformer:** don't use cache when `tsJestConfig` is different ([#​3966](kulshekhar/ts-jest#3966)) ([a445638](kulshekhar/ts-jest@a445638)) - bump `json5` to `2.2.3` ([#​3976](kulshekhar/ts-jest#3976)) ### [`v29.0.3`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2903-httpsgithubcomkulshekharts-jestcomparev2902v2903-2022-09-28) [Compare Source](kulshekhar/ts-jest@v29.0.2...v29.0.3) ##### Bug Fixes - merge config from `globals` with transformer config correctly ([#​3842](kulshekhar/ts-jest#3842)) ([9c9fd60](kulshekhar/ts-jest@9c9fd60)), closes [#​3841](kulshekhar/ts-jest#3841) - **presets:** allow merging transform config when using presets ([#​3833](kulshekhar/ts-jest#3833)) ([afc6a94](kulshekhar/ts-jest@afc6a94)) ##### Features - add `useESM` option to `pathsToModuleNameMapper` options ([#​3792](kulshekhar/ts-jest#3792)) ([eabe906](kulshekhar/ts-jest@eabe906)) ### [`v29.0.2`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2902-httpsgithubcomkulshekharts-jestcomparev2901v2902-2022-09-23) [Compare Source](kulshekhar/ts-jest@v29.0.1...v29.0.2) ##### Bug Fixes - mark `ts-jest` as optional in `ConfigGlobals` ([#​3816](kulshekhar/ts-jest#3816)) ([cbb88bb](kulshekhar/ts-jest@cbb88bb)), closes [#​3815](kulshekhar/ts-jest#3815) - use correct typings for `config:init` command ([#​3825](kulshekhar/ts-jest#3825)) ([21b94db](kulshekhar/ts-jest@21b94db)) ### [`v29.0.1`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2901-httpsgithubcomkulshekharts-jestcomparev2900v2901-2022-09-13) [Compare Source](kulshekhar/ts-jest@v29.0.0...v29.0.1) ##### Bug Fixes - **legacy:** include existing globals config in cached config ([#​3803](kulshekhar/ts-jest#3803)) ([e79be47](kulshekhar/ts-jest@e79be47)) ##### Features - add typings for `ts-jest` options via `transform` config ([#​3805](kulshekhar/ts-jest#3805)) ([664b0f2](kulshekhar/ts-jest@664b0f2)) ### [`v29.0.0`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2900-httpsgithubcomkulshekharts-jestcomparev2900-next1v2900-2022-09-08) [Compare Source](kulshekhar/ts-jest@v28.0.8...v29.0.0) ##### Features - drop Node 12 and Node 17 support ([#​3787](kulshekhar/ts-jest#3787)) ([0f1de16](kulshekhar/ts-jest@0f1de16)) - migrate globals config to transformer config ([#​3780](kulshekhar/ts-jest#3780)) ([31e5843](kulshekhar/ts-jest@31e5843)) - support Jest 29 ([#​3767](kulshekhar/ts-jest#3767)) ([94b553b](kulshekhar/ts-jest@94b553b)) ##### DEPRECATIONS - Define `ts-jest` config under `globals` is now deprecated. Please define the config via transformer config instead. ##### BREAKING CHANGES - Only Node 14, 16 and 18 are supported - **Jest 29** is required. ### [`v28.0.8`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2808-httpsgithubcomkulshekharts-jestcomparev2807v2808-2022-08-14) [Compare Source](kulshekhar/ts-jest@v28.0.7...v28.0.8) ##### Bug Fixes - allow `.mts` to be processed ([#​3713](kulshekhar/ts-jest#3713)) ([effae71](kulshekhar/ts-jest@effae71)), closes [#​3702](kulshekhar/ts-jest#3702) ### [`v28.0.7`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2807-httpsgithubcomkulshekharts-jestcomparev2806v2807-2022-07-15) [Compare Source](kulshekhar/ts-jest@v28.0.6...v28.0.7) ##### Bug Fixes - update `@jest/types` to be an optional peer dependency ([#​3690](kulshekhar/ts-jest#3690)) ([8a8c3fa](kulshekhar/ts-jest@8a8c3fa)), closes [#​3689](kulshekhar/ts-jest#3689) ### [`v28.0.6`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2806-httpsgithubcomkulshekharts-jestcomparev2805v2806-2022-07-13) [Compare Source](kulshekhar/ts-jest@v28.0.5...v28.0.6) ##### Bug Fixes - **config:** don't show diagnostics warning with `diagnostics: false` ([#​3647](kulshekhar/ts-jest#3647)) ([9a9bc02](kulshekhar/ts-jest@9a9bc02)), closes [#​3638](kulshekhar/ts-jest#3638) - **legacy:** add `useCaseSensitiveFileNames` wherever needed ([#​3683](kulshekhar/ts-jest#3683)) ([c40bc34](kulshekhar/ts-jest@c40bc34)), closes [#​3665](kulshekhar/ts-jest#3665) - set `@jest/types` as peer dependency ([#​3633](kulshekhar/ts-jest#3633)) ([24567e1](kulshekhar/ts-jest@24567e1)) ### [`v28.0.5`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2805-httpsgithubcomkulshekharts-jestcomparev2804v2805-2022-06-11) [Compare Source](kulshekhar/ts-jest@v28.0.4...v28.0.5) ##### Bug Fixes - **legacy:** throw type check error in ESM mode with `reject` ([#​3618](kulshekhar/ts-jest#3618)) ([7dd01ff](kulshekhar/ts-jest@7dd01ff)), closes [#​3507](kulshekhar/ts-jest#3507) ### [`v28.0.4`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2804-httpsgithubcomkulshekharts-jestcomparev2803v2804-2022-06-02) [Compare Source](kulshekhar/ts-jest@v28.0.3...v28.0.4) ##### Bug Fixes - remove `@types/jest` from peer deps ([#​3592](kulshekhar/ts-jest#3592)) ([b66b656](kulshekhar/ts-jest@b66b656)) ### [`v28.0.3`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2803-httpsgithubcomkulshekharts-jestcomparev2802v2803-2022-05-23) [Compare Source](kulshekhar/ts-jest@v28.0.2...v28.0.3) ##### Bug Fixes - **security:** update version of `json5` ([#​3528](kulshekhar/ts-jest#3528)) ([b31f5ba](kulshekhar/ts-jest@b31f5ba)) ### [`v28.0.2`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2802-httpsgithubcomkulshekharts-jestcomparev2801v2802-2022-05-07) [Compare Source](kulshekhar/ts-jest@v28.0.1...v28.0.2) ##### Bug Fixes - **transformers:** use `Array.sort` in hoisting transformer ([#​3498](kulshekhar/ts-jest#3498)) ([e400a6e](kulshekhar/ts-jest@e400a6e)), closes [#​3476](kulshekhar/ts-jest#3476) ### [`v28.0.1`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2801-httpsgithubcomkulshekharts-jestcomparev2800v2801-2022-05-03) [Compare Source](kulshekhar/ts-jest@v28.0.0...v28.0.1) ##### Bug Fixes - lower the required node version to ^16.10 ([#​3495](kulshekhar/ts-jest#3495)) ([3a4e48a](kulshekhar/ts-jest@3a4e48a)), closes [#​3494](kulshekhar/ts-jest#3494) ### [`v28.0.0`](https://github.com/kulshekhar/ts-jest/blob/HEAD/CHANGELOG.md#​2800-httpsgithubcomkulshekharts-jestcomparev2800-next3v2800-2022-05-02) [Compare Source](kulshekhar/ts-jest@v27.1.5...v28.0.0) ##### Bug Fixes - **legacy** invoke Babel `processAsync` for `babel-jest` in ESM mode instead of `process` ([#​3430](kulshekhar/ts-jest#3430)) ([0d7356c](kulshekhar/ts-jest@0d7356c)) ##### Features - **presets:** add presets for legacy mode ([#​3465](kulshekhar/ts-jest#3465)) ([543b4ad](kulshekhar/ts-jest@543b4ad)) - mark `ConfigSet` as legacy ([#​3456](kulshekhar/ts-jest#3456)) ([a986729](kulshekhar/ts-jest@a986729)) - mark `TsCompiler` and `TsJestCompiler` as legacy ([#​3457](kulshekhar/ts-jest#3457)) ([0f2fe30](kulshekhar/ts-jest@0f2fe30)) - remove `path-mapping` AST transformer ([#​3455](kulshekhar/ts-jest#3455)) ([f566869](kulshekhar/ts-jest@f566869)) - set Jest peer dependencies to v28 ([#​3454](kulshekhar/ts-jest#3454)) ([1e880ff](kulshekhar/ts-jest@1e880ff)) - **core:** drop support for Node.js 10 ([#​3332](kulshekhar/ts-jest#3332)) ([7a9aa61](kulshekhar/ts-jest@7a9aa61)) - **core:** remove `mocked` testing util ([#​3333](kulshekhar/ts-jest#3333)) ([2d9017d](kulshekhar/ts-jest@2d9017d)) - **core:** remove `ts-jest/utils` sub path export ([#​3334](kulshekhar/ts-jest#3334)) ([9f253d3](kulshekhar/ts-jest@9f253d3)) - mark `TsJestTransformer` as legacy ([#​3451](kulshekhar/ts-jest#3451)) ([b090179](kulshekhar/ts-jest@b090179)) ##### BREAKING CHANGES - `path-mapping` AST transformer is no longer shipped in `ts-jest` v28. Please use an alternative one like https://github.com/LeDDGroup/typescript-transform-paths instead. - Any imports `ts-jest/dist/compiler/ts-compiler` should change to `ts-jest/dist/legacy/compiler/ts-compiler` - Any imports `ts-jest/dist/compiler/ts-jest-compiler` should change to `ts-jest/dist/legacy/compiler/ts-jest-compiler` - Any imports `ts-jest/dist/config/config-set` should change to `ts-jest/dist/legacy/config/config-set` - Minimum support `TypeScript` version is now **4.3** since Jest 28 requires it. - **Jest 28** is required. - **core:** Any imports `ts-jest/utils` should be replaced with `ts-jest`. - **core:** Starting from Jest 27.4, `mocked` has been integrated into Jest repo. - **core:** Support for Node.js v10 has been removed as Jest drops support for it. #### [27.1.5](kulshekhar/ts-jest@v27.1.3...v27.1.4) (2022-05-17) ##### Bug Fixes - **transformers** use `Array.sort` in hoisting transformer ([#​3498](kulshekhar/ts-jest#3498)) ([e400a6e](kulshekhar/ts-jest@e400a6e)), fixes [#​3476](kulshekhar/ts-jest#3476) #### [27.1.4](kulshekhar/ts-jest@v27.1.3...v27.1.4) (2022-03-24) ##### Bug Fixes - **compiler:** revert [#​3194](kulshekhar/ts-jest#3194) ([#​3362](kulshekhar/ts-jest#3362)) ([2b7dffe](kulshekhar/ts-jest@2b7dffe)), closes [#​3272](kulshekhar/ts-jest#3272) - remove `esbuild` from peer dependency ([#​3360](kulshekhar/ts-jest#3360)) ([8c8c1ca](kulshekhar/ts-jest@8c8c1ca)), closes [#​3346](kulshekhar/ts-jest#3346) - support Babel config file with `.cjs` extension ([#​3361](kulshekhar/ts-jest#3361)) ([5e5ac4a](kulshekhar/ts-jest@5e5ac4a)), closes [#​3335](kulshekhar/ts-jest#3335) #### [27.1.3](kulshekhar/ts-jest@v27.1.2...v27.1.3) (2022-01-14) ##### Bug Fixes - **compiler:** update memory cache for compiler using received file content ([#​3194](kulshekhar/ts-jest#3194)) ([e4d9541](kulshekhar/ts-jest@e4d9541)) #### [27.1.2](kulshekhar/ts-jest@v27.1.1...v27.1.2) (2021-12-15) ##### Bug Fixes - stimulate `esbuild` type to avoid importing `esbuild` directly ([#​3147](kulshekhar/ts-jest#3147)) ([9ace0a9](kulshekhar/ts-jest@9ace0a9)) #### [27.1.1](kulshekhar/ts-jest@v27.1.0...v27.1.1) (2021-12-07) ##### Bug Fixes - bring back `afterProcess` hook ([#​3132](kulshekhar/ts-jest#3132)) ([2b6b86e](kulshekhar/ts-jest@2b6b86e)) - make `esbuild` as optional peer dependency ([#​3129](kulshekhar/ts-jest#3129)) ([20258de](kulshekhar/ts-jest@20258de)) </details> --- ### Configuration📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC43NC4yIiwidXBkYXRlZEluVmVyIjoiMzQuNzQuMiJ9--> Co-authored-by: Renovate Bot <renovate@vylpes.com> Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/244 Co-authored-by: RenovateBot <renovate@vylpes.com> Co-committed-by: RenovateBot <renovate@vylpes.com>
Summary
ESM requires imported file's extension (e.g.
import foo from './foo.js'
instead ofimport foo from './foo'
).This is also true for typescript modules. They should be imported as
.js
, not.ts
.But jest does not have an "automatic typescript import extension mismatch detection for ESM". Rather, it lets users configure
moduleNameMapper
by themselves.Currently,
pathsToModuleNameMapper
does not support this.Thus, a new option
removeJsExtension
is added.This is not a breaking change.
Test plan
Test code is provided as well.
Does this PR introduce a breaking change?
Other information
Thanks for maintaining ts-jest :)