Açıklama Yok

reporter.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React, {Component} from 'react';
  2. import {
  3. AppRegistry,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Platform,
  8. ScrollView,
  9. Image,
  10. } from 'react-native';
  11. import Assert from './assert.js'
  12. import RNTEST from '../index.js'
  13. export default class Reporter extends Component {
  14. render() {
  15. return (
  16. <ScrollView key="rn-test-scroller" style={styles.container}>
  17. {this.renderTests()}
  18. </ScrollView>)
  19. }
  20. renderTests() {
  21. let tests = RNTEST.TestContext.getTests()
  22. return tests.map((t, i) => {
  23. let pass = true
  24. let foundActions = false
  25. if(Array.isArray(t.result) && !t.expired) {
  26. t.result = t.result.map((r) => {
  27. if(r.type.name === 'Assert' || r.type.name === 'Info') {
  28. foundActions = true
  29. let comp = r.props.comparer ? r.props.comparer(r.props.expect, r.props.actual) : (r.props.actual === r.props.expect)
  30. pass = pass && comp
  31. }
  32. return React.cloneElement(r, {desc : r.key})
  33. })
  34. }
  35. if(tests[i].running)
  36. t.status = 'running'
  37. else if(tests[i].executed) {
  38. t.status = foundActions ? (pass ? 'pass' : 'fail') : 'skipped'
  39. t.status = t.expired ? 'timeout' : t.status
  40. }
  41. else
  42. t.status = 'waiting'
  43. return (<View key={'rn-test-' + t.desc} style={{
  44. borderBottomWidth : 1.5,
  45. borderColor : '#DDD',
  46. }}>
  47. <View key={t.desc} style={{
  48. alignItems : 'center',
  49. flexDirection : 'row'
  50. }}>
  51. <Text style={[styles.badge, {flex : 1, borderWidth : 0, textAlign : 'left'}]}>{t.desc}</Text>
  52. <Text style={[styles.badge, this.getBadge(t.status)]}>{t.status}</Text>
  53. </View>
  54. <View key={t.desc + '-result'} style={{backgroundColor : '#F4F4F4'}}>
  55. {t.result}
  56. </View>
  57. </View>)
  58. })
  59. }
  60. getBadge(status: 'waiting' | 'running' | 'pass' | 'fail' | 'timeout') {
  61. return styles[status]
  62. }
  63. }
  64. const styles = StyleSheet.create({
  65. container: {
  66. flex: 1,
  67. marginTop : 40,
  68. },
  69. badge : {
  70. margin : 16,
  71. padding : 4,
  72. borderRadius : 4,
  73. borderWidth : 2,
  74. textAlign : 'center'
  75. },
  76. skipped: {
  77. borderColor : '#AAAAAA',
  78. color : '#AAAAAA'
  79. },
  80. waiting: {
  81. borderColor : '#AAAAAA',
  82. color : '#AAAAAA'
  83. },
  84. pass: {
  85. borderColor : '#00a825',
  86. color : '#00a825'
  87. },
  88. running: {
  89. borderColor : '#e3c423',
  90. color : '#e3c423'
  91. },
  92. fail: {
  93. borderColor : '#ff0d0d',
  94. color : '#ff0d0d'
  95. },
  96. timeout: {
  97. borderColor : '#ff0d0d',
  98. color : '#ff0d0d'
  99. }
  100. });