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

Commit 1aff852

Browse files
committed
Change testkit reporter
1 parent 06685e4 commit 1aff852

File tree

4 files changed

+82
-42
lines changed

4 files changed

+82
-42
lines changed

test/react-native-testkit/components/reporter.js

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ListView,
1010
Image,
1111
TouchableOpacity,
12+
Dimensions,
1213
RecyclerViewBackedScrollView,
1314
} from 'react-native';
1415

@@ -20,9 +21,11 @@ export default class Reporter extends Component {
2021
constructor(props:any) {
2122
super(props)
2223
this.tests = {
23-
summary : [{}],
2424
common : []
2525
}
26+
this.state = {
27+
listHeight : 0
28+
}
2629
this.testGroups = ['summary','common']
2730
this.ds = null
2831
this.updateDataSource()
@@ -35,20 +38,49 @@ export default class Reporter extends Component {
3538

3639
render() {
3740

41+
let tests = RNTEST.TestContext.getTests()
42+
43+
let passed = 0
44+
let executed = 0
45+
let count = 0
46+
for(let i in tests) {
47+
if(tests[i].status !== 'skipped')
48+
count++
49+
if(tests[i].status !== 'waiting' && tests[i].status !== 'skipped')
50+
executed++
51+
passed += tests[i].status === 'pass' ? 1 : 0
52+
}
53+
let percent = passed / count
54+
let color = `rgb(${Math.floor((1-percent) *255)},${Math.floor(percent *255)}, 0)`
55+
3856
return (
39-
<ListView
40-
style={styles.container}
41-
dataSource={this.ds}
42-
renderRow={this.renderTest.bind(this)}
43-
renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}
44-
renderSectionHeader={(data, id) => {
45-
return (
46-
<View style={styles.sectionHeader}>
47-
<Text style={styles.sectionText}>{id}</Text>
48-
</View>
49-
)
50-
}}
51-
/>)
57+
<View style={{flex : 1}}>
58+
<View style={{margin : 20}} onLayout={(e) => {
59+
this.setState({
60+
headerHeight : e.nativeEvent.layout.height,
61+
listHeight : Dimensions.get('window').height - e.nativeEvent.layout.height
62+
})
63+
}}>
64+
<Text>{`${executed} tests executed`}</Text>
65+
<Text>{`${passed} test cases passed`}</Text>
66+
<Text>{`${count} test cases`}</Text>
67+
<Text style={{color, fontSize : 120, textAlign : 'center'}} >{`${Math.floor(percent*100)}`}</Text>
68+
<Text style={{color, fontSize : 30, textAlign :'right', marginTop : -54, marginRight : 40, backgroundColor : 'transparent'}} >{`%`}</Text>
69+
</View>
70+
<ListView
71+
style={[styles.container]}
72+
dataSource={this.ds}
73+
renderRow={this.renderTest.bind(this)}
74+
renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}
75+
renderSectionHeader={(data, id) => {
76+
return (
77+
<View style={styles.sectionHeader}>
78+
<Text style={styles.sectionText}>{id}</Text>
79+
</View>
80+
)
81+
}}
82+
/>
83+
</View>)
5284
}
5385

