|
354 | 354 | */ |
355 | 355 | Vue.prototype.setResponseHint = function (val, key, $event, isAssert, color, isDynamic) { |
356 | 356 | console.log('setResponseHint') |
| 357 | + var responseKey = this.$refs.responseKey |
| 358 | + if (responseKey == null) { |
| 359 | + return |
| 360 | + } |
| 361 | + |
357 | 362 | if (! isDynamic) { |
358 | 363 | CodeUtil.tableList = (docObj || {})['[]'] || CodeUtil.tableList; |
359 | 364 | } |
360 | | - this.$refs.responseKey.setAttribute('data-hint', isSingle ? '' : this.getResponseHint(val, key, $event, isAssert, color, isDynamic)); |
| 365 | + responseKey.setAttribute('data-hint', isSingle ? '' : this.getResponseHint(val, key, $event, isAssert, color, isDynamic)); |
361 | 366 | } |
362 | 367 | /**获取 Response JSON 的注释 |
363 | 368 | * 方案一: |
@@ -5772,10 +5777,10 @@ https://github.com/Tencent/APIJSON/issues |
5772 | 5777 | this.isLocalShow = type == 2 |
5773 | 5778 |
|
5774 | 5779 | this.testCases = this.remotes = [] |
5775 | | - if (type == 1 && this.chainGroups.length <= 0) { |
| 5780 | + if (type == 1 && StringUtil.isEmpty(this.chainGroups)) { |
5776 | 5781 | this.selectChainGroup(-1, null) |
5777 | 5782 | } |
5778 | | - else if (type == 0 && this.caseGroups.length <= 0) { |
| 5783 | + else if (type == 0 && StringUtil.isEmpty(this.caseGroups)) { |
5779 | 5784 | this.selectCaseGroup(-1, null) |
5780 | 5785 | } |
5781 | 5786 | else { |
@@ -5791,29 +5796,18 @@ https://github.com/Tencent/APIJSON/issues |
5791 | 5796 | }, |
5792 | 5797 |
|
5793 | 5798 | getCaseCountStr: function() { |
5794 | | - var isChainShow = this.isChainShow |
5795 | | - var isCaseGroupShow = this.isCaseGroupShow() |
5796 | | - var isLocalShow = this.isLocalShow |
5797 | | - var caseShowType = this.caseShowType |
5798 | | - var caseGroups = (isChainShow ? this.chainGroups : this.caseGroups) || [] |
5799 | | - var testCases = this.testCases || [] |
5800 | | - |
5801 | | - if (isLocalShow) { |
5802 | | - return '(' + testCases.length + ')' |
| 5799 | + if (this.isLocalShow) { |
| 5800 | + return '(' + StringUtil.length(this.testCases) + ')' |
5803 | 5801 | } |
5804 | 5802 |
|
5805 | | - return '(' + (isCaseGroupShow ? caseGroups.length : '') |
5806 | | - + (caseShowType == 0 && isCaseGroupShow ? '|' : '') |
5807 | | - + (caseShowType == 2 && (isCaseGroupShow) ? '' : testCases.length) + ')'; |
| 5803 | + var isChainShow = this.isChainShow |
| 5804 | + var isCaseGroupShow = this.isCaseGroupShow() |
| 5805 | + var isCaseItemShow = this.isCaseItemShow() |
| 5806 | + var caseGroups = (isChainShow ? this.chainGroups : this.caseGroups) |
5808 | 5807 |
|
5809 | | - // 以下代码不知道为啥结果显示不对 |
5810 | | - // var isCaseGroupShow = this.isCaseGroupShow() |
5811 | | - // var isCaseItemShow = this.isCaseItemShow() |
5812 | | - // var caseGroups = (this.isChainShow ? this.chainGroups : this.caseGroups) || [] |
5813 | | - // |
5814 | | - // return '(' + (isCaseGroupShow ? caseGroups.length : '') |
5815 | | - // + (isCaseGroupShow && isCaseItemShow ? '|' : '') |
5816 | | - // + (isCaseItemShow ? '' : testCases.length) + ')'; |
| 5808 | + return '(' + (isCaseGroupShow ? StringUtil.length(caseGroups) : '') |
| 5809 | + + (isCaseGroupShow && isCaseItemShow ? '|' : '') |
| 5810 | + + (isCaseItemShow ? StringUtil.length(this.testCases) : '') + ')'; |
5817 | 5811 | }, |
5818 | 5812 |
|
5819 | 5813 | //显示远程的测试用例文档 |
@@ -7702,6 +7696,20 @@ https://github.com/Tencent/APIJSON/issues |
7702 | 7696 | return Promise.reject(error); |
7703 | 7697 | }); |
7704 | 7698 |
|
| 7699 | + // Object.defineProperty(req, 'constructor', { |
| 7700 | + // value: 'getInstance', |
| 7701 | + // enumerable: true, |
| 7702 | + // configurable: false, |
| 7703 | + // writable: true |
| 7704 | + // }) |
| 7705 | + |
| 7706 | + var isJSON = HTTP_JSON_TYPES.indexOf(type) >= 0; |
| 7707 | + if (isJSON && JSONResponse.isObject(req) && (req.constructor != null || req.package != null || req.class != null || req.method != null || req.prototype != null)) { |
| 7708 | + req = JSON.stringify(req) |
| 7709 | + header = header || {} |
| 7710 | + header['Content-Type'] = 'application/json' |
| 7711 | + } |
| 7712 | + |
7705 | 7713 | // axios.defaults.withcredentials = true |
7706 | 7714 | axios({ |
7707 | 7715 | method: method != null ? method : (HTTP_METHODS.indexOf(type) >= 0 ? type.toLowerCase() : (type == REQUEST_TYPE_PARAM ? 'get' : 'post')), |
@@ -7715,7 +7723,7 @@ https://github.com/Tencent/APIJSON/issues |
7715 | 7723 | ) |
7716 | 7724 | ), |
7717 | 7725 | params: isParam ? req : null, |
7718 | | - data: HTTP_JSON_TYPES.indexOf(type) >= 0 ? req : (HTTP_FORM_DATA_TYPES.indexOf(type) >= 0 ? toFormData(req) : null), |
| 7726 | + data: isJSON ? req : (HTTP_FORM_DATA_TYPES.indexOf(type) >= 0 ? toFormData(req) : null), |
7719 | 7727 | headers: header, //Accept-Encoding(HTTP Header 大小写不敏感,SpringBoot 接收后自动转小写)可能导致 Response 乱码 |
7720 | 7728 | withCredentials: true, //Cookie 必须要 type == REQUEST_TYPE_JSON |
7721 | 7729 | // crossDomain: true |
@@ -11250,8 +11258,28 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea |
11250 | 11258 |
|
11251 | 11259 | var toEval = value; |
11252 | 11260 | if (start > 0 && end > start) { |
11253 | | - |
11254 | 11261 | var funWithOrder = value.substring(0, start); |
| 11262 | + var prefixEnd = funWithOrder.indexOf('ORDER_') |
| 11263 | + if (prefixEnd < 0) { |
| 11264 | + prefixEnd = funWithOrder.indexOf('RANDOM_') |
| 11265 | + if (prefixEnd < 0) { |
| 11266 | + prefixEnd = funWithOrder.indexOf('PRE_') |
| 11267 | + if (prefixEnd < 0) { |
| 11268 | + prefixEnd = funWithOrder.indexOf('CTX_') |
| 11269 | + if (prefixEnd < 0) { |
| 11270 | + prefixEnd = funWithOrder.indexOf('CUR_') |
| 11271 | + } |
| 11272 | + } |
| 11273 | + } |
| 11274 | + } |
| 11275 | + |
| 11276 | + var prefix = prefixEnd < 0 ? '' : StringUtil.get(funWithOrder.substring(0, prefixEnd)) |
| 11277 | + if (/^[_A-Za-z]+$/g.test(prefix.substring(prefix.length - 1))) { |
| 11278 | + prefix = '' |
| 11279 | + } else { |
| 11280 | + funWithOrder = funWithOrder.substring(prefixEnd) |
| 11281 | + } |
| 11282 | + |
11255 | 11283 | var splitIndex = funWithOrder.indexOf('+'); |
11256 | 11284 |
|
11257 | 11285 | var isDesc = false; |
@@ -11301,26 +11329,26 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea |
11301 | 11329 | var as3 = as[3] // account@host/index |
11302 | 11330 | var accountHostIndexPath = StringUtil.isEmpty(as3) ? '/' : as3 + (as3.indexOf('/') < 0 ? '/' : '') |
11303 | 11331 | var isChain = StringUtil.isNotEmpty(as2) |
11304 | | - var chainArr = isChain ? '((ctx || {}).map || {})[' + as2 + ']' : null; // [GET /users] = { account@host: [] } |
| 11332 | + var chainArr = isChain ? '(((ctx || {}).ctx || {}).map || {})[' + as2 + ']' : null; // [GET /users] = { account@host: [] } |
11305 | 11333 | if (isChain) { |
11306 | 11334 | as2 = parseJSON(as2, as2, true) |
11307 | 11335 | as.splice(2, 2) |
11308 | 11336 | } |
11309 | 11337 |
|
11310 | 11338 | if (fun == PRE_REQ) { |
11311 | | - var source = isChain ? 'get4Path(' + chainArr + ', "' + accountHostIndexPath + '/req")' : 'get4Path(((ctx || {}).pre || {}).req' |
| 11339 | + var source = isChain ? 'get4Path(' + chainArr + ', "' + accountHostIndexPath + '/req")' : '((ctx || {}).pre || {}).req' |
11312 | 11340 | toEval = 'get4Path(' + source + ', ' + (value == 'PRE_REQ()' ? JSON.stringify(path) : '') + (isChain ? as.join(', ') + value.substring(end) : value.substring(start + 1)); |
11313 | 11341 | } |
11314 | 11342 | else if (fun == PRE_ARG) { |
11315 | | - var source = isChain ? 'get4Path(' + chainArr + ', "' + accountHostIndexPath + '/arg")' : 'get4Path(((ctx || {}).pre || {}).arg' |
| 11343 | + var source = isChain ? 'get4Path(' + chainArr + ', "' + accountHostIndexPath + '/arg")' : '((ctx || {}).pre || {}).arg' |
11316 | 11344 | toEval = 'get4Path(' + source + ', ' + (value == 'PRE_ARG()' ? JSON.stringify(path) : '') + (isChain ? as.join(', ') + value.substring(end) : value.substring(start + 1)); |
11317 | 11345 | } |
11318 | 11346 | else if (fun == PRE_RES) { |
11319 | | - var source = isChain ? 'get4Path(' + chainArr + ', "' + accountHostIndexPath + '/res")' : 'get4Path(((ctx || {}).pre || {}).res' |
| 11347 | + var source = isChain ? 'get4Path(' + chainArr + ', "' + accountHostIndexPath + '/res")' : '((ctx || {}).pre || {}).res' |
11320 | 11348 | toEval = 'get4Path(' + source + ', ' + (value == 'PRE_RES()' ? JSON.stringify(path) : '') + (isChain ? as.join(', ') + value.substring(end) : value.substring(start + 1)); |
11321 | 11349 | } |
11322 | 11350 | else if (fun == PRE_DATA) { |
11323 | | - var source = isChain ? 'get4Path(' + chainArr + ', "' + accountHostIndexPath + '/data")' : 'get4Path(((ctx || {}).pre || {}).data' |
| 11351 | + var source = isChain ? 'get4Path(' + chainArr + ', "' + accountHostIndexPath + '/data")' : '((ctx || {}).pre || {}).data' |
11324 | 11352 | toEval = 'get4Path(' + source + ', ' + (value == 'PRE_DATA()' ? JSON.stringify(path) : '') + (isChain ? as.join(', ') + value.substring(end) : value.substring(start + 1)); |
11325 | 11353 | } |
11326 | 11354 | else if (fun == CTX_GET) { |
@@ -11417,6 +11445,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea |
11417 | 11445 |
|
11418 | 11446 | } |
11419 | 11447 |
|
| 11448 | + toEval = prefix + toEval |
11420 | 11449 | } |
11421 | 11450 |
|
11422 | 11451 | var isInject = true; |
@@ -11721,7 +11750,16 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea |
11721 | 11750 |
|
11722 | 11751 | res = res || {} |
11723 | 11752 | var config = res.config || {} |
11724 | | - cur.arg = App.getRequest(config.data || config.params, {}) |
| 11753 | + var p = config.data || config.params |
| 11754 | + try { |
| 11755 | + cur.arg = App.getRequest(p, {}) |
| 11756 | + } catch (e) { |
| 11757 | + if (StringUtil.isNotString(p) || p.indexOf('=') <= 0) { |
| 11758 | + throw e |
| 11759 | + } |
| 11760 | + cur.arg = getRequestFromURL('?' + p, true) |
| 11761 | + } |
| 11762 | + |
11725 | 11763 | cur.req = { |
11726 | 11764 | method: method, |
11727 | 11765 | url: config.url, |
@@ -11732,19 +11770,32 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea |
11732 | 11770 | cur.statusText = res.statusText |
11733 | 11771 | cur.res = res |
11734 | 11772 | cur.data = res.data |
11735 | | - var map = ctx.map = ctx.map || {} |
11736 | | - var m = map[method + ' ' + url] = map[method + ' ' + url] || {} |
11737 | 11773 |
|
11738 | | - const baseUrl = App.getBaseUrl(config.url) |
11739 | | - const accountKey = StringUtil.trim(account) + '@' + StringUtil.trim(baseUrl) |
11740 | | - var arr = m[accountKey] = m[accountKey] || [] |
11741 | | - arr.push({ |
| 11774 | + var info = { |
11742 | 11775 | type: type, |
11743 | 11776 | req: req, |
11744 | 11777 | arg: json, |
11745 | 11778 | res: res, |
11746 | 11779 | data: res.data |
11747 | | - }) |
| 11780 | + } |
| 11781 | + |
| 11782 | + var map = ctx.map = ctx.map || {} |
| 11783 | + var m = map[method + ' ' + url] = map[method + ' ' + url] || {} |
| 11784 | + |
| 11785 | + const baseUrl = StringUtil.trim(App.getBaseUrl(config.url)) |
| 11786 | + const accountKey = account + '@' + baseUrl |
| 11787 | + var arr = m[accountKey] = m[accountKey] || [] |
| 11788 | + arr.push(info) |
| 11789 | + |
| 11790 | + if (StringUtil.isNotEmpty(account)) { |
| 11791 | + var arr2 = m[account] = m[account] || [] |
| 11792 | + arr2.push(info) |
| 11793 | + } |
| 11794 | + |
| 11795 | + if (StringUtil.isNotEmpty(baseUrl)) { |
| 11796 | + var arr2 = m[baseUrl] = m[baseUrl] || [] |
| 11797 | + arr2.push(info) |
| 11798 | + } |
11748 | 11799 |
|
11749 | 11800 | App.startTestChain(list, allCount, index + 1, list[index + 1], item, ctx, isRandom, accountIndex, isCross, callback) |
11750 | 11801 | }, ctx) |
|