当我在本地运行“ npm测试”时,我的所有测试运行正常,没有问题。但是,当我尝试在CircleCI上运行测试时,出现了错误...
import React from 'react';
^^^^^
SyntaxError: Unexpected identifier
at Runtime._execModule (node_modules/jest-runtime/build/index.js:988:58)
我不确定两者之间的差异在哪里。这是我的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"
},
"dependencies": {
"@aws-amplify/api": "^1.2.4",
"@aws-amplify/pubsub": "^1.2.4",
"aws-amplify": "^2.2.2",
"aws-amplify-react": "^2.5.4",
"aws-amplify-react-native": "^3.2.0",
"expo": "^35.0.0",
"react": "16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
"react-native-gesture-handler": "~1.3.0",
"react-native-modal-dropdown": "^0.7.0",
"react-native-reanimated": "~1.2.0",
"react-native-screens": "^2.0.0-alpha.32",
"react-native-svg": "9.9.5",
"react-native-vector-icons": "^6.6.0",
"react-native-web": "^0.11.7",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.10.3",
"react-navigation-tabs": "^2.6.0",
"victory-native": "^33.0.0"
},
"devDependencies": {
"babel-preset-expo": "^7.1.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"enzyme-react-16-adapter-setup": "^0.1.0",
"enzyme-to-json": "^3.4.3",
"jest": "^24.9.0",
"jest-enzyme": "^7.1.2",
"react-dom": "^16.8.3"
},
"private": true,
"jest": {
"preset": "react-native",
"collectCoverage": true,
"moduleDirectories": [
"node_modules",
"src"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
},
"setupFiles": [
"<rootDir>/jest/setup.js"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|victory-.*)"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/jest"
]
}
}
这是我的CircleCI .yml文件...
version: 2.2
jobs:
build:
docker:
- image: circleci/node:10.15
working_directory: ~/repo/my-app
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v2.2-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v2.2-dependencies-
- run: npm install
- save_cache:
paths:
- node_modules
key: v2.2-dependencies-{{ checksum "package.json" }}
# run tests!
- run: npm test
似乎是因为我“ npm install”,所有React和Jest元素都应该可以正常工作。关于我的配置似乎有任何想法吗?
我看到了可能是问题原因的两件事,但是将此注释更多地用作提示而不是解决方案。
首先,您必须确保运行与circleci(10.15)相同的节点版本。您可以使用nvm(https://github.com/nvm-sh/nvm)来实现。
然后,您应该缓存package-lock.json
,因为它包含项目依赖项的更精细的表示。
最后删除node_modules/
,然后重新安装依赖项。