【发布时间】:2020-02-01 05:29:41
【问题描述】:
当我在本地运行“npm test”时,我的测试都运行良好,没有问题。但是,当我尝试在 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 元素都应该可以正常工作。如果我的配置看起来不对,有什么想法吗?
【问题讨论】:
标签: react-native jestjs circleci