Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Add support for jsconfig/tsconfig paths in next/jest #44553

Closed
Naddiseo opened this issue Jan 4, 2023 · 0 comments · Fixed by #45815
Closed

Add support for jsconfig/tsconfig paths in next/jest #44553

Naddiseo opened this issue Jan 4, 2023 · 0 comments · Fixed by #45815

Comments

@Naddiseo
Copy link

Naddiseo commented Jan 4, 2023

Describe the feature you'd like to request

I'm creating this to re-open #31159. The reproduction of the issue is still present in the with-jest example on the canary branch. If the "moduleNameMapper" section in jest.config.js is removed, jest won't find the "paths" field in tsconfig.json/jsconfig.json and is documented as such in both the example, and in the next testing documentation(ctrl+f "Optional: Absolute Imports and Module Path Aliases")

Describe the solution you'd like

next/jest should automatically fill the the "moduleNameMapper" field if paths if filled out in tsconfig.json.

Describe alternatives you've considered

There's the ts-paths package, and (as linked in #31159) the babel-plugin-module-resolver package. I used a home grown solution that's mostly lifted from the ts-jest

@vercel vercel locked and limited conversation to collaborators Jan 4, 2023
@ijjk ijjk converted this issue into discussion #44554 Jan 4, 2023
timneutkens pushed a commit that referenced this issue Mar 1, 2023
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

# Description

fixes #31159
fixes #44553

Path aliases defined in `tsconfig.json` or `jsconfig.json` are not
automatically configured to work with Jest. This means that these
aliases have to be defined in multiple places.

This PR configures the SWC Jest transform to handle the `baseUrl` and
`paths`, so that users don't need to configure a `moduleNameMapper` for
Jest.

~This PR intends to make the experience more seamless by automatically
configuring Jest's `moduleNameMapper` and `moduleDirectories` based on
the settings in a project's `tsconfig`/`jsconfig`.~

~Users will be able to supply their own configuration for these fields,
if they have use-cases that require manual configuration.~

~The implementation is taken from the [`paths-to-module-name-mapper`
function in
`ts-jest`](https://github.com/kulshekhar/ts-jest/blob/5a0880add0da8d71900eee20c7642e6be65f6a66/src/config/paths-to-module-name-mapper.ts).~

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [x] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant