我的 package.json id 在下面定义,我使用的是 e2e 模式并且没有定义任何测试文件。我的测试用例属于 e2e 并包含测试文本,以便 mocha 可以阅读它
{
"name": "appOfCard",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"watch:test": "npm run test -- --watch",
"clean-cache": "watchman watch-del-all",
"svg-transform": "msvgc -f ./src/shared-ui/Icon/svg/$SVG.svg -o ./src/shared-ui/Icon/native/ --react-native",
"#svg_cmd_example": "SVG=search yarn run svg-transform",
"syncmessages": "node syncI18n.js",
"postinstall": "npm run syncmessages",
"rnd": "adb shell input keyevent KEYCODE_MENU",
"runios": "react-native run-ios --simulator='iPhone 7'",
"runandroid": "react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run-android",
"precommit": "lint-staged && npm run test && npm run syncmessages",
"lint": "eslint src",
"lint-fix": "eslint --fix src",
"test": "mocha .\\e2e\\*test.js",
"detox-server": "detox-server",
"e2e": "mocha e2e --opts ./e2e/mocha.opts",
"build": "xcodebuild -project NativeExample.xcodeproj -scheme NativeExample -derivedDataPath . -sdk iphonesimulator"
},
"rnpm": {
"assets": [
"./src/assets/fonts"
]
},
"moduleRoots": [
"./src/"
],
"lint-staged": {
"*.js": "eslint --ignore-path .gitignore"
},
"dependencies": {
"base-64": "^0.1.0",
"creditcardutils": "^1.0.0",
"email-validator": "^1.1.1",
"gem": "^2.4.2",
"geolib": "^2.0.24",
"husky": "^0.14.3",
"i18n-iso-countries": "^3.3.0",
"i18n-js": "^3.0.1",
"is-email": "^1.0.0",
"jsbarcode": "^3.8.0",
"lint-staged": "^7.0.0",
"lodash": "^4.17.4",
"lodash.groupby": "^4.6.0",
"moment": "^2.19.1",
"normalizr": "^3.2.4",
"prop-types": "^15.5.10",
"react": "^16.2.0",
"react-native": "0.51.0",
"react-native-acc": "^1.0.0",
"react-native-acc-gcm": "^1.0.0",
"react-native-appsflyer": "1.1.12",
"react-native-barcode-builder": "^1.0.2",
"react-native-camera": "https://github.com/PierreYvesParis/react-native-camera.git#stable",
"react-native-communications": "^2.2.1",
"react-native-device-brightness": "^1.2.0",
"react-native-device-info": "^0.17.4",
"react-native-extended-stylesheet": "^0.6.0",
"react-native-firebase": "^3.2.0",
"react-native-geolocation-service": "^1.0.0",
"react-native-htmlview": "^0.12.1",
"react-native-i18n": "^2.0.6",
"react-native-image-picker": "^0.26.7",
"react-native-image-progress": "^1.0.1",
"react-native-interactable": "^0.1.3",
"react-native-keyboard-aware-scroll-view": "~0.4.3",
"react-native-linear-gradient": "^2.3.0",
"react-native-maps": "~0.20.0",
"react-native-material-textfield": "https://github.com/antoinegrelard/react-native-material-textfield.git#master",
"react-native-modal": "^4.0.0",
"react-native-open-maps": "^0.1.1",
"react-native-open-settings": "^1.0.1",
"react-native-photo-view": "^1.4.0",
"react-native-section-list-get-item-layout": "^2.0.0",
"react-native-shadow": "^1.2.1",
"react-native-shadow-view": "^0.0.1",
"react-native-snap-carousel": "^3.6.0",
"react-native-svg": "^5.5.1",
"react-native-swiper": "^1.5.13",
"react-native-text-input-reset": "^1.0.2",
"react-native-version-check": "^2.0.1",
"react-native-video": "^2.0.0",
"react-navigation": "~1.1.2",
"react-navigation-redux-helpers": "~1.0.1",
"react-navigation-slide-from-right-transition": "^1.0.4",
"react-redux": "^5.0.6",
"react-string-replace": "^0.4.1",
"recompose": "^0.25.0",
"redux": "^3.7.2",
"redux-persist": "^4.10.1",
"redux-thunk": "^2.2.0",
"reselect": "^3.0.1",
"shortid": "^2.2.8",
"sync-spreadsheet": "^1.0.7",
"vanilla-masker": "^1.2.0"
},
"devDependencies": {
"babel-eslint": "8.2.1",
"babel-jest": "21.0.2",
"babel-plugin-module-resolver": "2.7.1",
"babel-preset-react-native": "3.0.2",
"detox": "^7.3.7",
"eslint": "4.16.0",
"eslint-config-airbnb": "15.1.0",
"eslint-config-prettier": "2.9.0",
"eslint-import-resolver-babel-module": "3.0.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-prettier": "2.6.0",
"eslint-plugin-react": "7.5.1",
"jest": "21.0.2",
"mocha": "^5.1.1",
"msvgc": "^0.1.1",
"prettier": "1.10.2",
"react-test-renderer": "16.0.0-alpha.12",
"regenerator-runtime": "^0.11.0"
},
"detox": {
"specs": "e2e",
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/debug-iphonesimulator/appOfCard.app",
"build": "xcodebuild -project ios/appOfCard.xcodeproj -scheme appOfCard -configuration debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"name": "iPhone 8 Plus"
}
}
}
}
我的 init.js 文件代码
const detox = require('detox');
const config = require('../package.json').detox;
-require('babel-polyfill');
before(async () => {
await detox.init(config);
});
after(async () => {
await detox.cleanup();
});