Ingen beskrivning

reporter.js 2.5KB

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