- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Expo 为我的 React Native 应用程序创建一个自动化的 UI 测试套件。我到处寻找好的教程,但是当我进入实际的测试编写部分时,由于环境问题,例如 import Icon from...
上的“意外标识符/ token ”等环境问题,我的测试甚至从未运行过。或其他愚蠢的问题,我找不到任何关于如何修复它们的教程。我真的花了一周的时间试图解决这些问题。
我是 React Native 的新手,也是 Jest/Detox/Expo 的新手
这是我的 package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"test": "node_modules/.bin/jest test/**/*.spec.js",
"eject": "expo eject"
},
"jest": {
"verbose": true,
"preset": "jest-expo"
},
"dependencies": {
"apsl-react-native-button": "^3.1.1",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-camera": "git+https://git@github.com/react-native-community/react-native-camera.git",
"react-native-camera-roll-picker": "^1.2.3",
"react-native-elements": "^1.0.0",
"react-native-fontawesome": "^6.0.1",
"react-native-is-iphonex": "^1.0.1",
"react-native-vector-icons": "^6.2.0",
"react-navigation": "^3.1.5"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0",
"bunyan-debug-stream": "^2.0.0",
"detox": "^10.0.9",
"detox-expo-helpers": "^0.6.0",
"expo-detox-hook": "^1.0.10",
"jest-expo": "^32.0.0",
"react-native-testing-library": "^1.5.0",
"react-test-renderer": "^16.8.2",
"babel-jest": "^24.1.0",
"enzyme": "^3.9.0",
"@babel/core": "^7.3.3",
"@expo/vector-icons": "^9.0.0",
"expo": "^32.0.0",
"jest": "^24.1.0"
},
"private": true,
"detox": {
"test-runner": "jest",
"configurations": {
"ios.sim": {
"binaryPath": "bin/Exponent.app",
"type": "ios.simulator",
"name": "iPhone X"
}
}
}
}
ip-10-101-32-118:KitchenProject bob.dole$ detox test --loglevel trace
configuration="ios.sim" loglevel="trace" artifactsLocation="artifacts/ios.sim.2019-02-21 21-54-14Z" node_modules/.bin/jest "e2e" --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:android:).)*$'
● Deprecation Warning:
Option "setupTestFrameworkScriptFile" was replaced by configuration "setupFilesAfterEnv", which supports multiple paths.
Please update your configuration.
Configuration Documentation:
https://jestjs.io/docs/configuration.html
FAIL e2e/RoomLayout.spec.js
● Test suite failed to run
/Users/bob.dole/KitchenDetail/KitchenProject/node_modules/@expo/vector-icons/FontAwesome.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import glyphMap from './vendor/react-native-vector-icons/glyphmaps/FontAwesome.json';
^^^^^^^^
SyntaxError: Unexpected identifier
> 1 | import FontAwesomeI from 'react-native-vector-icons/FontAwesome'
| ^
2 | import React from 'react'
3 |
4 | export const FontAwesome = props => (
at ScriptTransformer._transformAndBuildScript (../node_modules/jest/node_modules/jest-runtime/build/ScriptTransformer.js:440:17)
at Object.<anonymous> (../Components/icons.js:1:1)
FAIL e2e/tests/components/RoomLayoutDetox.spec.js
● Test suite failed to run
/Users/bob.dole/KitchenDetail/KitchenProject/node_modules/@expo/vector-icons/FontAwesome.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import glyphMap from './vendor/react-native-vector-icons/glyphmaps/FontAwesome.json';
^^^^^^^^
SyntaxError: Unexpected identifier
> 1 | import FontAwesomeI from 'react-native-vector-icons/FontAwesome'
| ^
2 | import React from 'react'
3 |
4 | export const FontAwesome = props => (
at ScriptTransformer._transformAndBuildScript (../node_modules/jest/node_modules/jest-runtime/build/ScriptTransformer.js:440:17)
at Object.<anonymous> (../Components/icons.js:1:1)
Test Suites: 2 failed, 2 total
Tests: 0 total
Snapshots: 0 total
Time: 0.827s
Ran all test suites matching /e2e/i with tests matching "^((?!:android:).)*$".
child_process.js:677
throw err;
^
Error: Command failed: node_modules/.bin/jest "e2e" --config=e2e/config.json --maxWorkers=1 '--testNamePattern=^((?!:android:).)*$'
at checkExecSyncError (child_process.js:637:11)
at Object.execSync (child_process.js:674:13)
at runJest (/Users/bob.dole/KitchenDetail/KitchenProject/node_modules/detox/local-cli/detox-test.js:166:6)
at run (/Users/bob.dole/KitchenDetail/KitchenProject/node_modules/detox/local-cli/detox-test.js:86:7)
at Object.<anonymous> (/Users/bob.dole/KitchenDetail/KitchenProject/node_modules/detox/local-cli/detox-test.js:229:1)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
import React, { Component } from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
import { LayoutButtons } from './LayoutButtons';
import { CameraLauncher } from './CameraLauncher';
import { CommentsLauncher } from './CommentsLauncher';
export class RoomLayout extends Component {
render() {
return (
<View>
<Text testID='roomLayoutText' style={styles.room}>
Room Layout{"\n"}
</Text>
<Text testID='infoText' style={styles.infoText}>
Take photos from opposite corners of the room{"\n"}
</Text>
<LayoutButtons />
</View>
);
}
}
const styles = StyleSheet.create({
view: {
marginTop: 80,
textAlign: 'center',
alignItems: 'center',
justifyContent: 'center'
},
infoText: {
marginTop: -10,
fontWeight: 'normal',
textAlign: 'center',
fontSize: 12,
justifyContent: 'center',
alignSelf: 'center',
color: 'grey'
},
room: {
marginTop: 15,
fontWeight: 'bold',
textAlign: 'center',
lineHeight: 14,
fontSize: 15
}
});
import React from 'react';
// import { RoomLayout } from '../Components/RoomLayout';
import { render } from 'react-native-testing-library';
describe('RoomLayout', () => {
// *** EDIT - I have removed this code ***
// beforeEach(async () => {
// const tree = render(<RoomLayout />);
//
// });
test('should have header and info text', async () => {
await element(by.text('Room Layout'));
await element(by.id('infoText'));
await element(by.id('infoText').and(by.text(' Take photos from opposite corners of the room')));
await expect(element(by.id('layoutButtonsReference'))).toBeVisible();
});
});
最佳答案
使用 Expo 应用程序设置排毒。您可能最适合从尚未使用过的干净应用程序开始。您需要确保已遵循基本设置 (step 1)让排毒在你的机器上工作
安装以下 devDependencies
npm i -D detox detox-expo-helpers expo-detox-hook jest
package.json
文件,这将配置排毒。您可以选择所需的 iPhone 类型。
"detox": {
"configurations": {
"ios.sim": {
"binaryPath": "bin/Exponent.app",
"type": "ios.simulator",
"name": "iPhone X"
}
},
"test-runner": "jest"
}
"scripts": {
"e2e": "detox test --configuration ios.sim"
}
npm run e2e
detox init -r jest
e2e
的文件夹在你的项目中。你会在里面找到三个文件
config.json
firstTest.spec.js
init.js
firstTest.spec.js
是一个样本测试。您需要对其进行以下更改。
const { reloadApp } = require('detox-expo-helpers');
await device.reloadReactNative();
await reloadApp();
Exponent.app
.它会有一个文件图标,但仍然是一个文件夹。 bin
文件夹并放 Exponent.app
里面所以它匹配上面设置的 binaryPath 。 setup.sh
在你的项目根目录中,复制内容然后运行它(你可能需要给它运行权限,你可以先运行
chmod +x setup.sh
,然后你可以使用
./setup.sh
运行它)。
#!/bin/bash -e
# query expo.io to find most recent ipaUrl
IPA_URL=`curl https://expo.io/--/api/v2/versions | python -c 'import sys, json; print json.load(sys.stdin)["iosUrl"]'`
# download tar.gz
TMP_PATH=/tmp/exponent.tar.gz
wget -O $TMP_PATH $IPA_URL
# recursively make app dir
APP_PATH=bin/Exponent.app
mkdir -p $APP_PATH
# unzip tar.gz into APP_PATH
tar -C $APP_PATH -xzf $TMP_PATH
expo start -c
启动打包程序
npm run e2e
如果你添加了脚本或者你可以运行
detox test
.
firstTest.spec.js
中存在的所有测试用例。或者你可以废弃那些并编写自己的。
firstTest.spec.js
const { reloadApp } = require('detox-expo-helpers');
describe('Example', () => {
beforeEach(async () => {
await reloadApp();
});
it('should have welcome screen', async () => {
await expect(element(by.id('welcome'))).toBeVisible();
});
it('should show hello screen after tap', async () => {
await element(by.id('hello_button')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
});
it('should show world screen after tap', async () => {
await element(by.id('world_button')).tap();
await expect(element(by.label('World!!!'))).toBeVisible();
});
});
App.js
import React, { Component } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
export default class App extends Component {
state = {
greeting: undefined
};
render () {
if (this.state.greeting) return this.renderAfterButton();
return (
<View
testID="welcome"
style={{
flex: 1,
paddingTop: 20,
justifyContent: 'center',
alignItems: 'center'
}}>
<Text style={{ fontSize: 25, marginBottom: 30 }}>Welcome</Text>
<TouchableOpacity
testID="hello_button"
onPress={this.onButtonPress.bind(this, 'Hello')}>
<Text style={{ color: 'blue', marginBottom: 20 }}>Say Hello</Text>
</TouchableOpacity>
<TouchableOpacity
testID="world_button"
onPress={this.onButtonPress.bind(this, 'World')}>
<Text style={{ color: 'blue', marginBottom: 20 }}>Say World</Text>
</TouchableOpacity>
</View>
);
}
renderAfterButton () {
return (
<View
style={{
flex: 1,
paddingTop: 20,
justifyContent: 'center',
alignItems: 'center'
}}>
<Text style={{ fontSize: 25 }}>{this.state.greeting}!!!</Text>
</View>
);
}
onButtonPress (greeting) {
this.setState({
greeting: greeting
});
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center'
}
});
关于react-native - 是否真的可以通过与 Expo 一起运行的 React Native 应用程序通过 Detox/Jest 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54816994/
我正在尝试在两个表之间进行空间连接: 表 1:397265 个特征(在 geom 字段上有 gist 索引) 表 2:73 个特征(在 geom 字段上有 gist 索引) 表 1 和表 2 具有相同
我正在尝试在两个表之间进行空间连接: 表 1:397265 个特征(在 geom 字段上有 gist 索引) 表 2:73 个特征(在 geom 字段上有 gist 索引) 表 1 和表 2 具有相同
枚举类型的值是该类型的静态变量。 据我所知,变量是由引用变量引用的,但没有新的运算符来实例化枚举对象。但这就像初始化数组一样吗? 这是对还是错? 最佳答案 是的,枚举类型的文字是 public sta
我阅读了有关关闭 zsh 自动更正以完成命令的所有提示。但是,它们并没有完全发挥作用。我试过 DISABLE_CORRECTION="true", unsetopt correct, unsetopt
我知道这个问题是 answered before ,但给出的答案并不是完整的故事: 我进入了 Firefox 的 Options->Content 并删除了除德语/德国之外的所有语言,navigato
我知道用汇编语言编写任何内容或将汇编语言添加到任何程序都会损害其可移植性。但是,有多糟糕呢?我的意思是,现在基本上所有 PC 都是 x86 或 x64,对吧?那么,如果我将汇编嵌入到 C 程序中,为什
我正计划构建一个 Web 服务客户端,它始终检查数据库中的某些记录,并根据数据库内容的结果在每个时刻及时执行某些决策。 所以我在想,我怎样才能让客户端一直运行呢? 我唯一想到的就是无限循环。像这样的东
我无法获取小部件的实际背景颜色。在我的特殊情况下,我在使用 QTabWidget 中的小部件时遇到了问题。 这是在 Windows7 上。所以经典小部件有一些灰色背景,而选项卡中的小部件通常用白色背景
请不要将我指向How to wrap preference title?因为它不适用于(正如我评论的那样)您使用 @strings/ 的情况对 strings.xml 文件的引用。 如果你使用 and
情况如下: 已知hdfs是仅附加的(本身没有更新)。 配置单元将数据写入其位于hdfs中的仓库。 可以在配置单元中执行更新 这意味着写入了新数据,旧数据应该以某种方式标记为已弃用,然后在某个时间将其清
在javascript中删除cookies的方法是将过期日期设置为过去。现在这实际上并没有删除 cookie,至少在 Firefox 中是这样。这只是意味着 cookie 将在浏览器关闭时被删除。 这
我需要终止一个卡住的线程,我将 IsBackground 设置为 true 但它仍然存在。线程的属性: ThreadState = AbortRequested IsBackground = true
在逻辑中,以及在 *ahem* 正确设计的编程语言中,将 boolean 值与 true 进行比较总是多余的,即 a == True 应该简单地替换为 a 。 (类似地, a == False 由 n
我一直在努力寻找一个好的定义,并理解线程到底是什么。 看来我一定错过了一些明显的东西,但是每次我读到什么是线程时,它几乎是一个循环定义,la“线程是一个执行线程”或“一种划分运行任务的方法” ”。呃呃
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
是否可以在 MAC 上以真正的全屏模式运行 IntelliJ Idea? 没有工具栏、侧边栏、按钮,只有代码。 如果可以,请告诉我。 最佳答案 您可以通过禁用以下项目在 View 菜单中执行此操作:
考虑以下代码: case class Vector3(var x: Float, var y: Float, var z: Float) { def add(v: Vector3): Unit =
我试图确认这个说法是否属实: 模型包括: 持久层:本质上是 DAO + 表示表的类 + DTO 服务层:DAOS + 一些逻辑的组合 您能否也引用/支持您的回答?我相信我在Spring Framewo
给定代码: #include struct X {}; struct Y1: virtual X {}; struct Y2: virtual X {}; struct Y3: virtual X
从这个其他QUESTION他们谈论 Bjarne Stroustrup 是如何说的,就像比 int 窄的整数数据类型(例如 short)被提升为 int,float 被提升为 double。但是,与i
我是一名优秀的程序员,十分优秀!