-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Jest fails to import detectors when testing in NodeJS #140
Comments
Hi @phil714, I think this is still the same issue as described here: I'm no jest user, so I don't really know how to start investigating this. As a workaround you could enable the |
Hi, Thank you for the quick response. I've tried upgrading all our Jest-related librairies to the latest version and the issue seems to remain. I have looked at some issues linked in your other comments and like you said, (from what I understood) it doesn't look like their library support ESM resolution. It look like they are working on it but it might take a while. jestjs/jest#9430 I think for now I'll follow your advice of adding the flag and removing the detector from my util file. If you still think this is worth investigating on your side, I can make a small test repository with the problem. |
Would be great if you could provide me with an example repo, so I can take a look at how easy or hard it is to fix it 😊 |
Here goes @ivanhofer https://github.com/phil714/stunning-octo-chainsaw-jest-typesafe-i18n-test. I've manage to reproduce it with minimal configuration. You should just have to install everything doing |
@phil714 thanks for the repo! I will take a deeper look when I find some time :) |
Not sure whether this is the same issue I had with // jest.config.js
module.exports = {
preset: "ts-jest",
testEnvironment: "jsdom",
transformIgnorePatterns: ["node_modules"],
setupFilesAfterEnv: ["<rootDir>/setupTests.ts"],
moduleNameMapper: {
"typesafe-i18n/adapters/(.*)": "typesafe-i18n/adapters/$1.cjs",
"typesafe-i18n/detectors": "typesafe-i18n/detectors/index.cjs",
},
}; Hope this helps. |
@thanoskrg thanks for sharing your solution 👍 |
@phil714 I just tested the |
I have added a troubleshoot section to the docs: https://github.com/ivanhofer/typesafe-i18n#tests-are-not-running-with-jest |
Describe the bug
Hi,
I've been trying to run my test since I added
typesafe-i18n
to my backend but I've been running into a problem. While testing manually to see if the translations were working right, everything seems to be working well but while running the tests, my tests that were testing files that used the translation were failing. It seems to fail to import the detectors in the utils file and causing everything else to fail.Reproduction
Logs
Config
Additional information
I'm on MacOS and using NodeJS 16.9.0 and we're using Jest 27.0.4 & cross-env 7.0.3 for the project.
I also tried adding
typesafe-i18n --no-watch &&
in front of my test command to generate the translations before the tests but with no result. My suspicion is that there is a problem with how the subdirectory is imported (or setup on your side, I'm not really sure) because it fails at the line where the detector is imported but not the one where the i18nString, i18nObject function are imported.We also added a small wrapper around
i18nObject
which is why it's going through src/i18n/index.ts.We don't use the detector but we can't remove this particular code because it is generated each time. I'm a bit at a lost on what to do honestly so if you have any ideas on what can causes this, let me know.
The text was updated successfully, but these errors were encountered: