Procházet zdrojové kódy

Change testkit reporter

Ben Hsieh před 8 roky
rodič
revize
1aff85267b

+ 51
- 36
test/react-native-testkit/components/reporter.js Zobrazit soubor

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

+ 2
- 1
test/react-native-testkit/lib/test-context.js Zobrazit soubor

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

+ 28
- 4
test/test-0.5.1.js Zobrazit soubor

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

+ 1
- 1
test/test-init.js Zobrazit soubor

@@ -50,7 +50,7 @@ describe('GET image from server', (report, done) => {
50 50
         done()
51 51
     })
52 52
 })
53
-//
53
+
54 54
 require('./test-0.1.x-0.4.x')
55 55
 require('./test-0.5.1')
56 56
 require('./test-0.5.2')