Skip to content

Commit 987af25

Browse files
committed
零代码回归测试:解决 Response JSON 超过 2 层的 key 光标悬浮注释路径错误,断言总是漏报等
1 parent 3338745 commit 987af25

File tree

5 files changed

+123
-19
lines changed

5 files changed

+123
-19
lines changed

apijson/CodeUtil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var CodeUtil = {
135135
if (isExtract && standardObj != null && (isReq || depth != 1
136136
|| [JSONResponse.KEY_CODE, JSONResponse.KEY_MSG, JSONResponse.KEY_THROW].indexOf(key) < 0)) {
137137
comment = line.substring(cIndex + ccLen).trim();
138-
// standardObj = CodeUtil.updateStandardPart(standardObj, names, key, value, comment)
138+
// standardObj = CodeUtil.updateStandardByPath(standardObj, names, key, value, comment)
139139
}
140140

141141
line = line.substring(0, cIndex).trim();

apijson/JSONResponse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ var JSONResponse = {
17581758
return null;
17591759
}
17601760

1761-
tgt[pathKeys[pathKeys.length - 1]] = val;
1761+
tgt[pathKeys[depth - 1]] = val;
17621762

17631763
return target;
17641764
},

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@
370370
" >
371371
{
372372
"User": {
373-
"id": 82001
373+
"id": "82001"
374374
}, // 以上查一个对象,以下查一个数组,Comment.userId = User.id。在键值对后按 Enter 回车键自动智能生成补全提示
375375
"[]": {
376376
Comment : {
@@ -918,7 +918,7 @@
918918
<script type="text/x-template" id="item-template">
919919
<ul class="json-item">
920920
<vue-val :theme="theme" :field="key" :val="val" :isend="index == objLength(jsondata) - 1" :thiz="JSONResponse.isObject(jsondata) != true || StringUtil.isEmpty(jsondata._$_this_$_, true) ? {} : (JSON.parse(jsondata._$_this_$_) || {})"
921-
v-show="onRenderJSONItem(val, key, thiz == null ? null : thiz._$_path_$_)"
921+
v-show="onRenderJSONItem(val, key, (JSONResponse.isObject(jsondata) != true || StringUtil.isEmpty(jsondata._$_this_$_, true) ? {} : (thiz || JSON.parse(jsondata._$_this_$_) || {}))._$_path_$_)"
922922
v-for="(val, key, index) in jsondata"></vue-val>
923923
</ul>
924924
</script>

js/main.js

Lines changed: 117 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@
197197
if (val[0] instanceof Object && (val[0] instanceof Array == false)) { // && JSONObject.isArrayKey(key, null, isRestful)) {
198198
// alert('onRenderJSONItem key = ' + key + '; val = ' + JSON.stringify(val))
199199

200-
var ckey = key.substring(0, key.lastIndexOf('[]'));
200+
var ckey = key == null ? null : key.substring(0, key.lastIndexOf('[]'));
201201

202-
var aliaIndex = ckey.indexOf(':');
202+
var aliaIndex = ckey == null ? -1 : ckey.indexOf(':');
203203
var objName = aliaIndex < 0 ? ckey : ckey.substring(0, aliaIndex);
204204

205-
var firstIndex = objName.indexOf('-');
205+
var firstIndex = objName == null ? -1 : objName.indexOf('-');
206206
var firstKey = firstIndex < 0 ? objName : objName.substring(0, firstIndex);
207207

208208
for (var i = 0; i < val.length; i++) {
@@ -239,7 +239,7 @@
239239
var pathKeys = StringUtil.split(pathUri, '/');
240240
var target = App.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
241241
var real = JSONResponse.getValByPath(responseObj, pathKeys);
242-
var cmp = App.isMLEnabled ? JSONResponse.compareWithStandard(target, real, path) : JSONResponse.compareWithBefore(target, real, path);
242+
var cmp = App.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
243243
cmp.path = pathUri;
244244
var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
245245
thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
@@ -270,7 +270,7 @@
270270
}
271271
}
272272
else if (val instanceof Object) {
273-
var aliaIndex = key.indexOf(':');
273+
var aliaIndex = key == null ? -1 : key.indexOf(':');
274274
var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
275275

276276
// var newVal = JSON.parse(JSON.stringify(val))
@@ -299,7 +299,7 @@
299299
var target = App.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
300300
var real = JSONResponse.getValByPath(responseObj, pathKeys);
301301
// c = JSONResponse.compareWithBefore(target, real, path);
302-
var cmp = App.isMLEnabled ? JSONResponse.compareWithStandard(target, real, path) : JSONResponse.compareWithBefore(target, real, path);
302+
var cmp = App.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
303303
cmp.path = pathUri;
304304
var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
305305
thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
@@ -1519,16 +1519,118 @@ https://github.com/Tencent/APIJSON/issues
15191519
} catch (ex) {
15201520
log(ex)
15211521
}
1522+
1523+
var path = null;
1524+
var key = null;
1525+
var thiz = {
1526+
_$_path_$_: null,
1527+
_$_table_$_: null
1528+
};
1529+
15221530
if (isSingle || ret instanceof Array || (ret instanceof Object == false)) {
1523-
this.jsonhtml = ret
1531+
var val = ret;
1532+
if (isSingle != true && val instanceof Array && val[0] instanceof Object && (val[0] instanceof Array == false)) {
1533+
// alert('onRenderJSONItem key = ' + key + '; val = ' + JSON.stringify(val))
1534+
var ckey = key == null ? null : key.substring(0, key.lastIndexOf('[]'));
1535+
1536+
var aliaIndex = ckey == null ? -1 : ckey.indexOf(':');
1537+
var objName = aliaIndex < 0 ? ckey : ckey.substring(0, aliaIndex);
1538+
1539+
var firstIndex = objName == null ? -1 : objName.indexOf('-');
1540+
var firstKey = firstIndex < 0 ? objName : objName.substring(0, firstIndex);
1541+
1542+
for (var i = 0; i < val.length; i++) {
1543+
var vi = val[i]
1544+
1545+
if (vi instanceof Object && vi instanceof Array == false && JSONObject.isTableKey(firstKey, val, isRestful)) {
1546+
// var newVal = JSON.parse(JSON.stringify(val[i]))
1547+
if (vi == null) {
1548+
continue
1549+
}
1550+
1551+
var curPath = '' + i;
1552+
var curTable = firstKey;
1553+
var thiz = {
1554+
_$_path_$_: curPath,
1555+
_$_table_$_: curTable
1556+
};
1557+
1558+
var newVal = {};
1559+
for (var k in vi) {
1560+
newVal[k] = vi[k]; //提升性能
1561+
if (this.isFullAssert) {
1562+
try {
1563+
var tr = this.currentRemoteItem.TestRecord || {};
1564+
var d = this.currentRemoteItem.Document || {};
1565+
var standard = this.isMLEnabled ? tr.standard : tr.response;
1566+
var standardObj = StringUtil.isEmpty(standard, true) ? null : JSON.parse(standard);
1567+
var tests = this.tests[String(this.currentAccountIndex)] || {};
1568+
var responseObj = (tests[d.id] || {})[0]
1569+
1570+
var pathUri = (StringUtil.isEmpty(curPath, false) ? '' : curPath + '/') + k;
1571+
var pathKeys = StringUtil.split(pathUri, '/');
1572+
var target = this.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
1573+
var real = JSONResponse.getValByPath(responseObj, pathKeys);
1574+
var cmp = this.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
1575+
cmp.path = pathUri;
1576+
var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
1577+
thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
1578+
var countKey = '_$_' + cmpShowObj.compareColor + 'Count_$_';
1579+
thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
1580+
} catch (e) {
1581+
thiz[k] = [JSONResponse.COMPARE_ERROR, 'red', e.message];
1582+
var countKey = '_$_redCount_$_';
1583+
thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
1584+
}
1585+
}
1586+
1587+
delete vi[k]
1588+
}
1589+
1590+
vi._$_this_$_ = JSON.stringify(thiz)
1591+
for (var k in newVal) {
1592+
vi[k] = newVal[k]
1593+
}
1594+
}
1595+
1596+
}
1597+
}
1598+
1599+
this.jsonhtml = val;
15241600
}
15251601
else {
1526-
this.jsonhtml = Object.assign({
1527-
_$_this_$_: JSON.stringify({
1528-
_$_path_$_: null,
1529-
_$_table_$_: null
1530-
})
1531-
}, ret)
1602+
for (var k in ret) {
1603+
if (this.isFullAssert) {
1604+
try {
1605+
var tr = this.currentRemoteItem.TestRecord || {};
1606+
var d = this.currentRemoteItem.Document || {};
1607+
var standard = this.isMLEnabled ? tr.standard : tr.response;
1608+
var standardObj = StringUtil.isEmpty(standard, true) ? null : JSON.parse(standard);
1609+
var tests = this.tests[String(this.currentAccountIndex)] || {};
1610+
var responseObj = (tests[d.id] || {})[0]
1611+
1612+
var pathUri = k;
1613+
var pathKeys = StringUtil.split(pathUri, '/');
1614+
var target = this.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
1615+
var real = JSONResponse.getValByPath(responseObj, pathKeys);
1616+
// c = JSONResponse.compareWithBefore(target, real, path);
1617+
var cmp = this.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
1618+
cmp.path = pathUri;
1619+
var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
1620+
thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
1621+
var countKey = '_$_' + cmpShowObj.compareColor + 'Count_$_';
1622+
thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
1623+
} catch (e) {
1624+
thiz[k] = [JSONResponse.COMPARE_ERROR, 'red', e.message];
1625+
var countKey = '_$_redCount_$_';
1626+
thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
1627+
}
1628+
}
1629+
}
1630+
1631+
this.jsonhtml = Object.assign({
1632+
_$_this_$_: JSON.stringify(thiz)
1633+
}, ret)
15321634
}
15331635

15341636
}
@@ -1844,7 +1946,7 @@ https://github.com/Tencent/APIJSON/issues
18441946
var name = item == null ? '' : StringUtil.get(item.name);
18451947
target.value = text = before + name + after
18461948
if (target == vScript) { // 不这样会自动回滚
1847-
App.scripts[App.scriptType][App.scriptBelongId][App.isPreScript ? 'pre' : 'post'].script = text
1949+
this.scripts[this.scriptType][this.scriptBelongId][this.isPreScript ? 'pre' : 'post'].script = text
18481950
}
18491951
else if (target == vInput) {
18501952
inputted = target.value;
@@ -1870,7 +1972,7 @@ https://github.com/Tencent/APIJSON/issues
18701972
}
18711973

18721974
if (isInputValue != true) {
1873-
App.showOptions(target, text, before + name + (isSingle ? "'" : '"') + ': ', after.substring(3), true);
1975+
this.showOptions(target, text, before + name + (isSingle ? "'" : '"') + ': ', after.substring(3), true);
18741976
}
18751977
} else {
18761978
target.selectionStart = selectionStart;

js/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ app.use(async ctx => {
7979
ctx.set('Access-Control-Allow-Headers', "*");
8080
ctx.set('Access-Control-Allow-Credentials', 'true');
8181
ctx.set('Access-Control-Allow-Methods', 'GET,HEAD,POST,PUT,DELETE,OPTIONS,TRACE');
82+
// ctx.set('Access-Control-Expose-Headers', "*");
8283

8384
if (ctx.method == null || ctx.method.toUpperCase() == 'OPTIONS') {
8485
ctx.status = 200;
8586
return;
8687
}
88+
8789
if (ctx.path == '/test/start' || (isLoading != true && ctx.path == '/test')) {
8890
if (isLoading && ctx.path == '/test/start') {
8991
ctx.status = 200;

0 commit comments

Comments
 (0)