Test suite failed to run #1837
Replies: 1 comment
-
|
the error is because jest doesnt understand jsx/tsx or esm syntax out of the box. in a monorepo with react native, you need proper babel and jest config. here is what to check:
if you share your babel.config.js and jest.config.js i can give more specific help. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
We are currently developing a platform in the tourism and travel sector. We created a monorepo with TurboRepo for the frontend of our mobile and web applications using React/React Native/Next.js. I would like to develop a shared package of UI components for the different applications. I have installed the necessary packages for testing and developing the UI components and configured them as indicated in the examples folder (link) of @testing-library/react-native. However, I can't run the tests; I keep getting the same error. I've tried various strategies, but none of them work. I even sought help from AI like Claude and GPT, but with no results. There's surely something I haven't understood in the installation and configuration of the different packages, so if someone could take a look, that would be great.
Here is the error I get when I run my tests:
turbo test
turbo 2.6.3
• Packages in scope: @sychus/ui
• Running test in 1 packages
• Remote caching disabled
┌─ @sychus/ui#test > cache miss, executing 34b0bb5ddd8392de
FAIL tests/hello.test.tsx
● Test suite failed to run
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.092 s
Ran all test suites.
ELIFECYCLE Test failed. See above for more details.
command finished with error: command (/home/ali/Projets/tutorials/monorepo/packages/ui) /home/ali/.nvm/versions/node/v2
4.1.0/bin/pnpm run test exited (1)
└─ @sychus/ui#test ──
@sychus/ui#test: command (/home/ali/Projets/tutorials/monorepo/packages/ui) /home/ali/.nvm/versions/node/v24.1.0/bin/pnpm run test exited (1)
Tasks: 0 successful, 1 total
Cached: 0 cached, 1 total
Time: 2.244s
Failed: @sychus/ui#test
ERROR run failed: command exited (1)
The package folder structure:
`./packages/ui/
├── babel.config.js
├── eslint.config.mjs
├── jest.config.js
├── jest-setup.ts
├── node_modules
│ ├── @babel
│ │ └── core -> ../../../../node_modules/.pnpm/@babel[email protected]/node_modules/@babel/core
│ ├── @callstack
│ │ └── eslint-config -> ../../../../node_modules/.pnpm/@callstack+eslint-config@15.0.0_@types[email protected][email protected]_jest@30.2.0_@types[email protected][email protected]/node_modules/@callstack/eslint-config
│ ├── @eslint
│ │ ├── eslintrc -> ../../../../node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc
│ │ └── js -> ../../../../node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/js
│ ├── eslint -> ../../../node_modules/.pnpm/[email protected]/node_modules/eslint
│ ├── eslint-plugin-testing-library -> ../../../node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/eslint-plugin-testing-library
│ ├── expo -> ../../../node_modules/.pnpm/expo@54.0.30_@babel[email protected]_react-native@0.81.5_@babel+core@7.28.5_@types[email protected][email protected][email protected]/node_modules/expo
│ ├── jest -> ../../../node_modules/.pnpm/jest@30.2.0_@types[email protected]/node_modules/jest
│ ├── react -> ../../../node_modules/.pnpm/[email protected]/node_modules/react
│ ├── react-dom -> ../../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom
│ ├── react-native -> ../../../node_modules/.pnpm/react-native@0.81.5_@babel+core@7.28.5_@types[email protected][email protected]/node_modules/react-native
│ ├── react-native-web -> ../../../node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/react-native-web
│ ├── react-test-renderer -> ../../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-test-renderer
│ ├── @testing-library
│ │ └── react-native -> ../../../../node_modules/.pnpm/@testing-library[email protected]_jest@30.2.0_@types[email protected][email protected]._943e4cf54da94787e2394f0e2a4fd585/node_modules/@testing-library/react-native
│ ├── @types
│ │ ├── eslint -> ../../../../node_modules/.pnpm/@types[email protected]/node_modules/@types/eslint
│ │ ├── jest -> ../../../../node_modules/.pnpm/@types[email protected]/node_modules/@types/jest
│ │ └── react -> ../../../../node_modules/.pnpm/@types[email protected]/node_modules/@types/react
│ └── typescript -> ../../../node_modules/.pnpm/[email protected]/node_modules/typescript
├── package.json
├── README.md
├── tests
│ └── hello.test.tsx
└── tsconfig.json
26 directories, 8 files
`
babel.config.js :
module.exports = function (api) { api.cache(true); return { presets: ["babel-preset-expo"], }; };eslint.config.mjs :
module.exports = function (api) { api.cache(true); return { presets: ["babel-preset-expo"], }; };jest.config.js:
module.exports = { preset: "react-native", moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"], transformIgnorePatterns: [ "node_modules/(?!(jest-)?react-native|@react-native(-community)?)", ], setupFilesAfterEnv: ["./jest-setup.ts"], };package.json:
{ "name": "@sychus/ui", "version": "0.0.1", "keywords": [], "license": "SEE LICENSE IN LICENSE", "private": true, "scripts": { "dev": "echo 'do nothing'", "build": "", "lint": "eslint .", "check-types": "tsc --noEmit", "test": "jest" }, "dependencies": { "expo": "catalog:", "react": "catalog:", "react-dom": "catalog:", "react-native": "catalog:", "react-native-web": "catalog:", "@callstack/eslint-config": "^15.0.0" }, "devDependencies": { "@babel/core": "catalog:", "@eslint/eslintrc": "^3.3.3", "@eslint/js": "^9.39.2", "@testing-library/react-native": "catalog:", "@types/eslint": "catalog:", "@types/jest": "catalog:", "@types/react": "catalog:", "eslint": "catalog:", "eslint-plugin-testing-library": "catalog:", "jest": "catalog:", "react-test-renderer": "catalog:", "typescript": "catalog:" } }tsconfig.json:
{ "extends": "expo/tsconfig.base", "compilerOptions": { "strict": true, "allowJs": false } }pnpm-worspace.yaml:
packages:
catalog:
'@babel/core': latest
'@testing-library/react-native': latest
'@types/eslint': latest
'@types/jest': latest
'@types/react': latest
eslint: latest
expo: latest
jest: latest
react: "19.1"
react-dom: "19.1"
react-native: "0.81.5"
react-native-web: latest
react-test-renderer: "19.1"
tamagui: latest
typescript: latest
eslint-plugin-testing-library: latest
Is it possible that this is a versioning issue?
Beta Was this translation helpful? Give feedback.
All reactions