aspect-build / aspect-build/rules_jest
[Bug]: ability to properly set the `snapshotResolver` under rules_jest
- Dominant language
- Starlark
- Stars
- 24
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
### What happened?
When passing a config that expects the ability to import relative to the root dir (root dir being where the package.json is) this `modulePaths` override is ignored due to rules_jest setting the rootDir relative to the target directory.
To fix this, I have added this workaround locally
`jest.config`
```js
if (!process.env.ROOT_DIR) {
process.env.ROOT_DIR = ''
}
//...
export default {
modulePaths: [process.env.ROOT_DIR],
```
`BUILD.bazel`
```
# Add the below to the jest_test rule
env = {
# rules_jest roots the resolver in the target folder as oppose
# To the top level project folder. This is a hack to reposition
# the root directory so the jest module resolver can find
# other top level folders like "routes/"
"ROOT_DIR": "%s/web/web-app/app" % path_to_workspace_root(),
},
```
### Version
Development (host) and target OS/architectures:
Output of `bazel --version`:
bazel 6.0.0-pre.20221020.1
Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: HEAD
Language(s) and/or frameworks involved:Typescript/SWC
### How to reproduce
```shell
Have a jest.config with the following field
modulePaths: [']
and pass it into the `jest_test` as the `config`
In a test, have a file that `imports` something relative to the root directory like `import {thing} from 'path/to/thing'` where `path/to/thing` is accessible from the root (where the package.json and jest config reside)
```
### Any other information?
_No response_
### Fund our work
- [ ] Sponsor our open source work by donating a [bug bounty](https://opencollective.com/aspect-build/)
Contributor guide
Research direction
Start with the jest.config and BUILD.bazel examples, then inspect how the jest_test rule handles the config and rootDir. Reproduce the modulePaths case with a root-relative import and check whether snapshotResolver can resolve it without the ROOT_DIR workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100