You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
# 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
Have a jest.config with the following field
modulePaths: ['<rootDir'>]
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
The text was updated successfully, but these errors were encountered:
Aghassi
changed the title
[Bug]: ability to properly set the rootDir under rules_jest
[Bug]: ability to properly set the snapshotResolver under rules_jest
Apr 26, 2023
I spoke with @gregmagolan about this and I actually think the problem I'm running into is how the snapshotResolver specifically is resolved. The logic resides here
The assumption is that the config will be relative to the snapshot resolver, but between bazel test and bazel run the path from which the runner gets the resolver file is different. The only guaranteed fix I think locally is to do path.resolve(__dirname, 'snapshotResolver.cjs') when passing in the custom snapshot resolver. However, I still have issues with the bazel run command as it just hangs. I assume there is an error not bubbling up.
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
BUILD.bazel
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
orMODULE.bazel
file: HEADLanguage(s) and/or frameworks involved:Typescript/SWC
How to reproduce
Any other information?
No response
Fund our work
The text was updated successfully, but these errors were encountered: