Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 0099ae1

Browse files
committed
Add test case for #8 redirection responses verify.
1 parent 5a9ad20 commit 0099ae1

File tree

12 files changed

+208
-77
lines changed

12 files changed

+208
-77
lines changed

test/.flowconfig

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[ignore]
2+
3+
# We fork some components by platform.
4+
.*/*.web.js
5+
.*/*.android.js
6+
7+
# Some modules have their own node_modules with overlap
8+
.*/node_modules/node-haste/.*
9+
10+
# Ugh
11+
.*/node_modules/babel.*
12+
.*/node_modules/babylon.*
13+
.*/node_modules/invariant.*
14+
15+
# Ignore react and fbjs where there are overlaps, but don't ignore
16+
# anything that react-native relies on
17+
.*/node_modules/fbjs/lib/Map.js
18+
.*/node_modules/fbjs/lib/ErrorUtils.js
19+
20+
# Flow has a built-in definition for the 'react' module which we prefer to use
21+
# over the currently-untyped source
22+
.*/node_modules/react/react.js
23+
.*/node_modules/react/lib/React.js
24+
.*/node_modules/react/lib/ReactDOM.js
25+
26+
.*/__mocks__/.*
27+
.*/__tests__/.*
28+
29+
.*/commoner/test/source/widget/share.js
30+
31+
# Ignore commoner tests
32+
.*/node_modules/commoner/test/.*
33+
34+
# See https://github.com/facebook/flow/issues/442
35+
.*/react-tools/node_modules/commoner/lib/reader.js
36+
37+
# Ignore jest
38+
.*/node_modules/jest-cli/.*
39+
40+
# Ignore Website
41+
.*/website/.*
42+
43+
# Ignore generators
44+
.*/local-cli/generator.*
45+
46+
# Ignore BUCK generated folders
47+
.*\.buckd/
48+
49+
.*/node_modules/is-my-json-valid/test/.*\.json
50+
.*/node_modules/iconv-lite/encodings/tables/.*\.json
51+
.*/node_modules/y18n/test/.*\.json
52+
.*/node_modules/spdx-license-ids/spdx-license-ids.json
53+
.*/node_modules/spdx-exceptions/index.json
54+
.*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json
55+
.*/node_modules/resolve/lib/core.json
56+
.*/node_modules/jsonparse/samplejson/.*\.json
57+
.*/node_modules/json5/test/.*\.json
58+
.*/node_modules/ua-parser-js/test/.*\.json
59+
.*/node_modules/builtin-modules/builtin-modules.json
60+
.*/node_modules/binary-extensions/binary-extensions.json
61+
.*/node_modules/url-regex/tlds.json
62+
.*/node_modules/joi/.*\.json
63+
.*/node_modules/isemail/.*\.json
64+
.*/node_modules/tr46/.*\.json
65+
66+
67+
[include]
68+
69+
[libs]
70+
node_modules/react-native/Libraries/react-native/react-native-interface.js
71+
node_modules/react-native/flow
72+
flow/
73+
74+
[options]
75+
module.system=haste
76+
77+
esproposal.class_static_fields=enable
78+
esproposal.class_instance_fields=enable
79+
80+
munge_underscores=true
81+
82+
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
83+
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
84+
85+
suppress_type=$FlowIssue
86+
suppress_type=$FlowFixMe
87+
suppress_type=$FixMe
88+
89+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
90+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
91+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
92+
93+
[version]
94+
0.24.0

test/in-app-test-runner/assert.js renamed to test/in-app-test-runner/components/assert.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
import React, {Component} from 'react';
32
import {
43
AppRegistry,
@@ -14,7 +13,9 @@ export default class Assert extends Component {
1413

1514
props : {
1615
expect : any,
17-
actual : any
16+
actual : any,
17+
desc : any,
18+
compaer : () => bool
1819
};
1920

2021
constructor(props) {
@@ -33,22 +34,32 @@ export default class Assert extends Component {
3334
<Text style={{
3435
color : this.getAssertion() ? '#00a825' : '#ff0d0d',
3536
margin : 8,
37+
marginTop : 0,
3638
marginLeft : 0
37-
}}>{ this.getAssertion() ? '✅' : '×' } Assertion description</Text>
39+
}}>{ this.getAssertion() ? '✅' : '×' } {this.props.desc}</Text>
3840
<Text style={{flex : 1, flexDirection : 'row'}}>
3941
<Text style={{ color : '#AAA'}}>expect </Text>
40-
<Text style={{flex : 1}}>{this.props.expect}</Text>
42+
<Text style={{flex : 1}}>{String(this.props.expect)}</Text>
4143
</Text>
4244
<Text style={{flex : 1, flexDirection : 'row'}}>
4345
<Text style={{color : '#AAA'}}>actual </Text>
44-
<Text style={{flex : 1}}>{this.props.actual}</Text>
46+
<Text style={{flex : 1}}>{String(this.props.actual)}</Text>
4547
</Text>
48+
{this.props.comparer ? <Text style={{flex : 1, flexDirection : 'row'}}>
49+
<Text style={{color : '#AAA'}}>comparer = </Text>
50+
<Text style={{flex : 1}}>
51+
{ String(this.props.comparer) }
52+
</Text>
53+
</Text> : null}
4654
</View>
4755
)
4856
}
4957

5058
getAssertion() {
51-
return this.props.expect === this.props.actual
59+
if(this.props.comparer)
60+
return this.props.comparer(this.props.expect, this.props.actual)
61+
else
62+
return this.props.expect === this.props.actual
5263
}
5364

5465
}

