소스 검색

Change test reporter

Ben Hsieh 8 년 전
부모
커밋
06685e463a
3개의 변경된 파일103개의 추가작업 그리고 73개의 파일을 삭제
  1. 21
    2
      test/react-native-testkit/components/reporter.js
  2. 11
    0
      test/react-native-testkit/lib/test-context.js
  3. 71
    71
      test/test-0.6.2.js

+ 21
- 2
test/react-native-testkit/components/reporter.js 파일 보기

@@ -20,9 +20,10 @@ export default class Reporter extends Component {
20 20
   constructor(props:any) {
21 21
     super(props)
22 22
     this.tests = {
23
+      summary : [{}],
23 24
       common : []
24 25
     }
25
-    this.testGroups = ['common']
26
+    this.testGroups = ['summary','common']
26 27
     this.ds = null
27 28
     this.updateDataSource()
28 29
 
@@ -50,11 +51,29 @@ export default class Reporter extends Component {
50 51
       />)
51 52
   }
52 53
 
53
-  renderTest(t) {
54
+  renderTest(t, group) {
55
+
54 56
     let pass = true
55 57
     let foundActions = false
56 58
     let tests = RNTEST.TestContext.getTests()
57 59
 
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
+
58 77
     if(Array.isArray(t.result) && !t.expired) {
59 78
       t.result = t.result.map((r) => {
60 79
         if(r.type.name === 'Assert' || r.type.name === 'Info') {

+ 11
- 0
test/react-native-testkit/lib/test-context.js 파일 보기

@@ -4,6 +4,7 @@ let tests: Array<TestCase> = []
4 4
 let RCTContext: ReactElement = null
5 5
 let props:any = {}
6 6
 let timeout = 30000
7
+let summary = {}
7 8
 
8 9
 export default class TestContext {
9 10
 
@@ -146,6 +147,16 @@ export default class TestContext {
146 147
   static update(i, ...data) {
147 148
     let test = tests[i]
148 149
     let result = test.result || []
150
+    // if new element have prop `uid`, we should replace it not appending it.
151
+    for(let i in data) {
152
+      if(data[i].props.uid) {
153
+        for(let j in result) {
154
+          if(result[j].uid === data[i].props.uid)
155
+          result[j] = data[i]
156
+          break
157
+        }
158
+      }
159
+    }
149 160
     Object.assign(test, {result : [...result, ...data]})
150 161
     RCTContext.forceUpdate()
151 162
   }

+ 71
- 71
test/test-0.6.2.js 파일 보기

@@ -76,74 +76,74 @@ describe('Upload multipart data with file from CameraRoll', (report, done) => {
76 76
     })
77 77
 })
78 78
 
79
-//
80
-// describe('access assets from camera roll', (report, done) => {
81
-//   let photo = null
82
-//   CameraRoll.getPhotos({first : 10})
83
-//     .then((resp) => {
84
-//       photo = resp.edges[0].node.image.uri
85
-//       report(<Info key="items">
86
-//         <Text>{photo}</Text>
87
-//       </Info>)
88
-//       return fs.readFile(photo, 'base64')
89
-//     })
90
-//     .then((data) => {
91
-//       report(<Info key="asset image">
92
-//         <Image
93
-//           style={styles.image}
94
-//           source={{uri: `data:image/png;base64, ${data}`}}/>
95
-//       </Info>)
96
-//       done()
97
-//     })
98
-// })
99
-//
100
-// describe('read asset in app bundle',(report, done) => {
101
-//   let target = fs.asset('test-asset2.png')
102
-//   fs.readFile(target, 'base64')
103
-//   .then((data) => {
104
-//     report(<Info key="asset image">
105
-//       <Image
106
-//         style={styles.image}
107
-//         source={{uri: `data:image/png;base64, ${data}`}}/>
108
-//     </Info>)
109
-//     return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
110
-//   })
111
-//   .then((resp) => {
112
-//     report(
113
-//       <Assert key="asset content verify"
114
-//         expect="asset#1"
115
-//         actual={JSON.parse(resp).secret}/>)
116
-//       done()
117
-//   })
118
-// })
119
-//
120
-// describe('stat assets in app', (report, done) => {
121
-//   fs.stat(fs.asset('test-asset2.png'))
122
-//     .then((data) => {
123
-//       report(<Info key="list of assets">
124
-//         <Text>{JSON.stringify(data)}</Text>
125
-//       </Info>)
126
-//       done()
127
-//     })
128
-// })
129
-//
130
-// describe('copy asset', (report, done) => {
131
-//   let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
132
-//   fs.cp(fs.asset('test-asset1.json'), dest)
133
-//     .then(() => fs.readFile(dest, 'utf8'))
134
-//     .then((data) => {
135
-//       report(<Assert key="asset copied correctly"
136
-//         expect={'asset#1'}
137
-//         actual={JSON.parse(data).secret}/>)
138
-//       return fs.stat(fs.asset('test-asset1.json'))
139
-//     })
140
-//     .then((stat) => {
141
-//       report(<Assert key="file size check"
142
-//         expect={27}
143
-//         actual={Math.floor(stat.size)}/>,
144
-//       <Info key="dest file info">
145
-//         <Text>{JSON.stringify(stat)}</Text>
146
-//       </Info>)
147
-//       done()
148
-//     })
149
-// })
79
+
80
+describe('access assets from camera roll', (report, done) => {
81
+  let photo = null
82
+  CameraRoll.getPhotos({first : 10})
83
+    .then((resp) => {
84
+      photo = resp.edges[0].node.image.uri
85
+      report(<Info key="items">
86
+        <Text>{photo}</Text>
87
+      </Info>)
88
+      return fs.readFile(photo, 'base64')
89
+    })
90
+    .then((data) => {
91
+      report(<Info key="asset image">
92
+        <Image
93
+          style={styles.image}
94
+          source={{uri: `data:image/png;base64, ${data}`}}/>
95
+      </Info>)
96
+      done()
97
+    })
98
+})
99
+
100
+describe('read asset in app bundle',(report, done) => {
101
+  let target = fs.asset('test-asset2.png')
102
+  fs.readFile(target, 'base64')
103
+  .then((data) => {
104
+    report(<Info key="asset image">
105
+      <Image
106
+        style={styles.image}
107
+        source={{uri: `data:image/png;base64, ${data}`}}/>
108
+    </Info>)
109
+    return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
110
+  })
111
+  .then((resp) => {
112
+    report(
113
+      <Assert key="asset content verify"
114
+        expect="asset#1"
115
+        actual={JSON.parse(resp).secret}/>)
116
+      done()
117
+  })
118
+})
119
+
120
+describe('stat assets in app', (report, done) => {
121
+  fs.stat(fs.asset('test-asset2.png'))
122
+    .then((data) => {
123
+      report(<Info key="list of assets">
124
+        <Text>{JSON.stringify(data)}</Text>
125
+      </Info>)
126
+      done()
127
+    })
128
+})
129
+
130
+describe('copy asset', (report, done) => {
131
+  let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
132
+  fs.cp(fs.asset('test-asset1.json'), dest)
133
+    .then(() => fs.readFile(dest, 'utf8'))
134
+    .then((data) => {
135
+      report(<Assert key="asset copied correctly"
136
+        expect={'asset#1'}
137
+        actual={JSON.parse(data).secret}/>)
138
+      return fs.stat(fs.asset('test-asset1.json'))
139
+    })
140
+    .then((stat) => {
141
+      report(<Assert key="file size check"
142
+        expect={27}
143
+        actual={Math.floor(stat.size)}/>,
144
+      <Info key="dest file info">
145
+        <Text>{JSON.stringify(stat)}</Text>
146
+      </Info>)
147
+      done()
148
+    })
149
+})