Skip to content

Commit

Permalink
零代码回归测试:解决 Response JSON 超过 2 层的 key 光标悬浮注释路径错误,断言总是漏报等
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Nov 7, 2024
1 parent 3338745 commit 987af25
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apijson/CodeUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var CodeUtil = {
if (isExtract && standardObj != null && (isReq || depth != 1
|| [JSONResponse.KEY_CODE, JSONResponse.KEY_MSG, JSONResponse.KEY_THROW].indexOf(key) < 0)) {
comment = line.substring(cIndex + ccLen).trim();
// standardObj = CodeUtil.updateStandardPart(standardObj, names, key, value, comment)
// standardObj = CodeUtil.updateStandardByPath(standardObj, names, key, value, comment)
}

line = line.substring(0, cIndex).trim();
Expand Down
2 changes: 1 addition & 1 deletion apijson/JSONResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ var JSONResponse = {
return null;
}

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

return target;
},
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
" >
{
"User": {
"id": 82001
"id": "82001"
}, // 以上查一个对象,以下查一个数组,Comment.userId = User.id。在键值对后按 Enter 回车键自动智能生成补全提示
"[]": {
Comment : {
Expand Down Expand Up @@ -918,7 +918,7 @@
<script type="text/x-template" id="item-template">
<ul class="json-item">
<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_$_) || {})"
v-show="onRenderJSONItem(val, key, thiz == null ? null : thiz._$_path_$_)"
v-show="onRenderJSONItem(val, key, (JSONResponse.isObject(jsondata) != true || StringUtil.isEmpty(jsondata._$_this_$_, true) ? {} : (thiz || JSON.parse(jsondata._$_this_$_) || {}))._$_path_$_)"
v-for="(val, key, index) in jsondata"></vue-val>
</ul>
</script>
Expand Down
132 changes: 117 additions & 15 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@
if (val[0] instanceof Object && (val[0] instanceof Array == false)) { // && JSONObject.isArrayKey(key, null, isRestful)) {
// alert('onRenderJSONItem key = ' + key + '; val = ' + JSON.stringify(val))

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

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

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

for (var i = 0; i < val.length; i++) {
Expand Down Expand Up @@ -239,7 +239,7 @@
var pathKeys = StringUtil.split(pathUri, '/');
var target = App.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
var real = JSONResponse.getValByPath(responseObj, pathKeys);
var cmp = App.isMLEnabled ? JSONResponse.compareWithStandard(target, real, path) : JSONResponse.compareWithBefore(target, real, path);
var cmp = App.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
cmp.path = pathUri;
var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
Expand Down Expand Up @@ -270,7 +270,7 @@
}
}
else if (val instanceof Object) {
var aliaIndex = key.indexOf(':');
var aliaIndex = key == null ? -1 : key.indexOf(':');
var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);

// var newVal = JSON.parse(JSON.stringify(val))
Expand Down Expand Up @@ -299,7 +299,7 @@
var target = App.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
var real = JSONResponse.getValByPath(responseObj, pathKeys);
// c = JSONResponse.compareWithBefore(target, real, path);
var cmp = App.isMLEnabled ? JSONResponse.compareWithStandard(target, real, path) : JSONResponse.compareWithBefore(target, real, path);
var cmp = App.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
cmp.path = pathUri;
var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
Expand Down Expand Up @@ -1519,16 +1519,118 @@ https://github.com/Tencent/APIJSON/issues
} catch (ex) {
log(ex)
}

var path = null;
var key = null;
var thiz = {
_$_path_$_: null,
_$_table_$_: null
};

