basicTest.uvue 4.5 KB
Newer Older
Y
yurj26 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view class="content">
      <page-head :title="title"></page-head>
      <view v-for="(item, index) in resultArray" :key="index" class="result">
        <view>{{ names[index] }}测试结果:</view>
        <view> 测试api:{{ item.passed.join(', ') }} </view>
        <view>总共:{{ item.total }}</view>
        <view>通过:{{ item.passed.length }}</view>
        <view>失败:{{ item.failed.length }}</view>
        <view v-for="(fail, i) in item.failed" :key="i">
          <text class="failed">{{ fail }}</text>
Y
yurj26 已提交
15
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
16
      </view>
Y
yurj26 已提交
17
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19 20
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
Y
yurj26 已提交
21
</template>
22
<script lang="ts">
23 24
import { runTests, Result } from '../../uni_modules/uts-tests'
// #ifdef APP-IOS
lizhongyi_'s avatar
lizhongyi_ 已提交
25
import { testTypeFromAppJs, Options } from '@/uni_modules/uts-ios-tests';
26 27
// #endif
// #ifdef APP
F
fxy060608 已提交
28
import { onTest1, testKeepAlive, testKeepAliveOption, TestKeepAliveClass, TestKeepAliveOption, } from '@/uni_modules/uts-tests'
29
// #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
30 31 32 33 34 35 36
export default {
  data() {
    return {
      title: 'UTS基础语法',
      resultArray: [] as Result[],
      result: {} as UTSJSONObject,
      names: [] as string[],
Y
yurj26 已提交
37
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39 40 41 42 43
  },
  onReady() {
    this.test()
  },
  methods: {
    test() {
lizhongyi_'s avatar
lizhongyi_ 已提交
44 45 46 47 48 49 50 51 52 53 54
      this.result = runTests()
      // const resultMap = this.result.toMap()
      // resultMap.forEach((res, name) => {
      //   this.names.push(name)
      //   this.resultArray.push(res as Result)
      // })
      const resultMap = this.result
      for (const key in resultMap) {
        this.names.push(key)
        this.resultArray.push(resultMap[key] as Result)
      }
55 56 57 58
    },
    // #ifdef APP-IOS
    jest_testTypeFromAppJs() {
      return testTypeFromAppJs({
59
        num: 1   
60
      } as Options)
lizhongyi_'s avatar
lizhongyi_ 已提交
61 62
    },
    // #endif
63
    // #ifdef APP
lizhongyi_'s avatar
lizhongyi_ 已提交
64
    jest_testCallbackKeepAlive(): boolean {
lizhongyi_'s avatar
lizhongyi_ 已提交
65
      
lizhongyi_'s avatar
lizhongyi_ 已提交
66
        let ret: boolean = true
67 68 69 70 71 72 73 74 75
        let count = 0;
        
        onTest1((res) => {
          count++;
          console.log("onTest1 callback =====> ", res)
        })
        
        if (count < 2) {
          ret = false
lizhongyi_'s avatar
lizhongyi_ 已提交
76
        }
77 78 79 80
        count = 0;
        
        testKeepAlive((res) => {
          count++;
lizhongyi_'s avatar
lizhongyi_ 已提交
81
          console.log(res)
82 83 84 85
        })
        
        if (count < 2) {
          ret = false
lizhongyi_'s avatar
lizhongyi_ 已提交
86
        }
87 88 89 90 91 92 93 94
        count = 0;
        
        testKeepAliveOption({
          a: "testKeepAliveOption",
          success: (res) => {
            count++;
            console.log("testKeepAliveOption callback =====> ", res)
          }
F
fxy060608 已提交
95
        } as TestKeepAliveOption)
96 97 98
        
        if (count < 2) {
          ret = false
lizhongyi_'s avatar
lizhongyi_ 已提交
99
        }
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
        count = 0;
        
        TestKeepAliveClass.onTestStatic((res) => {
          count++;
          console.log("onTestStatic callback =====> ", res)
        })
        
        if (count < 2) {
          ret = false
        }
        count = 0;
        
        TestKeepAliveClass.testKeepAliveStatic((res) => {
          count++;
          console.log("testKeepAliveStatic callback =====> ", res)
        })
        
        if (count < 2) {
          ret = false
        }
        count = 0;
        
        TestKeepAliveClass.testKeepAliveOptionStatic({
          a: "testKeepAliveOption",
          success: (res) => {
            count++;
            console.log("testKeepAliveOptionStatic callback =====> ", res)
          }
F
fxy060608 已提交
128
        } as TestKeepAliveOption)
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
        
        if (count < 2) {
          ret = false
        }
        count = 0;
        
        const obj = new TestKeepAliveClass()
        obj.onTest((res) => {
          count++;
          console.log("TestKeepAliveClass.onTest callback =====> ", res)
        })
        
        if (count < 2) {
          ret = false
        }
        count = 0;
        
        obj.testKeepAlive((res) => {
          count++;
          console.log("TestKeepAliveClass.testKeepAlive callback =====> ", res)
        })
        
        if (count < 2) {
          ret = false
        }
        count = 0;
        
        obj.testKeepAliveOption({
          a: "testKeepAliveOption",
          success: (res) => {
            count++;
            console.log("TestKeepAliveClass.testKeepAliveOption callback =====> ", res)
          }
F
fxy060608 已提交
162
        } as TestKeepAliveOption)
163 164 165 166
        if (count < 2) {
          ret = false
        }
        return ret
167 168
    }
    // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
169 170
  },
}
Y
yurj26 已提交
171
</script>
DCloud-WZF's avatar
DCloud-WZF 已提交
172 173 174 175 176
<style>
@import '@/common/uni-uvue.css';
.content {
  padding: 32rpx;
}
Y
yurj26 已提交
177

DCloud-WZF's avatar
DCloud-WZF 已提交
178 179 180
.passed {
  color: green;
}
Y
yurj26 已提交
181

DCloud-WZF's avatar
DCloud-WZF 已提交
182 183 184
.failed {
  color: red;
}
Y
yurj26 已提交
185

DCloud-WZF's avatar
DCloud-WZF 已提交
186 187 188 189
.result {
  margin-bottom: 20rpx;
}
</style>