Description
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
cross-env NODE_ENV=test jest --verbose --maxWorkers=3
Logs
FAIL tests/integration/mutations/productMutation/productCreate.test.ts
● Test suite failed to run
Cannot find module 'typesafe-i18n/detectors' from 'src/i18n/i18n-util.ts'
Require stack:
src/i18n/i18n-util.ts
src/i18n/i18n-node.ts
src/i18n/index.ts
src/graphql/resolvers/auditLogQuery/resolvers.ts
src/graphql/resolvers/query/resolvers.ts
src/graphql/index.ts
tests/helpers/apolloServerHelper.ts
tests/integration/mutations/productMutation/productCreate.test.ts
6 | import type { Translation, TranslationFunctions, Formatters, Locales } from './i18n-types'
7 | import type { LocaleDetector } from 'typesafe-i18n/detectors'
> 8 | import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors'
| ^
9 | import { initFormatters } from './formatters'
10 |
11 | export const baseLocale: Locales = 'en'
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:311:11)
at Object.<anonymous> (src/i18n/i18n-util.ts:8:1)
Config
{
"adapter": "node",
"loadLocalesAsync": false,
"$schema": "https://unpkg.com/typesafe-i18n@2.53.2/schema/typesafe-i18n.json"
}
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.
// src/i18n/index.ts
import { i18nObject } from './i18n-node';
export const LL = i18nObject;
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.