if (isSingle || ret instanceof Array || (ret instanceof Object == false)) {
this.jsonhtml = ret
var val = ret;
if (isSingle != true && val instanceof Array && val[0] instanceof Object && (val[0] instanceof Array == false)) {
// alert('onRenderJSONItem key = ' + key + '; val = ' + JSON.stringify(val))
var ckey = key == null ? null : key.substring(0, key.lastIndexOf('[]'));

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

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

for (var i = 0; i < val.length; i++) {
var vi = val[i]

if (vi instanceof Object && vi instanceof Array == false && JSONObject.isTableKey(firstKey, val, isRestful)) {
// var newVal = JSON.parse(JSON.stringify(val[i]))
if (vi == null) {
continue
}

var curPath = '' + i;
var curTable = firstKey;
var thiz = {
_$_path_$_: curPath,
_$_table_$_: curTable
};

var newVal = {};
for (var k in vi) {
newVal[k] = vi[k]; //提升性能
if (this.isFullAssert) {
try {
var tr = this.currentRemoteItem.TestRecord || {};
var d = this.currentRemoteItem.Document || {};
var standard = this.isMLEnabled ? tr.standard : tr.response;
var standardObj = StringUtil.isEmpty(standard, true) ? null : JSON.parse(standard);
var tests = this.tests[String(this.currentAccountIndex)] || {};
var responseObj = (tests[d.id] || {})[0]

var pathUri = (StringUtil.isEmpty(curPath, false) ? '' : curPath + '/') + k;
var pathKeys = StringUtil.split(pathUri, '/');
var target = this.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
var real = JSONResponse.getValByPath(responseObj, pathKeys);
var cmp = this.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
cmp.path = pathUri;
var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
var countKey = '_$_' + cmpShowObj.compareColor + 'Count_$_';
thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
} catch (e) {
thiz[k] = [JSONResponse.COMPARE_ERROR, 'red', e.message];
var countKey = '_$_redCount_$_';
thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
}
}

delete vi[k]
}

vi._$_this_$_ = JSON.stringify(thiz)
for (var k in newVal) {
vi[k] = newVal[k]
}
}

}
}

this.jsonhtml = val;
}
else {
this.jsonhtml = Object.assign({
_$_this_$_: JSON.stringify({
_$_path_$_: null,
_$_table_$_: null
})
}, ret)
for (var k in ret) {
if (this.isFullAssert) {
try {
var tr = this.currentRemoteItem.TestRecord || {};
var d = this.currentRemoteItem.Document || {};
var standard = this.isMLEnabled ? tr.standard : tr.response;
var standardObj = StringUtil.isEmpty(standard, true) ? null : JSON.parse(standard);
var tests = this.tests[String(this.currentAccountIndex)] || {};
var responseObj = (tests[d.id] || {})[0]

var pathUri = k;
var pathKeys = StringUtil.split(pathUri, '/');
var target = this.isMLEnabled ? JSONResponse.getStandardByPath(standardObj, pathKeys) : JSONResponse.getValByPath(standardObj, pathKeys);
var real = JSONResponse.getValByPath(responseObj, pathKeys);
// c = JSONResponse.compareWithBefore(target, real, path);
var cmp = this.isMLEnabled ? JSONResponse.compareWithStandard(target, real, pathUri) : JSONResponse.compareWithBefore(target, real, pathUri);
cmp.path = pathUri;
var cmpShowObj = JSONResponse.getCompareShowObj(cmp);
thiz[k] = [cmpShowObj.compareType, cmpShowObj.compareColor, cmpShowObj.compareMessage];
var countKey = '_$_' + cmpShowObj.compareColor + 'Count_$_';
thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
} catch (e) {
thiz[k] = [JSONResponse.COMPARE_ERROR, 'red', e.message];
var countKey = '_$_redCount_$_';
thiz[countKey] = thiz[countKey] == null ? 1 : thiz[countKey] + 1;
}
}
}

this.jsonhtml = Object.assign({
_$_this_$_: JSON.stringify(thiz)
}, ret)
}

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

if (isInputValue != true) {
App.showOptions(target, text, before + name + (isSingle ? "'" : '"') + ': ', after.substring(3), true);
this.showOptions(target, text, before + name + (isSingle ? "'" : '"') + ': ', after.substring(3), true);
}
} else {
target.selectionStart = selectionStart;
Expand Down
2 changes: 2 additions & 0 deletions js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ app.use(async ctx => {
ctx.set('Access-Control-Allow-Headers', "*");
ctx.set('Access-Control-Allow-Credentials', 'true');
ctx.set('Access-Control-Allow-Methods', 'GET,HEAD,POST,PUT,DELETE,OPTIONS,TRACE');
// ctx.set('Access-Control-Expose-Headers', "*");

if (ctx.method == null || ctx.method.toUpperCase() == 'OPTIONS') {
ctx.status = 200;
return;
}

if (ctx.path == '/test/start' || (isLoading != true && ctx.path == '/test')) {
if (isLoading && ctx.path == '/test/start') {
ctx.status = 200;
Expand Down

0 comments on commit 987af25

Please sign in to comment.