I had a project on 0.57.7 and upgraded to 0.59.0 for supporting android 64-bit architecture devices and
We resolved the warning like moving testRegex to testMatch
The jest tests stopped working with the following error. We tried to resolve with multiple options & keep getting -
Cannot find module ‘setupDevtools’ from ‘setup.js’.
React Native version:
React Native Environment Info:
System:
OS: macOS 10.14
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Memory: 22.80 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.11.3 - /usr/local/bin/node
Yarn: 1.3.2 - /usr/local/bin/yarn
npm: 5.6.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 26.0.1, 26.0.2, 26.0.3, 27.0.1, 27.0.3, 28.0.2, 28.0.3
System Images: android-23 | Intel x86 Atom, android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-26 | Android TV Intel x86 Atom, android-26 | China version of Android Wear Intel x86 Atom, android-26 | Android Wear Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-26 | Google Play Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-P | Android TV Intel x86 Atom, android-P | China version of Wear OS Intel x86 Atom, android-P | Wear OS Intel x86 Atom, android-P | Google APIs Intel x86 Atom, android-P | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.0 => 0.59.0
npmGlobalPackages:
react-native-cli: 2.0.1
Upgrade RN 0.57.7 project to 0.59.0 version.
Describe what you expected to happen:
Tests to start running - Without getting the Cannot find module ‘setupDevtools’ from ‘setup.js’.*
Jest.config
const tsjPreset = require('ts-jest/jest-preset');
const _ = require('lodash')
module.exports = {
...(_.omit(tsjPreset, 'testMatch')),
"roots": [
"<rootDir>",
"<rootDir>/src/"
],
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"setupFiles": [
"<rootDir>/test/setup.js"
],
"collectCoverageFrom": [
"src/**/*.{ts,tsx}",
"!**/*.d.ts"
],
"coveragePathIgnorePatterns": ["!*.d.ts", "<rootDir>/src/components/Icons/", "<rootDir>/src/containers/navigation/navigators/"],
"watchPathIgnorePatterns": ["<rootDir>/node_modules/", "<rootDir>/coverage/", "<rootDir>/.jest/", "<rootDir>/test/", "<rootDir>/lib/"],
"setupFilesAfterEnv": ["./test/setupFramework.js"],
"moduleNameMapper": {
"~components$": "<rootDir>/src/components/index.ts",
"~setTestId$": "<rootDir>/src/utils/setTestId.ts",
"^[@./a-zA-Z0-9$_-]+\\.(jpg|png|gif)$": "RelativeImageStub"
},
"transform": {
...tsjPreset.transform,
'\\.js$': 'babel-jest'
},
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"testMatch": [
'**/__tests__/**/*.(js|ts|tsx)',
'**/?(*.)+(spec|test).(js|ts|tsx)',
],
"testPathIgnorePatterns": [
"\\.snap$",
"<rootDir>/node_modules/",
"<rootDir>/lib/"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-native-animatable|react-navigation|@react-navigation|react-native-vector-icons|react-native-fetch-blob|lottie-react-native)"
],
"testURL": "http://localhost:8081",
"coverageThreshold": {
"global": {
"branches": 45,
"functions": 47,
"lines": 67,
"statements": 66
}
},
"globals": {
'ts-jest': {
"babelConfig": true,
"diagnostics": false
}
},
"testResultsProcessor": "jest-sonar-reporter",
"cacheDirectory": ".jest/cache"
}
It looks like you are using an older version of React Native. Please update to the latest release, v0.60 and verify if the issue still exists.
react-native info on a project using the latest release.
Even bumped version to the 0.60.4 which is the latest stable version. It can't be found module 'warnOnce' from 'react-native-implementation.js' while running the unit tests. Keep looking on this to fix it.
We are facing the same issue in our App
if i remove the
import =is not supported by @babel/plugin-transform-typescript
Please consider usingimport <moduleName> from '<moduleName>';alongside Typescript's --allowSyntheticDefaultImports option.
The alias name type -import * as <moduleName> from '<moduleName>'is stopped working in new babel. you have to change it like import <moduleName> from '<moduleName>' after upgrade the your moudule dependencies.