apipost-cli 2.0.23 → 2.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +100 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -222169,6 +222169,33 @@ const parseExp = (exp, environments, lang = 'en', customFunc) => {
|
|
|
222169
222169
|
};
|
|
222170
222170
|
}
|
|
222171
222171
|
// } else if (isNumericString(distData) || (_.startsWith(distData, '"') && _.endsWith(distData, '"')) ||
|
|
222172
|
+
} else if (_.startsWith(distData, '$function.fn_')) {
|
|
222173
|
+
const regex = /\$function\.fn_([a-zA-Z0-9_]+)\(([^)]*)\)/;
|
|
222174
|
+
const match = distData.match(regex);
|
|
222175
|
+
|
|
222176
|
+
if (!match || !_.isString(match[1]) || !_.isString(match[2]) || !_.has(encodeFunctions, `fn_${_.toLower(_.trim(match[1]))}`)) {
|
|
222177
|
+
dist = {
|
|
222178
|
+
type: 'fixed',
|
|
222179
|
+
expression: `{{${distData}}}`,
|
|
222180
|
+
value: `{{${distData}}}`,
|
|
222181
|
+
};
|
|
222182
|
+
} else {
|
|
222183
|
+
try {
|
|
222184
|
+
const callMethod = _.get(encodeFunctions, `fn_${_.toLower(_.trim(match[1]))}`);
|
|
222185
|
+
const parameter = match[2];
|
|
222186
|
+
dist = {
|
|
222187
|
+
type: 'function',
|
|
222188
|
+
expression: `fn_${_.trim(match[1])}(${parameter})`,
|
|
222189
|
+
value: callMethod(parameter),
|
|
222190
|
+
};
|
|
222191
|
+
} catch (e) {
|
|
222192
|
+
dist = {
|
|
222193
|
+
type: 'fixed',
|
|
222194
|
+
expression: `{{${distData}}}`,
|
|
222195
|
+
value: `{{${distData}}}`,
|
|
222196
|
+
};
|
|
222197
|
+
}
|
|
222198
|
+
}
|
|
222172
222199
|
} else if ((_.startsWith(distData, '"') && _.endsWith(distData, '"')) ||
|
|
222173
222200
|
(_.startsWith(distData, "'") && _.endsWith(distData, "'"))) {
|
|
222174
222201
|
dist = {
|
|
@@ -528542,6 +528569,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
528542
528569
|
const queryAddEqual = _.toInteger(
|
|
528543
528570
|
_.get(request, "request.query.query_add_equal") || -1
|
|
528544
528571
|
);
|
|
528572
|
+
|
|
528545
528573
|
_.forEach(_.get(request, "request.query.parameter"), (item) => {
|
|
528546
528574
|
if (_.isObject(item) && item?.is_checked > 0) {
|
|
528547
528575
|
let { key, value, schema } = item;
|
|
@@ -528549,7 +528577,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
528549
528577
|
value = String(autoReplaceMockVar(value));
|
|
528550
528578
|
|
|
528551
528579
|
if (value == '' && _.isObject(schema)) {
|
|
528552
|
-
const tmpValue = jsfGenerate(schema, [], option?.lang);
|
|
528580
|
+
const tmpValue = jsfGenerate(schema, [], option?.lang, option?.custom_functions || {});
|
|
528553
528581
|
|
|
528554
528582
|
if (!_.isUndefined(tmpValue)) {
|
|
528555
528583
|
value = tmpValue;
|
|
@@ -528592,7 +528620,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
528592
528620
|
value = autoReplaceMockVar(value);
|
|
528593
528621
|
|
|
528594
528622
|
if (value == '' && _.isObject(schema)) {
|
|
528595
|
-
const tmpValue = jsfGenerate(schema, [], option?.lang);
|
|
528623
|
+
const tmpValue = jsfGenerate(schema, [], option?.lang, option?.custom_functions || {});
|
|
528596
528624
|
|
|
528597
528625
|
if (!_.isUndefined(tmpValue)) {
|
|
528598
528626
|
value = tmpValue;
|
|
@@ -528779,7 +528807,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
528779
528807
|
value = autoReplaceMockVar(value);
|
|
528780
528808
|
|
|
528781
528809
|
if (value == '' && _.isObject(schema)) {
|
|
528782
|
-
const tmpValue = jsfGenerate(schema, [], option?.lang);
|
|
528810
|
+
const tmpValue = jsfGenerate(schema, [], option?.lang, option?.custom_functions || {});
|
|
528783
528811
|
|
|
528784
528812
|
if (!_.isUndefined(tmpValue)) {
|
|
528785
528813
|
value = tmpValue;
|
|
@@ -528869,7 +528897,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
528869
528897
|
let value = autoReplaceMockVar(item.value);
|
|
528870
528898
|
|
|
528871
528899
|
if (value == '' && _.isObject(item?.schema)) {
|
|
528872
|
-
const tmpValue = jsfGenerate(item?.schema, [], option?.lang);
|
|
528900
|
+
const tmpValue = jsfGenerate(item?.schema, [], option?.lang, option?.custom_functions || {});
|
|
528873
528901
|
|
|
528874
528902
|
if (!_.isUndefined(tmpValue)) {
|
|
528875
528903
|
value = tmpValue;
|
|
@@ -528965,7 +528993,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
528965
528993
|
value = autoReplaceMockVar(value);
|
|
528966
528994
|
|
|
528967
528995
|
if (value == '' && _.isObject(schema)) {
|
|
528968
|
-
const tmpValue = jsfGenerate(schema, [], option?.lang);
|
|
528996
|
+
const tmpValue = jsfGenerate(schema, [], option?.lang, option?.custom_functions || {});
|
|
528969
528997
|
|
|
528970
528998
|
if (!_.isUndefined(tmpValue)) {
|
|
528971
528999
|
value = tmpValue;
|
|
@@ -530962,7 +530990,7 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
530962
530990
|
},
|
|
530963
530991
|
|
|
530964
530992
|
responseData(cursor, data) {
|
|
530965
|
-
if (!_.includes(['get_parsed_request'], scene)) {
|
|
530993
|
+
if (!_.includes(['get_parsed_request'], scene) && requestJson?.target_type === 'sse') {
|
|
530966
530994
|
callback({
|
|
530967
530995
|
action: "sse",
|
|
530968
530996
|
data: {
|
|
@@ -531525,8 +531553,9 @@ module.exports = async (event, option, callback, eventRuntimeData, eventResultLi
|
|
|
531525
531553
|
/***/ 248657:
|
|
531526
531554
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
531527
531555
|
|
|
531528
|
-
const { repeatArrayToLength, formatAutotestReport, formatAutotestReportList } = __nccwpck_require__(490181);
|
|
531556
|
+
const { repeatArrayToLength, formatAutotestReport, formatAutotestReportList, getInsideVariables } = __nccwpck_require__(490181);
|
|
531529
531557
|
const _ = __nccwpck_require__(690250);
|
|
531558
|
+
const { mockExp } = __nccwpck_require__(693436);
|
|
531530
531559
|
const aTools = __nccwpck_require__(167350);
|
|
531531
531560
|
const { executeEvent, iterationEvent } = __nccwpck_require__(890666);
|
|
531532
531561
|
const ABORT_RECURSION_ERROR = ['systemError']; //需要跳出递归的错误
|
|
@@ -531540,7 +531569,7 @@ const run = async (events, option, callback) => {
|
|
|
531540
531569
|
}
|
|
531541
531570
|
|
|
531542
531571
|
const tempEvents = _.cloneDeep(_.flatten(new Array(scene == 'auto_test' ? _.max([_.toInteger(iterationCount), 1]) : 1).fill(events))) || [];
|
|
531543
|
-
const
|
|
531572
|
+
const iterationDataArrTemp = _.flatMap(repeatArrayToLength(_.cloneDeep(iterationData), _.max([_.toInteger(iterationCount), 1])), (element) => _.times(_.size(events), () => element));
|
|
531544
531573
|
const eventOptions = _.pick(option, ["scene", "lang", "project", "env", "globals", "cookies", "system_configs", "custom_functions", "collection", "database_configs", "enable_sandbox", "sleep", "name", "testing_id"]);
|
|
531545
531574
|
|
|
531546
531575
|
// 初始化变量
|
|
@@ -531555,6 +531584,37 @@ const run = async (events, option, callback) => {
|
|
|
531555
531584
|
}
|
|
531556
531585
|
};
|
|
531557
531586
|
|
|
531587
|
+
const iterationDataArr = [];
|
|
531588
|
+
if (scene != 'http_request') {
|
|
531589
|
+
// 解析测试数据
|
|
531590
|
+
const regex = /{{([^}]+)}}/g;
|
|
531591
|
+
_.forEach(iterationDataArrTemp, (obj, index) => {
|
|
531592
|
+
const cloneObj = _.cloneDeep(obj);
|
|
531593
|
+
if (_.isObject(obj) && !_.isEmpty(obj)) {
|
|
531594
|
+
_.forEach(obj, (val, key) => {
|
|
531595
|
+
if (_.trim(val) != '' && _.isString(val)) {
|
|
531596
|
+
const matches = val.match(regex);
|
|
531597
|
+
|
|
531598
|
+
if (!_.isEmpty(matches)) {
|
|
531599
|
+
_.forEach(matches, (match) => {
|
|
531600
|
+
try {
|
|
531601
|
+
const tmpVal = mockExp(match, getInsideVariables(), option?.lang, option?.custom_functions || {});
|
|
531602
|
+
|
|
531603
|
+
if (tmpVal != match && !_.isUndefined(tmpVal)) {
|
|
531604
|
+
_.set(cloneObj, [key], _.replace(val, match, tmpVal));
|
|
531605
|
+
|
|
531606
|
+
}
|
|
531607
|
+
} catch (e) { }
|
|
531608
|
+
})
|
|
531609
|
+
}
|
|
531610
|
+
}
|
|
531611
|
+
})
|
|
531612
|
+
}
|
|
531613
|
+
|
|
531614
|
+
iterationDataArr.push(cloneObj)
|
|
531615
|
+
})
|
|
531616
|
+
}
|
|
531617
|
+
|
|
531558
531618
|
const tempVars = { environment: _.get(option, 'env.environment', {}), globals: _.get(option, 'globals', {}), iterationDataArr };
|
|
531559
531619
|
|
|
531560
531620
|
['environment', 'globals', 'iterationDataArr'].forEach((type) => {
|
|
@@ -532332,13 +532392,14 @@ const encodeURIComponentUnique = (str) => {
|
|
|
532332
532392
|
}
|
|
532333
532393
|
}
|
|
532334
532394
|
|
|
532335
|
-
const jsfGenerate = (schema, mockRules = [], lang) => {
|
|
532395
|
+
const jsfGenerate = (schema, mockRules = [], lang, customFunctions = {}) => {
|
|
532336
532396
|
jsf.option({
|
|
532337
532397
|
alwaysFakeOptionals: true,
|
|
532338
532398
|
useExamplesValue: true,
|
|
532339
532399
|
fillProperties: false,
|
|
532340
532400
|
useDefaultValue: true,
|
|
532341
532401
|
mockRules,
|
|
532402
|
+
customFunctions,
|
|
532342
532403
|
lang: 'zh-cn',
|
|
532343
532404
|
});
|
|
532344
532405
|
|
|
@@ -820606,6 +820667,32 @@ var require_exp_mock = __commonJS({
|
|
|
820606
820667
|
value: `{{${distData}}}`
|
|
820607
820668
|
};
|
|
820608
820669
|
}
|
|
820670
|
+
} else if (_.startsWith(distData, "$function.fn_")) {
|
|
820671
|
+
const regex = /\$function\.fn_([a-zA-Z0-9_]+)\(([^)]*)\)/;
|
|
820672
|
+
const match2 = distData.match(regex);
|
|
820673
|
+
if (!match2 || !_.isString(match2[1]) || !_.isString(match2[2]) || !_.has(encodeFunctions, `fn_${_.toLower(_.trim(match2[1]))}`)) {
|
|
820674
|
+
dist = {
|
|
820675
|
+
type: "fixed",
|
|
820676
|
+
expression: `{{${distData}}}`,
|
|
820677
|
+
value: `{{${distData}}}`
|
|
820678
|
+
};
|
|
820679
|
+
} else {
|
|
820680
|
+
try {
|
|
820681
|
+
const callMethod = _.get(encodeFunctions, `fn_${_.toLower(_.trim(match2[1]))}`);
|
|
820682
|
+
const parameter = match2[2];
|
|
820683
|
+
dist = {
|
|
820684
|
+
type: "function",
|
|
820685
|
+
expression: `fn_${_.trim(match2[1])}(${parameter})`,
|
|
820686
|
+
value: callMethod(parameter)
|
|
820687
|
+
};
|
|
820688
|
+
} catch (e2) {
|
|
820689
|
+
dist = {
|
|
820690
|
+
type: "fixed",
|
|
820691
|
+
expression: `{{${distData}}}`,
|
|
820692
|
+
value: `{{${distData}}}`
|
|
820693
|
+
};
|
|
820694
|
+
}
|
|
820695
|
+
}
|
|
820609
820696
|
} else if (_.startsWith(distData, '"') && _.endsWith(distData, '"') || _.startsWith(distData, "'") && _.endsWith(distData, "'")) {
|
|
820610
820697
|
dist = {
|
|
820611
820698
|
type: "fixed",
|
|
@@ -823290,7 +823377,8 @@ function traverse(schema2, path2, resolve2, rootSchema) {
|
|
|
823290
823377
|
} catch (e2) {
|
|
823291
823378
|
}
|
|
823292
823379
|
}
|
|
823293
|
-
|
|
823380
|
+
const customFunctions = option_default("customFunctions") || {};
|
|
823381
|
+
value = (0, import_exp_mock.mockExp)(mockPlaceholder, {}, lang2, customFunctions);
|
|
823294
823382
|
break;
|
|
823295
823383
|
}
|
|
823296
823384
|
break;
|
|
@@ -823453,7 +823541,8 @@ function traverse(schema2, path2, resolve2, rootSchema) {
|
|
|
823453
823541
|
return { value: import_mockjs5_pro.default.mock(mockRule), context };
|
|
823454
823542
|
}
|
|
823455
823543
|
if (import_lodash3.default.startsWith(mockRule, "{{$") && import_lodash3.default.endsWith(mockRule, "}}")) {
|
|
823456
|
-
|
|
823544
|
+
const customFunctions = option_default("customFunctions") || {};
|
|
823545
|
+
return { value: (0, import_exp_mock.mockExp)(mockRule, {}, lang2, customFunctions), context };
|
|
823457
823546
|
}
|
|
823458
823547
|
}
|
|
823459
823548
|
}
|