I'm trying to get Jest working with the TypeORM Expo-Example project
I've done a lot to try to get either ts-jest as well as expo-jest working. I have followed official guides for both Jest and Expo Jest. I was able to expo init a new empty project (not the TypeORM example) and get Expo-Jest working as expected, but when I to apply the changes to the TypeORM expo project, it ran into issues.
I think expo-jest is preferred. It will probably be easier to start from a clean clone of the TypeORM Expo-Example repo.
I've edited the package.json to a version that shouldn't have dependency issues if it is an easier starting point. (the jest stuff can be modified or removed in favor of separate config)
{
"name": "expo-example",
"version": "0.1.0",
"private": true,
"devDependencies": {
"#babel/core": "^7.18.0",
"#babel/preset-env": "^7.18.0",
"#types/jest": "^27.5.1",
"#types/node": "^10.1.3",
"#types/react": "~17.0.21",
"#types/react-native": "~0.67.6",
"#types/react-test-renderer": "^16.0.1",
"babel-plugin-transform-typescript-metadata": "^0.3.2",
"jest": "27",
"jest-expo": "^45.0.1",
"react-native-typescript-transformer": "^1.2.9",
"react-test-renderer": "17",
"typescript": "^4.6.4"
},
"scripts": {
"start": "expo start --dev-client",
"eject": "expo eject",
"android": "expo run:android",
"ios": "expo run:ios",
"test": "jest",
"postinstall": "patch-package"
},
"jest": {
"preset": "jest-expo",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"\\.snap$",
"<rootDir>/node_modules/"
],
"cacheDirectory": ".jest/cache",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|#react-native(-community)?)|expo(nent)?|#expo(nent)?/.*|#expo-google-fonts/.*|react-navigation|#react-navigation/.*|#unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)"
]
},
"dependencies": {
"babel-jest": "27",
"expo": "^45.0.0",
"expo-splash-screen": "~0.15.1",
"expo-sqlite": "~10.2.0",
"expo-status-bar": "~1.3.0",
"patch-package": "^6.4.7",
"postinstall-postinstall": "^2.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.1",
"react-native-sqlite-storage": "^4.1.0",
"react-native-web": "0.17.7",
"reflect-metadata": "^0.1.13",
"ts-jest": "27",
"tslib": "^1.9.1",
"typeorm": "^0.3.6"
}
}
I have the same issue, my problem is an error when i try test the return of getConnection() typeorm function or DataSource({...}).initialize() with expo-sqlite driver... to make it work i use slite3 lib instead expo-sqlite... so it work, see: https://github.com/EmanuelVogt/expo-sqlite-typeorm-jest
Related
I'm testing a React Native app.
I run jest --coverage and I get 233 files:
I still get the coverage file and I can see the coverage through index.html.
But why the other files.
Here is the package.json
{
"name": "entoutonika",
"version": "0.0.1",
"private": true,
"scripts": {
"8": "react-native run-ios --simulator=\"iPhone 8 Plus\" ",
"11": "react-native run-ios --simulator=\"iPhone 11 Pro Max\" ",
"ios": "react-native run-ios",
"and": "react-native run-android",
"se": "react-native run-ios --simulator=\"iPhone SE (2nd generation)\" ",
"ipad13": "react-native run-ios --simulator=\"iPad Pro (12.9-inch) (5th generation)\" ",
"air": "react-native run-ios --simulator=\"iPad Air (4th generation)\" ",
"start": "react-native start",
"test": "jest --runInBand --detectOpenHandles --forceExit",
"watch": "jest --watch",
"cov": "jest --coverage",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"typecheck": "npx tsc",
"checkformat": "prettier --check \"**/*.{js,jsx,ts,tsx,json}\"",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json}\"",
"prepare": "npm run typecheck && lint-staged && husky install",
"postinstall": "npx typesync"
},
"dependencies": {
"#react-native-community/async-storage": "^1.12.1",
"#react-native-community/netinfo": "^7.1.9",
"#react-navigation/drawer": "^6.1.8",
"#react-navigation/elements": "^1.2.1",
"#react-navigation/native": "^6.0.6",
"#react-navigation/native-stack": "^6.2.5",
"firebase": "^9.4.1",
"formik": "^2.2.9",
"lottie-react-native": "^4.1.3",
"moment": "^2.29.1",
"react": "17.0.2",
"react-native": "0.66.1",
"react-native-bootsplash": "^4.0.2",
"react-native-code-push": "^7.0.4",
"react-native-gesture-handler": "^1.10.3",
"react-native-image-picker": "^4.3.0",
"react-native-reanimated": "^2.2.3",
"react-native-safe-area-context": "^3.3.2",
"react-native-screens": "^3.10.1",
"react-native-sound": "^0.11.1",
"react-native-vector-icons": "^9.0.0",
"react-redux": "^7.2.5",
"redux": "^4.1.1",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0",
"typescript": "^4.4.4",
"yup": "^0.32.11"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#babel/preset-typescript": "^7.16.7",
"#babel/runtime": "^7.12.5",
"#react-native-community/eslint-config": "^2.0.0",
"#testing-library/jest-native": "^4.0.4",
"#testing-library/react": "^12.1.2",
"#testing-library/react-native": "^9.0.0",
"#types/babel__core": "^7.1.16",
"#types/eslint": "^7.28.2",
"#types/jest": "^26.0.24",
"#types/mocha": "^9.0.0",
"#types/react": "17.0.2",
"#types/react-native": "^0.65.0",
"#types/react-native-vector-icons": "^6.4.9",
"#types/react-redux": "^7.1.20",
"#types/react-test-renderer": "^17.0.1",
"#typescript-eslint/eslint-plugin": "^5.1.0",
"#typescript-eslint/parser": "^5.1.0",
"babel-jest": "^26.6.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-testing-library": "^5.0.5",
"husky": "^7.0.0",
"jest": "^26.6.3",
"jest-fetch-mock": "^3.0.3",
"lint-staged": ">=10",
"metro-react-native-babel-preset": "^0.66.2",
"react-test-renderer": "^17.0.2",
"redux-devtools-extension": "^2.13.9"
},
"resolutions": {
"#types/react": "^17"
},
"jest": {
"verbose": true,
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"setupFilesAfterEnv": [
"#testing-library/jest-native/extend-expect"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/assetsTransformer.js",
"\\.(css|less)$": "<rootDir>/assetsTransformer.js"
},
"moduleDirectories": [
"node_modules",
"src"
],
"transform": {
"^.+\\.js$": "babel-jest"
},
"transformIgnorePatterns": [
"/node_modules/(?!native-base)/"
],
"setupFiles": [
"./setupJest.js"
]
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "eslint --cache --fix",
"*.{js,jsx,ts,tsx, json}": "prettier --write"
},
"rnpm": {
"assets": [
"./assets/fonts/"
]
}
}
What I do now is check the coverage, and then delete all the files.
I don't have this issue with React projects.
Is there something wrong with the configuration?
Those files are expected since are part of the repo itself so you can see lines of code covered by your tests etc.
You need to add the folder where those are generated into your .gitignore since the whole coverage shouldn't be tracked in your repo.
I keep getting export * from #react-navigation/core. Unexpected token export whenever I try to run my test for my project :
https://github.com/MatTaNg/React-Native
(run npm i && npm run test:watch [don't worry npm i doesn't take long its a small project])
Here's my package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"test": "jest",
"test:watch": "npm run test -- --watchAll"
},
"dependencies": {
"#types/jest": "^26.0.8",
"#types/node": "^14.0.27",
"expo": "~38.0.8",
"expo-status-bar": "^1.0.2",
"react": "~16.11.0",
"react-dom": "~16.11.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
"react-native-gesture-handler": "^1.7.0",
"react-native-reanimated": "^1.10.1",
"react-native-responsive-screen": "^1.4.1",
"react-native-router-flux": "^4.2.0",
"react-native-screens": "^2.9.0",
"react-native-web": "~0.11.7",
"react-test-renderer": "^16.13.1"
},
"devDependencies": {
"#babel/core": "^7.8.6",
"#testing-library/jest-native": "^3.3.0",
"#testing-library/react-native": "^7.0.1",
"#types/react": "~16.9.41",
"#types/react-native": "~0.62.13",
"jest": "^26.2.2",
"typescript": "~3.9.5"
},
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native)",
"node_modules/?!(react-navigation)"
],
"jest": {
"preset": "react-native"
},
"private": true
}
I'm just not able to figure this out. Something with react-navigation core is messing everything up I think.
Another, separate issue is that for some reason the HTML (jsx) isn't showing up on my mobile device (IOS) but its working fine in the browser. Seems like its just ignoring all the html inside my route.
EDIT:
I've followed the docs https://docs.expo.io/guides/testing-with-jest/
I've just added this to my package.json:
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|#react-native-community|expo(nent)?|#expo(nent)?/.*|react-navigation|#react-navigation/.*|#unimodules/.*|unimodules|sentry-expo|native-base|#sentry/.*)"
]
},
But now I'm getting this error when I run my test:
you are using expo therefore, you need to install expo-jest and use "preset": "jest-expo"
yarn add jest-expo --dev
package.json
"scripts": {
...
"test": "jest"
},
"jest": {
"preset": "jest-expo"
}
Here is DOCS for Expo jest. so, change expo jest configuration according to docs like below.
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"test": "jest",
"test:watch": "npm run test -- --watchAll"
},
"dependencies": {
"#types/jest": "^26.0.8",
"#types/node": "^14.0.27",
"expo": "~38.0.8",
"expo-status-bar": "^1.0.2",
"react": "~16.11.0",
"react-dom": "~16.11.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
"react-native-gesture-handler": "^1.7.0",
"react-native-reanimated": "^1.10.1",
"react-native-responsive-screen": "^1.4.1",
"react-native-router-flux": "^4.2.0",
"react-native-screens": "^2.9.0",
"react-native-web": "~0.11.7",
"react-test-renderer": "^16.13.1"
},
"devDependencies": {
"#babel/core": "^7.8.6",
"#testing-library/jest-native": "^3.3.0",
"#testing-library/react-native": "^7.0.1",
"#types/react": "~16.9.41",
"#types/react-native": "~0.62.13",
"jest": "^26.2.2",
"typescript": "~3.9.5",
"jest-expo": "^38.0.0"
},
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|#react-native-community|expo(nent)?|#expo(nent)?/.*|react-navigation|#react-navigation/.*|#unimodules/.*|unimodules|sentry-expo|native-base|#sentry/.*)"
]
},
"private": true
}
hope this will help you
I have an expo RN app that I was able to successfully upload to TestFlight last month but now is being rejected because of the AppStore's depreciation of the UIWebView version. I have removed all references of UIWebView, I have cleared the cache, I have refreshed the package-lock.json and even force removed all references with grep -r "UIWebView" . command. Nothing is working. Every time I rebuild my iOs app with Expo and then upload to TestFlight the build fails and throws this generic unhelpful error: This build is invalid.
I get an email with the below slightly more helpful message:
TMS-90809: Deprecated API Usage - New apps that use UIWebView are no
longer accepted. Instead, use WKWebView for improved security and
reliability. Learn more
I found one article saying I need to update my expo SDK version to 37 but when I do this my app breaks because I am on an old react native version (v 0.59) and they are not compatible.
I would really hate to rip apart my app, update the RN version, update the expo SDK version to only have the error persist.
Is there a way to get my app on App Store Connect without having to update my RN and expo SDK version in my app.json?
docs I have already looked through:
ITMS-90809: Deprecated API Usage -- Apple will stop accepting submissions of apps that use UIWebView APIs
https://developer.apple.com/documentation/uikit/uiwebview
app.json
{
"expo": {
"name": "companyname",
"slug": "companyname",
"privacy": "public",
"sdkVersion": "35.0.0",
"platforms": ["ios", "android", "web"],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/logo.png",
"splash": {
"image": "./assets/logo_original.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.companyname.companyname",
"buildNumber": "9.0.8"
},
"android": {
"package": "com.companyname.companyname",
"versionCode": 2.0,
"config": {
"googleMaps": {
"apiKey": "123"
}
},
"permissions": [
"ACCESS_COARSE_LOCATION",
"ACCESS_FINE_LOCATION",
"CAMERA",
"MANAGE_DOCUMENTS",
"READ_CONTACTS",
"READ_CALENDAR",
"WRITE_CALENDAR",
"READ_EXTERNAL_STORAGE",
"READ_PHONE_STATE",
"RECORD_AUDIO",
"USE_FINGERPRINT",
"VIBRATE",
"WAKE_LOCK",
"WRITE_EXTERNAL_STORAGE",
"com.anddoes.launcher.permission.UPDATE_COUNT",
"com.android.launcher.permission.INSTALL_SHORTCUT",
"com.google.android.c2dm.permission.RECEIVE",
"com.google.android.gms.permission.ACTIVITY_RECOGNITION",
"com.google.android.providers.gsf.permission.READ_GSERVICES",
"com.htc.launcher.permission.READ_SETTINGS",
"com.htc.launcher.permission.UPDATE_SHORTCUT",
"com.majeur.launcher.permission.UPDATE_BADGE",
"com.sec.android.provider.badge.permission.READ",
"com.sec.android.provider.badge.permission.WRITE",
"com.sonyericsson.home.permission.BROADCAST_BADGE"
]
}
}
}
package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest",
"postinstall": "node overwrite/migrate.js"
},
"jest": {
"preset": "react-native"
},
"dependencies": {
"#ptomasroos/react-native-multi-slider": "^2.0.0",
"#react-native-community/datetimepicker": "^2.2.3",
"#shoutem/ui": "^1.0.4",
"add": "^2.0.6",
"expo": "35.0.0",
"expo-cli": "^3.20.3",
"expo-constants": "^8.0.0",
"expo-device": "^2.0.0",
"expo-file-system": "^7.0.0",
"expo-image-picker": "^7.0.0",
"expo-linear-gradient": "^7.0.1",
"expo-location": "^5.0.1",
"expo-permissions": "^5.0.1",
"faker": "^4.1.0",
"firebase": "~7.0.0",
"firebase-admin": "^8.10.0",
"react": "16.8.3",
"react-dom": "^16.8.6",
"react-native": "0.59.8",
"react-native-animatable": "^1.3.3",
"react-native-app-intro-slider": "^3.0.0",
"react-native-collapsible": "^1.5.1",
"react-native-datepicker": "^1.7.2",
"react-native-deck-swiper": "^1.6.7",
"react-native-device-info": "^5.5.3",
"react-native-draggable-flatlist": "^1.1.9",
"react-native-elements": "^1.2.6",
"react-native-flash-message": "^0.1.15",
"react-native-gesture-handler": "^1.2.2",
"react-native-gifted-chat": "^0.12.0-beta-0",
"react-native-google-places": "^3.1.2",
"react-native-google-places-autocomplete": "^1.3.9",
"react-native-image-slider-show": "^1.0.3",
"react-native-keyboard-aware-scroll-view": "^0.9.1",
"react-native-maps": "0.24.2",
"react-native-multi-slider": "^0.3.6",
"react-native-picker-select": "^6.3.3",
"react-native-screens": "^2.5.0",
"react-native-swiper-flatlist": "^2.0.3",
"react-native-vector-icons": "^6.6.0",
"react-native-view-overflow": "0.0.4",
"react-native-web": "^0.11.4",
"react-navigation": "^3.13.0",
"redux": "^4.0.4"
},
"rnpm": {
"assets": [
"utils/Fonts/"
]
},
"devDependencies": {
"babel-eslint": "^10.0.3",
"babel-plugin-module-resolver": "^3.2.0",
"babel-preset-expo": "^5.2.0",
"eslint": "^6.6.0",
"eslint-config-react": "^1.1.7",
"eslint-config-react-native": "^4.0.0",
"eslint-import-resolver-babel-module": "^5.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.16.0",
"eslint-plugin-react-hooks": "0.0.0-f6b8d31a7",
"eslint-plugin-react-native": "^3.8.1",
"prettier": "^1.19.1"
},
"private": true
}
You need to update to SDK 37 to remove all dependencies on UIWebView. See this blog post for more information, in particular under the "UIWebView Removed" heading. https://blog.expo.io/expo-sdk-37-is-now-available-dd5770f066a6
I can't run my app using expo android application. My device working on Android Pie (8).
Expo android app version: 2.11.10
I trying run application on another device but have the same issue
error screen
27.0.0 is not a valid SDK Version. Option are 31.0.0, 32.0.0, 33.0.0 Unversioned
my package.json looks as below:
{
"name": "project",
"version": "0.1.0",
"private": true,
"devDependencies": {
"#types/jest": "^23.1.0",
"#types/react": "^16.4.1",
"#types/react-dom": "^16.0.6",
"#types/react-native": "^0.55.21",
"#types/react-navigation": "^2.0.5",
"#types/react-redux": "^6.0.2",
"#types/react-test-renderer": "^16.0.1",
"jest-expo": "~27.0.0",
"react-native-scripts": "1.14.0",
"react-native-typescript-transformer": "^1.2.10",
"react-test-renderer": "16.3.1",
"tslib": "^1.9.2",
"typescript": "^2.9.2"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"#types/expo": "^27.0.3",
"#types/lodash": "^4.14.116",
"axios": "^0.18.0",
"expo": "^27.0.1",
"lodash": "^4.17.11",
"native-base": "^2.5.2",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-27.0.0.tar.gz",
"react-native-animatable": "^1.3.0",
"react-native-maps": "^0.21.0",
"react-native-navigation": "^1.1.486",
"react-native-router-flux": "^4.0.0-beta.31",
"react-native-swipe-gestures": "^1.0.2",
"react-navigation": "^2.7.0",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-saga": "^0.16.0"
}
}
app.json looks like:
{
"expo": {
"name": "Tream",
"slug": "Tream",
"version": "1.0.0",
"orientation": "portrait",
"sdkVersion": "27.0.0",
"icon": "./src/assets/icon.png",
"splash": {
"image": "./src/assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"android": {
"package": "com.treamcompany.tream"
},
"packagerOpts": {
"sourceExts": ["ts", "tsx"],
"transformer": "node_modules/react-native-typescript-transformer/index.js"
}
}
}
You need to update your expo version:
npm install (for node module)
expo update
npm install react-native-gesture-handler --save
npm start
I had the same issue but i run the above commands and got the output
You can see the explanation for why this happened here: https://blog.expo.io/updated-expo-client-available-on-app-store-and-play-store-8747bd3a1364
For me the solution was:
"in your app.json and package.json files the sdk version should be the same"
"expo": {
"name": "ThirdReactApp",
"slug": "Third-React-App",
"privacy": "public",
"sdkVersion": "33.0.0",
"platforms": [
"ios",
"android"
],
"dependencies": {
"expo": "^34.0.1",
"react": "16.8.3",
"react-dom": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
"react-native-web": "^0.11.4"
},
The Expo client on your device is probably uptodate and fine but its the app (project) that you are trying to load thats outdated. You simply need to update your app (project) to a more recent and more compatible sdk. That said, follow the instructions on this website for a step by step guide on how to do this.
https://docs.expo.io/versions/latest/workflow/upgrading-expo-sdk-walkthrough/
For 27.0.0,You can use Expo apk 2.10.6
https://d1ahtucjixef4r.cloudfront.net/Exponent-2.10.6.apk
I just started working with React Native. Now I am trying to get my client running however I'm facing this issue
Requiring unknown module "./lib/templates/bootstrap".If you are sure the module is there, try restarting the packager or running "npm install".
package.json
{
"name": "client",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"eslint": "^2.10.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.8.0",
"eslint-plugin-jsx-a11y": "^1.2.0",
"eslint-plugin-react": "^5.1.1",
"react": "15.3.2",
"react-native": "^0.37.0",
"tcomb-form-native": "^0.5.0",
"whatwg-fetch": "^1.0.0"
},
"jest": {
"preset": "jest-react-native"
},
"devDependencies": {
"babel-jest": "17.0.0",
"babel-preset-react-native": "1.9.0",
"jest": "17.0.0",
"jest-react-native": "17.0.0",
"react-test-renderer": "15.3.2"
}
}
Then I tried to search the text /lib/templates/bootstrap in my project and I found it in index.android.bundle.
module.exports=LoginView;
}, "client/views/LoginView.js");
__d(559 / tcomb-form-native/index.js /, function(global, require, module, exports) {var _lib=require(560 / ./lib /);var _lib2=babelHelpers.interopRequireDefault(_lib);
var _en=require(620 / ./lib/i18n/en /);var _en2=babelHelpers.interopRequireDefault(_en);
var _bootstrap=require('./lib/templates/bootstrap');var _bootstrap2=babelHelpers.interopRequireDefault(_bootstrap);
var _bootstrap3=require(621 / ./lib/stylesheets/bootstrap /);var _bootstrap4=babelHelpers.interopRequireDefault(_bootstrap3);
Anyone can shed some lights on this ?