-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ux
More file actions
249 lines (222 loc) · 6.65 KB
/
Copy pathindex.ux
File metadata and controls
249 lines (222 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
128
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<template>
<div class="page-summary-root">
<div style="flex-direction: column;">
<div class="page-summary-desc" onclick="restartTestProcess()">
<text>点击重新测试</text>
</div>
<div class="page-item" for="{{pageTestList}}">
<div class="page-item-summary">
<text class="page-item-summary-num-name">
<span>{{$item.stats.title}}</span>
</text>
<text onclick="togglePageTestDetailStatus($item)">
<span class="page-item-summary-num-total">结果:{{$item.stats.tests}}:</span>
<span class="page-item-summary-num-pass">({{$item.stats.passes}}:</span>
<span class="page-item-summary-num-fail">{{$item.stats.failures}})</span>
</text>
</div>
<div class="page-item-caselist" show="{{!!$item.showPageTestDetail}}">
<div class="case-item {{!$item.err.message ? 'case-item-pass' : 'case-item-fail' }}" for="{{$item.tests}}">
<text class="case-item-title" onclick="togglePageErrStackStatus($item)">{{$item.title}}</text>
<text if="{{$item.err.message}}" show="{{!!$item.showPageTestErrDetail}}">{{$item.err.stack}}</text>
</div>
</div>
</div>
<div class="page-summary-desc" show="{{showCompletedText}}" style="background-color: #d9d7d6;">
<text>所有测试已结束</text>
</div>
<div class="page-summary-desc" style="background-color: #d9d7d6; margin-top: 60px;">
<text>测试的页面列表</text>
</div>
<div class="page-item" for="{{pageNameList}}">
<div class="page-item-summary" onclick="gotoPage($item.name, $item.params)">
<text>{{$item.title}} : {{$item.name}}</text>
</div>
</div>
<div class="page-summary-desc" if="{{hasIstanbulCoverage}}" onclick="saveIstanbulCoverageData" style="background-color: #d9d7d6; margin-top: 60px;">
<text>保存代码覆盖率数据</text>
</div>
</div>
</div>
</template>
<script>
import router from '@system.router'
import fetch from '@system.fetch'
import prompt from '@system.prompt'
import {
autoCaseList
} from '../../test/autocase'
/**
* 获取下一个自动测试的page
*/
function findNextTestPage() {
const list = global.loadData('pageNameList')
const item = list.shift()
global.saveData('pageNameList', list)
return item
}
function waitForOK(time = 100) {
return new Promise(resolve => {
setTimeout(resolve, time)
})
}
function checkIstanbulCoverage () {
return !!global.__coverage__
}
export default {
private: {
// 包含自动测试脚本的case列表
pageNameList: [],
pageTestList: [],
shouldTestAll: false,
showCompletedText: false,
isRunningTest: false,
hasIstanbulCoverage: false
},
onInit() {
this.pageNameList = autoCaseList
// 初始化自动化测试相关数据
if (global.loadData) {
global.saveData('pageNameList', this.pageNameList)
}
// 是否启用了代码覆盖率工具
this.hasIstanbulCoverage = checkIstanbulCoverage()
},
onShow() {
// 更新pageTestList
this.pageTestList = (global.loadData('pageTestList') || []).map(item => {
item.showPageTestDetail = false
item.tests.forEach(itemCase => {
itemCase.showPageTestErrDetail = false
})
return item
})
this.shouldTestAll && this.startNextTestPage()
},
/**
* 重启整个所有测试
*/
restartTestProcess() {
// 防止连续多次点击
if (!this.isRunningTest) {
this.isRunningTest = true
global.saveData('pageNameList', this.pageNameList)
global.saveData('pageTestList', [])
this.pageTestList = []
// 重置测试结束文本的显示状态
this.showCompletedText = false
// 自动跑测试下一个测试用例
this.shouldTestAll = true
// 启动下个测试用例
this.startNextTestPage()
}
},
/**
* 启动下个测试用例
*/
async startNextTestPage() {
const pageItem = findNextTestPage()
if (pageItem) {
console.info(`下个测试用例:${pageItem.title}:${pageItem.name}`)
await waitForOK(1000)
console.info(`开始测试页面:${pageItem.title}:${pageItem.name}`)
router.push({
uri: pageItem.name,
params: pageItem.params
})
} else {
console.info(`测试用例列表执行完毕`)
this.isRunningTest = false
this.showCompletedText = true
this.shouldTestAll = false
}
},
gotoPage(path, params) {
// 单个页面的点击跳转:不会在测试后,自动返回
params = Object.assign({
back: 'false'
}, params)
router.push({
uri: path,
params
})
},
togglePageTestDetailStatus($item) {
$item.showPageTestDetail = !$item.showPageTestDetail
},
togglePageErrStackStatus($item) {
$item.showPageTestErrDetail = !$item.showPageTestErrDetail
},
// 保存在项目目录下
saveIstanbulCoverageData () {
// 代码覆盖率的数据
const dataCoverage = global.__coverage__
// TODO:记得更新到您的PC服务器地址
fetch.fetch({
url: `http://10.221.130.186:8000/data/coverage`,
method: 'POST',
data: {
coverage: dataCoverage
},
header: {
'Content-Type': 'application/json'
},
success: () => {
prompt.showToast({ message: `保存成功` })
},
fail: (err) => {
prompt.showToast({ message: `保存失败:${JSON.stringify(err)}` })
}
})
}
}
</script>
<style>
.page-summary-root {
background-color: #fbf9fe;
flex: 1;
flex-direction: column;
}
.page-summary-desc {
padding: 20px;
justify-content: center;
background-color: #ffe4c4;
}
.page-item {
flex-direction: column;
}
.page-item-summary {
padding: 20px;
background-color: #efebc6;
}
.page-item-summary-num-name {
font-weight: bold;
margin-right: 40px;
}
.page-item-summary-num-total {
margin-right: 20px;
}
.page-item-summary-num-pass {
margin-right: 20px;
color: #008000;
}
.page-item-summary-num-fail {
margin-right: 20px;
color: #FF0000;
}
.page-item-caselist {
flex-direction: column;
margin-top: 10px;
}
.case-item {
flex-direction: column;
padding: 10px 50px;
margin-bottom: 5px;
}
.case-item-pass {
background-color: #008000;
}
.case-item-fail {
background-color: #FF0000;
}
</style>