5486
renderTest(t, group) {
@@ -57,23 +89,6 @@ export default class Reporter extends Component {
5789
let foundActions = false
5890
let tests = RNTEST.TestContext.getTests()
5991

60-
if(group === 'summary')
61-
{
62-
let passed = 0
63-
let executed = 0
64-
let count = 0
65-
for(let i in tests) {
66-
count++
67-
if(tests[i].executed)
68-
passed += tests[i].status === 'pass' ? 1 : 0
69-
}
70-
return (<View style={{flex : 1}}>
71-
<Text>{`${count} test cases`}</Text>
72-
<Text>{`${executed} tests executed`}</Text>
73-
<Text>{`${ParseFloat(pass/count).toFixed(2)}% tests passed`}</Text>
74-
</View>)
75-
}
76-
7792
if(Array.isArray(t.result) && !t.expired) {
7893
t.result = t.result.map((r) => {
7994
if(r.type.name === 'Assert' || r.type.name === 'Info') {
@@ -94,9 +109,9 @@ export default class Reporter extends Component {
94109
t.status = 'waiting'
95110

96111
return (
97-
<TouchableOpacity onPress={()=>{
98-
t.start(t.sn)
99-
}}>
112+
// <TouchableOpacity onPress={()=>{
113+
// t.start(t.sn)
114+
// }}>
100115
<View key={'rn-test-' + t.desc} style={{
101116
borderBottomWidth : 1.5,
102117
borderColor : '#DDD',
@@ -111,8 +126,8 @@ export default class Reporter extends Component {
111126
<View key={t.desc + '-result'} style={{backgroundColor : '#F4F4F4'}}>
112127
{t.expand ? t.result : (t.status === 'pass' ? null : t.result)}
113128
</View>
114-
</View>
115-
</TouchableOpacity>)
129+
</View>)
130+
{/*</TouchableOpacity>)*/}
116131
}
117132

118133
updateDataSource() {

test/react-native-testkit/lib/test-context.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class TestContext {
4242
run : run === false ? false : true,
4343
result : null,
4444
asserts : [],
45-
timeout : timeout || 3000,
45+
timeout : timeout || 15000,
4646
expired : false,
4747
running : false,
4848
executed : false,
@@ -153,6 +153,7 @@ export default class TestContext {
153153
for(let j in result) {
154154
if(result[j].uid === data[i].props.uid)
155155
result[j] = data[i]
156+
result.splice(j,1)
156157
break
157158
}
158159
}

test/test-0.5.1.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe('Upload from file storage', (report, done) => {
119119
})
120120

121121
describe('Upload multipart data with file from storage', (report, done) => {
122+
try{
122123
let filename = 'test-from-storage-img-'+Date.now()+'.png'
123124
RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
124125
'Content-Type' : 'multipart/form-data',
@@ -144,6 +145,9 @@ describe('Upload multipart data with file from storage', (report, done) => {
144145
</Info>)
145146
done()
146147
})
148+
} catch(err) {
149+
console.log(err)
150+
}
147151
})
148152

149153
describe('Upload and download at the same time', (report, done) => {
@@ -179,30 +183,51 @@ describe('Upload and download at the same time', (report, done) => {
179183
done()
180184
})
181185
})
182-
183186
})
184187

185188
RNTest.config({
186189
group : '0.5.1',
187190
run : true,
188191
expand : false,
189-
timeout : 30000,
192+
timeout : 600000,
190193
})('Upload and download large file', (report, done) => {
191194
let filename = '22mb-dummy-' + Date.now()
195+
let begin = -1
196+
let begin2 = -1
192197
RNFetchBlob.config({
193198
fileCache : true
194199
})
195200
.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`)
201+
// .progress((now, total) => {
202+
// if(begin === -1)
203+
// begin = Date.now()
204+
// report(<Info uid="200" key="progress">
205+
// <Text>
206+
// {`download ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s)`}
207+
// </Text>
208+
// </Info>)
209+
// })
196210
.then((res) => {
197211
return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
198212
Authorization : `Bearer ${DROPBOX_TOKEN}`,
199213
'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
200214
'Content-Type' : 'application/octet-stream',
201215
}, RNFetchBlob.wrap(res.path()))
216+
// .progress((now, total) => {
217+
// if(begin2 === -1)
218+
// begin2 = Date.now()
219+
// let speed = Math.floor(now / (Date.now() - begin2))
220+
// report(<Info uid="100" key="progress">
221+
// <Text>
222+
// {`upload ${now} / ${total} bytes (${speed} kb/s)`}
223+
// {` ${Math.floor((total-now)/speed/1000)} seconds left`}
224+
// </Text>
225+
// </Info>)
226+
// })
202227
})
203228
.then((res) => {
204229
report(<Assert
205-
key="upload should success withou crashing app"
230+
key="upload should success without crashing app"
206231
expect={filename}
207232
actual={res.json().name}/>)
208233
done()
@@ -302,5 +327,4 @@ describe('Session API CRUD test', (report, done) => {
302327
})
303328

304329
})
305-
306330
})

test/test-init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('GET image from server', (report, done) => {
5050
done()
5151
})
5252
})
53-
//
53+
5454
require('./test-0.1.x-0.4.x')
5555
require('./test-0.5.1')
5656
require('./test-0.5.2')

0 commit comments

Comments
 (0)