basicTest.uvue 5.8 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 29
import { onTest1, testKeepAlive, testKeepAliveOption, createTest, TestKeepAliveClass, TestKeepAliveOption, } from '@/uni_modules/uts-tests'
import { testNonKeepAlive, testNonKeepAliveOption } from '@/uni_modules/uts-tests'
30
// #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
31 32 33 34 35 36
export default {
  data() {
    return {
      title: 'UTS基础语法',
      resultArray: [] as Result[],
      result: {} as UTSJSONObject,
F
fxy060608 已提交
37 38 39
      names: [] as string[],
      keepAliveCount: 0,
      nonKeepAliveCount: 0
Y
yurj26 已提交
40
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
41 42 43 44 45 46
  },
  onReady() {
    this.test()
  },
  methods: {
    test() {
lizhongyi_'s avatar
lizhongyi_ 已提交
47 48 49 50 51 52 53 54 55 56
      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)
F
fxy060608 已提交
57 58 59 60 61 62
      }
      console.log('jest_testCallbackKeepAlive:' + this.jest_testCallbackKeepAlive())
      this.jest_testCallbackNonKeepAlive().then(res=>{
       console.log('jest_testCallbackNonKeepAlive:' + res)  
      })
      
63 64 65 66
    },
    // #ifdef APP-IOS
    jest_testTypeFromAppJs() {
      return testTypeFromAppJs({
67
        num: 1   
68
      } as Options)
lizhongyi_'s avatar
lizhongyi_ 已提交
69 70
    },
    // #endif
71
    // #ifdef APP
lizhongyi_'s avatar
lizhongyi_ 已提交
72
    jest_testCallbackKeepAlive(): boolean {
lizhongyi_'s avatar
lizhongyi_ 已提交
73
      
lizhongyi_'s avatar
lizhongyi_ 已提交
74
        let ret: boolean = true
75 76 77 78 79 80 81 82 83
        let count = 0;
        
        onTest1((res) => {
          count++;
          console.log("onTest1 callback =====> ", res)
        })
        
        if (count < 2) {
          ret = false
lizhongyi_'s avatar
lizhongyi_ 已提交
84
        }
85 86 87 88
        count = 0;
        
        testKeepAlive((res) => {
          count++;
lizhongyi_'s avatar
lizhongyi_ 已提交
89
          console.log(res)
90 91 92 93
        })
        
        if (count < 2) {
          ret = false
lizhongyi_'s avatar
lizhongyi_ 已提交
94
        }
95 96 97 98 99 100 101 102
        count = 0;
        
        testKeepAliveOption({
          a: "testKeepAliveOption",
          success: (res) => {
            count++;
            console.log("testKeepAliveOption callback =====> ", res)
          }
F
fxy060608 已提交
103
        } as TestKeepAliveOption)
104 105 106
        
        if (count < 2) {
          ret = false
lizhongyi_'s avatar
lizhongyi_ 已提交
107
        }
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        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 已提交
136
        } as TestKeepAliveOption)
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 162 163 164 165 166 167 168 169
        
        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 已提交
170
        } as TestKeepAliveOption)
171 172 173
        if (count < 2) {
          ret = false
        }
F
fxy060608 已提交
174 175 176 177 178 179 180 181 182 183
        count = 0;
        const testImpl = createTest()
        testImpl.test((res) => {
          count++;
          console.log("TestImpl.test callback =====> ", res)
        })
        if (count < 2) {
          ret = false
        }
        this.keepAliveCount = count
184
        return ret
F
fxy060608 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    },
    jest_testCallbackNonKeepAlive(): Promise<number> {
      let count = 0
      const fn = (res:string) => {
        count++;
        console.log("testCallbackNonKeepAlive callback =====> ", res)
      }
      testNonKeepAlive(fn)
      testNonKeepAlive(fn)
      const options: TestKeepAliveOption = {
        a:'a',
        success(res:string){
          count++;
          console.log("testCallbackNonKeepAliveOption callback =====> ", res)
        }
      }
      testNonKeepAliveOption(options)
      testNonKeepAliveOption(options)
      return new Promise((resolve)=>{
        setTimeout(()=>{
          this.nonKeepAliveCount = count
          resolve(count)
        },50)
      })
209 210
    }
    // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
211 212
  },
}
Y
yurj26 已提交
213
</script>
DCloud-WZF's avatar
DCloud-WZF 已提交
214 215 216 217 218
<style>
@import '@/common/uni-uvue.css';
.content {
  padding: 32rpx;
}
Y
yurj26 已提交
219

DCloud-WZF's avatar
DCloud-WZF 已提交
220 221 222
.passed {
  color: green;
}
Y
yurj26 已提交
223

DCloud-WZF's avatar
DCloud-WZF 已提交
224 225 226
.failed {
  color: red;
}
Y
yurj26 已提交
227

DCloud-WZF's avatar
DCloud-WZF 已提交
228 229 230 231
.result {
  margin-bottom: 20rpx;
}
</style>