Selaa lähdekoodia

Change testkit reporter

Ben Hsieh 8 vuotta sitten
vanhempi
commit
1aff85267b

+ 51
- 36
test/react-native-testkit/components/reporter.js Näytä tiedosto

9
   ListView,
9
   ListView,
10
   Image,
10
   Image,
11
   TouchableOpacity,
11
   TouchableOpacity,
12
+  Dimensions,
12
   RecyclerViewBackedScrollView,
13
   RecyclerViewBackedScrollView,
13
 } from 'react-native';
14
 } from 'react-native';
14
 
15
 
20
   constructor(props:any) {
21
   constructor(props:any) {
21
     super(props)
22
     super(props)
22
     this.tests = {
23
     this.tests = {
23
-      summary : [{}],
24
       common : []
24
       common : []
25
     }
25
     }
26
+    this.state = {
27
+      listHeight : 0
28
+    }
26
     this.testGroups = ['summary','common']
29
     this.testGroups = ['summary','common']
27
     this.ds = null
30
     this.ds = null
28
     this.updateDataSource()
31
     this.updateDataSource()
35
 
38
 
36
   render() {
39
   render() {
37
 
40
 
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
+
38
     return (
56
     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>)
52
   }
84
   }
53
 
85
 
54
   renderTest(t, group) {
86
   renderTest(t, group) {
57
     let foundActions = false
89
     let foundActions = false
58
     let tests = RNTEST.TestContext.getTests()
90
     let tests = RNTEST.TestContext.getTests()
59
 
91
 
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
-
77
     if(Array.isArray(t.result) && !t.expired) {
92
     if(Array.isArray(t.result) && !t.expired) {
78
       t.result = t.result.map((r) => {
93
       t.result = t.result.map((r) => {
79
         if(r.type.name === 'Assert' || r.type.name === 'Info') {
94
         if(r.type.name === 'Assert' || r.type.name === 'Info') {
94
       t.status = 'waiting'
109
       t.status = 'waiting'
95
 
110
 
96
     return (
111
     return (
97
-      <TouchableOpacity onPress={()=>{
98
-          t.start(t.sn)
99
-        }}>
112
+      // <TouchableOpacity onPress={()=>{
113
+      //   t.start(t.sn)
114
+      // }}>
100
         <View key={'rn-test-' + t.desc} style={{
115
         <View key={'rn-test-' + t.desc} style={{
101
           borderBottomWidth : 1.5,
116
           borderBottomWidth : 1.5,
102
           borderColor : '#DDD',
117
           borderColor : '#DDD',
111
           <View key={t.desc + '-result'} style={{backgroundColor : '#F4F4F4'}}>
126
           <View key={t.desc + '-result'} style={{backgroundColor : '#F4F4F4'}}>
112
             {t.expand ? t.result : (t.status === 'pass' ? null : t.result)}
127
             {t.expand ? t.result : (t.status === 'pass' ? null : t.result)}
113
           </View>
128
           </View>
114
-        </View>
115
-      </TouchableOpacity>)
129
+        </View>)
130
+        {/*</TouchableOpacity>)*/}
116
   }
131
   }
117
 
132
 
118
   updateDataSource() {
133
   updateDataSource() {

+ 2
- 1
test/react-native-testkit/lib/test-context.js Näytä tiedosto

42
       run : run === false ? false : true,
42
       run : run === false ? false : true,
43
       result : null,
43
       result : null,
44
       asserts : [],
44
       asserts : [],
45
-      timeout : timeout || 3000,
45
+      timeout : timeout || 15000,
46
       expired : false,
46
       expired : false,
47
       running : false,
47
       running : false,
48
       executed : false,
48
       executed : false,
153
         for(let j in result) {
153
         for(let j in result) {
154
           if(result[j].uid === data[i].props.uid)
154
           if(result[j].uid === data[i].props.uid)
155
           result[j] = data[i]
155
           result[j] = data[i]
156
+          result.splice(j,1)
156
           break
157
           break
157
         }
158
         }
158
       }
159
       }

+ 28
- 4
test/test-0.5.1.js Näytä tiedosto

119
 })
119
 })
120
 
120
 
121
 describe('Upload multipart data with file from storage', (report, done) => {
121
 describe('Upload multipart data with file from storage', (report, done) => {
122
+  try{
122
     let filename = 'test-from-storage-img-'+Date.now()+'.png'
123
     let filename = 'test-from-storage-img-'+Date.now()+'.png'
123
     RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
124
     RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
124
         'Content-Type' : 'multipart/form-data',
125
         'Content-Type' : 'multipart/form-data',
144
       </Info>)
145
       </Info>)
145
       done()
146
       done()
146
     })
147
     })
148
+  } catch(err) {
149
+    console.log(err)
150
+  }
147
 })
151
 })
148
 
152
 
149
 describe('Upload and download at the same time', (report, done) => {
153
 describe('Upload and download at the same time', (report, done) => {
179
         done()
183
         done()
180
       })
184
       })
181
     })
185
     })
182
-
183
 })
186
 })
184
 
187
 
185
 RNTest.config({
188
 RNTest.config({
186
   group : '0.5.1',
189
   group : '0.5.1',
187
   run : true,
190
   run : true,
188
   expand : false,
191
   expand : false,
189
-  timeout : 30000,
192
+  timeout : 600000,
190
 })('Upload and download large file', (report, done) => {
193
 })('Upload and download large file', (report, done) => {
191
   let filename = '22mb-dummy-' + Date.now()
194
   let filename = '22mb-dummy-' + Date.now()
195
+  let begin = -1
196
+  let begin2 = -1
192
   RNFetchBlob.config({
197
   RNFetchBlob.config({
193
     fileCache : true
198
     fileCache : true
194
   })
199
   })
195
   .fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`)
200
   .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
+  // })
196
   .then((res) => {
210
   .then((res) => {
197
     return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
211
     return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
198
       Authorization : `Bearer ${DROPBOX_TOKEN}`,
212
       Authorization : `Bearer ${DROPBOX_TOKEN}`,
199
       'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
213
       'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
200
       'Content-Type' : 'application/octet-stream',
214
       'Content-Type' : 'application/octet-stream',
201
     }, RNFetchBlob.wrap(res.path()))
215
     }, 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
+    // })
202
   })
227
   })
203
   .then((res) => {
228
   .then((res) => {
204
     report(<Assert
229
     report(<Assert
205
-      key="upload should success withou crashing app"
230
+      key="upload should success without crashing app"
206
       expect={filename}
231
       expect={filename}
207
       actual={res.json().name}/>)
232
       actual={res.json().name}/>)
208
     done()
233
     done()
302
       })
327
       })
303
 
328
 
304
   })
329
   })
305
-
306
 })
330
 })

+ 1
- 1
test/test-init.js Näytä tiedosto

50
         done()
50
         done()
51
     })
51
     })
52
 })
52
 })
53
-//
53
+
54
 require('./test-0.1.x-0.4.x')
54
 require('./test-0.1.x-0.4.x')
55
 require('./test-0.5.1')
55
 require('./test-0.5.1')
56
 require('./test-0.5.2')
56
 require('./test-0.5.2')