test/in-app-test-runner/info.js renamed to test/in-app-test-runner/components/info.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
import React, {Component} from 'react';
32
import {
43
AppRegistry,
@@ -10,8 +9,8 @@ import {
109
export default class Info extends Component {
1110

1211
props : {
13-
description : string,
14-
}
12+
desc : string,
13+
};
1514

1615
render() {
1716
return (
@@ -22,10 +21,10 @@ export default class Info extends Component {
2221
}}>
2322
<View style={{ alignSelf : 'stretch'}}>
2423
<Text style={{color : '#777', alignSelf : 'stretch', textAlign : 'center', margin : 8}}>
25-
{this.props.description}
24+
{this.props.desc}
2625
</Text>
2726
</View>
28-
<View style={{alignSelf : 'stretch'}}>{this.props.children}</View>
27+
<View style={{margin : 8, alignSelf : 'stretch'}}>{this.props.children}</View>
2928
</View>
3029
)
3130
}

test/in-app-test-runner/reporter.js renamed to test/in-app-test-runner/components/reporter.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import Assert from './assert.js'
1313

1414
export default class Reporter extends Component {
1515

16+
props : {
17+
context : TestContext
18+
};
19+
1620
render() {
1721
return (
1822
<ScrollView key="rn-test-scroller" style={styles.container}>
@@ -26,14 +30,18 @@ export default class Reporter extends Component {
2630
let pass = true
2731
let foundAssertions = false
2832

29-
Array.isArray(t.result) && t.result.forEach((r) => {
30-
if(r.type.name === 'Assert') {
31-
foundAssertions = true
32-
pass = pass && (r.props.actual === r.props.expect)
33-
}
34-
})
33+
if(Array.isArray(t.result)) {
34+
t.result = t.result.map((r) => {
35+
if(r.type.name === 'Assert') {
36+
foundAssertions = true
37+
let comp = r.props.comparer ? r.props.comparer(r.props.expect, r.props.actual) : (r.props.actual === r.props.expect)
38+
pass = pass && comp
39+
}
40+
return React.cloneElement(r, {desc : r.key})
41+
})
42+
}
3543

36-
t.status = foundAssertions ? (pass ? 'pass' : 'fail') : t.status
44+
t.status = foundAssertions ? (pass ? 'pass' : 'fail') : 'pass'
3745

3846
return (<View key={'rn-test-' + t.desc} style={{
3947
borderBottomWidth : 1.5,
@@ -43,8 +51,8 @@ export default class Reporter extends Component {
4351
alignItems : 'center',
4452
flexDirection : 'row'
4553
}}>
46-
<Text style={[styles.badge, {flex : 1, borderWidth : 0}]}>{t.desc}</Text>
47-
<Text style={[styles.badge, this.getBadge(t.status)]}>{t.status}</Text>
54+
<Text style={[styles.badge, {flex : 1, borderWidth : 0, textAlign : 'left'}]}>{t.desc}</Text>
55+
<Text style={[styles.badge, this.getBadge(t.status)]}>{t.status ? 'pass' : 'fail'}</Text>
4856
</View>
4957
<View key={t.desc + '-result'} style={{backgroundColor : '#F4F4F4'}}>
5058
{t.result}
@@ -53,9 +61,9 @@ export default class Reporter extends Component {
5361
})
5462
}
5563

56-
getBadge(status) {
64+
getBadge(status: 'running' | 'pass' | 'fail') {
5765
if(status === 'running')
58-
return styles.badgeRunning
66+
return styles.badgeWaiting
5967
else if(status === 'pass')
6068
return styles.badgePass
6169
else
@@ -74,12 +82,13 @@ const styles = StyleSheet.create({
7482
padding : 4,
7583
borderRadius : 4,
7684
borderWidth : 2,
85+
textAlign : 'center'
7786
},
7887
badgePass: {
7988
borderColor : '#00a825',
8089
color : '#00a825'
8190
},
82-
badgeRunning: {
91+
badgeWaiting: {
8392
borderColor : '#e3c423',
8493
color : '#e3c423'
8594
},

test/in-app-test-runner/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import TestContext from './app-test'
2-
import Reporter from './reporter'
3-
import Assert from './assert'
4-
import Info from './info'
1+
import TestContext from './lib/test-context'
2+
import Comparer from './lib/comparer'
3+
import Reporter from './components/reporter'
4+
import Assert from './components/assert'
5+
import Info from './components/info'
56

67
export default {
78
TestContext,
89
Reporter,
910
Info,
10-
Assert
11+
Assert,
12+
Comparer
1113
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
greater : (a, b) => a > b,
3+
smaller : (a, b) => a < b,
4+
instanceOf : (a, b) => a instanceof b,
5+
typeof : (a, b) => typeof a === b,
6+
IsNull : (a, b) => a === null,
7+
exists : (a, b) => a !== void 0,
8+
hasValue : (a, b) => (a !== void 0) && (Array.isArray(a) ? a.length !==0 : true),
9+
isArray : (a, b) => Array.isArray(a),
10+
}

test/in-app-test-runner/app-test.js renamed to test/in-app-test-runner/lib/test-context.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class RNAppTest {
1+
export default class TestContext {
22

33
constructor() {
44
this.tests = []
@@ -30,8 +30,8 @@ export default class RNAppTest {
3030
return promise
3131
}
3232

33-
update(i, data) {
34-
Object.assign(this.tests[i], data)
33+
update(i, ...data) {
34+
Object.assign(this.tests[i], {result : [...data]})
3535
this.context.forceUpdate()
3636
}
3737

test/in-app-test-runner/types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type TestContext = {
2+
context? : any,
3+
tests : Array
4+
}

test/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "react-native-module-testor",
3+
"version": "0.1.0",
4+
"description": "An in-app test framework for react-native.",
5+
"main": "index.js",
6+
"keywords": [
7+
"react"
8+
],
9+
"author": "wkh237",
10+
"license": "MIT"
11+
}

0 commit comments

Comments
 (0)