runner-runtime 1.0.90 → 1.0.91
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 +1 -0
- package/package.json +14 -7
- package/events/api.js +0 -2570
- package/events/index.js +0 -408
- package/events/wait.js +0 -39
- package/index.js +0 -180
- package/jar-main-1.0-SNAPSHOT.jar +0 -0
- package/libs/2har.js +0 -161
- package/libs/utils.js +0 -604
- package/tmp/request.js +0 -326
package/libs/utils.js
DELETED
|
@@ -1,604 +0,0 @@
|
|
|
1
|
-
const atomicSleep = require("atomic-sleep"),
|
|
2
|
-
_ = require('lodash'),
|
|
3
|
-
fs = require("fs"),
|
|
4
|
-
jsf = require("json-schema-faker-pro"),
|
|
5
|
-
path = require("path"),
|
|
6
|
-
{ mockExp } = require('exp-mock'),
|
|
7
|
-
Mock = require('mockjs5-pro'),
|
|
8
|
-
mime = require("mime"),
|
|
9
|
-
os = require("os"),
|
|
10
|
-
Buffer = require("buffer/").Buffer,
|
|
11
|
-
urlJoin = require("@apipost/url-join");
|
|
12
|
-
|
|
13
|
-
// 获取某接口的详细信息
|
|
14
|
-
const getAPIFromCollection = function (collection, target_id) {
|
|
15
|
-
return _.find(collection, _.matchesProperty("target_id", target_id));
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// 获取某接口的 所有父target
|
|
19
|
-
const getParentTargetIDs = function (collection, target_id, parent_ids) {
|
|
20
|
-
if (_.isArray(collection)) {
|
|
21
|
-
|
|
22
|
-
const item = _.find(collection, _.matchesProperty("target_id", target_id));
|
|
23
|
-
|
|
24
|
-
if (item) {
|
|
25
|
-
if (parent_ids.includes(item.parent_id)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (_.isString(item.parent_id)) {
|
|
30
|
-
parent_ids.push(item.parent_id);
|
|
31
|
-
getParentTargetIDs(collection, item.parent_id, parent_ids);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// url 拼接
|
|
38
|
-
const smartUrlJoin = (base, ...paths) => {
|
|
39
|
-
// 检查paths中是否有完整的URL
|
|
40
|
-
for (let path of paths) {
|
|
41
|
-
if (/^[a-zA-Z]+:\/\//.test(path)) {
|
|
42
|
-
return path;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 如果没有完整的URL,则使用url-join正常合并
|
|
47
|
-
return urlJoin(base, ...paths);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//replace2RegExp
|
|
51
|
-
const replace2RegExp = (str, replace, value) => {
|
|
52
|
-
try {
|
|
53
|
-
return _.replace(str, new RegExp(String(replace), 'ig'), String(value))
|
|
54
|
-
} catch (e) {
|
|
55
|
-
return _.replace(str, replace, String(value))
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const base64toCacheFile = (key, value, base64, dirpath) => {
|
|
60
|
-
let src = value;
|
|
61
|
-
try {
|
|
62
|
-
fs.statSync(src);
|
|
63
|
-
} catch (e) {
|
|
64
|
-
if (!_.isEmpty(base64)) {
|
|
65
|
-
const match = String(base64).match(/data:([0-9a-zA-Z\/\-]+);base64,/i);
|
|
66
|
-
const ext = mime.getExtension(match && match[1] ? match[1] : "");
|
|
67
|
-
|
|
68
|
-
if (_.isString(ext)) {
|
|
69
|
-
const tempDirPath = path.resolve(os.tmpdir(), `${dirpath}`);
|
|
70
|
-
try {
|
|
71
|
-
fs.mkdirSync(tempDirPath);
|
|
72
|
-
} catch (e) { }
|
|
73
|
-
|
|
74
|
-
let tempFileName = value;
|
|
75
|
-
if (!_.endsWith(tempFileName, `.${ext}`)) {
|
|
76
|
-
tempFileName = `${key}.${ext}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const tempFilePath = path.resolve(tempDirPath, tempFileName);
|
|
80
|
-
try {
|
|
81
|
-
fs.writeFileSync(
|
|
82
|
-
tempFilePath,
|
|
83
|
-
Buffer.from(_.replace(base64, /^data:[0-9a-zA-Z\/\-]+;base64,/, ""), "base64")
|
|
84
|
-
);
|
|
85
|
-
src = tempFilePath;
|
|
86
|
-
} catch (e) { }
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return src;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// generateNorthAmericanPhoneNumber
|
|
95
|
-
const generateNorthAmericanPhoneNumber = () => {
|
|
96
|
-
const areaCode = Math.floor(Math.random() * 900) + 100; // 100-999
|
|
97
|
-
const phoneNumber = Math.floor(Math.random() * 10000000) + 1000000; // 1000000-9999999
|
|
98
|
-
const formattedPhoneNumber = `${areaCode}-${phoneNumber.toString().slice(0, 3)}-${phoneNumber.toString().slice(3)}`;
|
|
99
|
-
|
|
100
|
-
return formattedPhoneNumber;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// generateChinesePhoneNumber
|
|
104
|
-
const generateChinesePhoneNumber = () => {
|
|
105
|
-
let phoneNumber = '1';
|
|
106
|
-
phoneNumber += _.random(3, 9).toString();
|
|
107
|
-
phoneNumber += _.times(9, () => _.random(0, 9)).join('');
|
|
108
|
-
return phoneNumber;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const getInsideVariables = () => {
|
|
112
|
-
const list = {};
|
|
113
|
-
|
|
114
|
-
new Array(
|
|
115
|
-
"natural",
|
|
116
|
-
"integer",
|
|
117
|
-
"float",
|
|
118
|
-
"character",
|
|
119
|
-
"range",
|
|
120
|
-
"date",
|
|
121
|
-
"time",
|
|
122
|
-
"datetime",
|
|
123
|
-
"now",
|
|
124
|
-
"guid",
|
|
125
|
-
"increment",
|
|
126
|
-
"url",
|
|
127
|
-
"protocol",
|
|
128
|
-
"domain",
|
|
129
|
-
"tld",
|
|
130
|
-
"email",
|
|
131
|
-
"ip",
|
|
132
|
-
"region",
|
|
133
|
-
"province",
|
|
134
|
-
"city",
|
|
135
|
-
"county",
|
|
136
|
-
"county",
|
|
137
|
-
"zip",
|
|
138
|
-
"first",
|
|
139
|
-
"last",
|
|
140
|
-
"name",
|
|
141
|
-
"cfirst",
|
|
142
|
-
"clast",
|
|
143
|
-
"cname",
|
|
144
|
-
"color",
|
|
145
|
-
"rgb",
|
|
146
|
-
"rgba",
|
|
147
|
-
"hsl",
|
|
148
|
-
"paragraph",
|
|
149
|
-
"cparagraph",
|
|
150
|
-
"sentence",
|
|
151
|
-
"csentence",
|
|
152
|
-
"word",
|
|
153
|
-
"cword",
|
|
154
|
-
"title",
|
|
155
|
-
"ctitle",
|
|
156
|
-
"username",
|
|
157
|
-
"user_name",
|
|
158
|
-
"nickname",
|
|
159
|
-
"nick_name",
|
|
160
|
-
"avatar",
|
|
161
|
-
"icon",
|
|
162
|
-
"img",
|
|
163
|
-
"photo",
|
|
164
|
-
"pic",
|
|
165
|
-
"description",
|
|
166
|
-
"id",
|
|
167
|
-
"userid",
|
|
168
|
-
"user_id",
|
|
169
|
-
"articleid",
|
|
170
|
-
"article_id"
|
|
171
|
-
).forEach((func) => {
|
|
172
|
-
list[`$${func}`] = Mock.mock(`@${func}`);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
if (process && process?.IS_ECHOAPI) {
|
|
176
|
-
//echoapi
|
|
177
|
-
const blackArray = ['region', 'province', 'city', 'county', 'cfirst', 'clast', 'cname', 'cparagraph', 'csentence', 'cword', 'ctitle']
|
|
178
|
-
function createReturnFunction(param) {
|
|
179
|
-
return function () {
|
|
180
|
-
return param;
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
blackArray.forEach((func) => {
|
|
184
|
-
list[`$${func}`] = createReturnFunction(`$${func}`);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
new Array("phone", "mobile", "telephone").forEach((func) => {
|
|
188
|
-
list[`$${func}`] = generateNorthAmericanPhoneNumber();
|
|
189
|
-
});
|
|
190
|
-
} else {
|
|
191
|
-
new Array("phone", "mobile", "telephone").forEach((func) => {
|
|
192
|
-
list[`$${func}`] = generateChinesePhoneNumber();
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// 兼容 v3
|
|
197
|
-
list.$timestamp = (function () {
|
|
198
|
-
return _.toInteger(Date.now() / 1000);
|
|
199
|
-
})();
|
|
200
|
-
|
|
201
|
-
list.$microTimestamp = (function () {
|
|
202
|
-
return new Date().getTime();
|
|
203
|
-
})();
|
|
204
|
-
|
|
205
|
-
list.$randomInt = (function () {
|
|
206
|
-
return Math.floor(Math.random() * 1000);
|
|
207
|
-
})();
|
|
208
|
-
|
|
209
|
-
list.$randomFloat = (function () {
|
|
210
|
-
return Math.random() * 1000;
|
|
211
|
-
})();
|
|
212
|
-
|
|
213
|
-
return list;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const repeatArrayToLength = (arr, targetLength) => {
|
|
217
|
-
if (!_.isArray(arr)) {
|
|
218
|
-
arr = _.values(arr);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (_.isEmpty(arr)) {
|
|
222
|
-
return [];
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const repeatTimes = _.ceil(targetLength / arr.length);
|
|
226
|
-
const repeatedArray = _.flattenDeep(_.fill(new Array(repeatTimes), arr));
|
|
227
|
-
return _.take(repeatedArray, targetLength);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const returnBoolean = (exp, compare, value) => {
|
|
231
|
-
let bool = false;
|
|
232
|
-
if (exp === "") {
|
|
233
|
-
// fix bug
|
|
234
|
-
return compare == "null";
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
switch (compare) {
|
|
238
|
-
case "eq":
|
|
239
|
-
bool = exp == value;
|
|
240
|
-
break;
|
|
241
|
-
case "uneq":
|
|
242
|
-
bool = exp != value;
|
|
243
|
-
break;
|
|
244
|
-
case "gt":
|
|
245
|
-
bool = _.gt(Number(exp), Number(value));
|
|
246
|
-
break;
|
|
247
|
-
case "gte":
|
|
248
|
-
bool = _.gte(Number(exp), Number(value));
|
|
249
|
-
break;
|
|
250
|
-
case "lt":
|
|
251
|
-
bool = _.lt(Number(exp), Number(value));
|
|
252
|
-
break;
|
|
253
|
-
case "lte":
|
|
254
|
-
bool = _.lte(Number(exp), Number(value));
|
|
255
|
-
break;
|
|
256
|
-
case "includes":
|
|
257
|
-
bool = _.includes(exp, value) || _.includes(exp, Number(value));
|
|
258
|
-
break;
|
|
259
|
-
case "unincludes":
|
|
260
|
-
bool = !_.includes(exp, value) && !_.includes(exp, Number(value));
|
|
261
|
-
break;
|
|
262
|
-
case "null":
|
|
263
|
-
bool = _.isEmpty(exp);
|
|
264
|
-
break;
|
|
265
|
-
case "notnull":
|
|
266
|
-
bool = !_.isEmpty(exp);
|
|
267
|
-
break;
|
|
268
|
-
case "exist":
|
|
269
|
-
bool = !_.isUndefined(exp);
|
|
270
|
-
break;
|
|
271
|
-
case "notexist":
|
|
272
|
-
bool = _.isUndefined(exp);
|
|
273
|
-
break;
|
|
274
|
-
case "regularmatch":
|
|
275
|
-
try {
|
|
276
|
-
bool = new RegExp(
|
|
277
|
-
String(value).substring(1, String(value).length - 1)
|
|
278
|
-
).test(exp);
|
|
279
|
-
} catch (e) { }
|
|
280
|
-
break;
|
|
281
|
-
case "belongscollection":
|
|
282
|
-
bool = _.split(value, ",").indexOf(exp) > -1;
|
|
283
|
-
break;
|
|
284
|
-
case "notbelongscollection":
|
|
285
|
-
bool = _.split(value, ",").indexOf(exp) == -1;
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return bool;
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
const getCaseInsensitive = (object, keyToFind) => {
|
|
293
|
-
try {
|
|
294
|
-
// 先将要查找的键转换成小写
|
|
295
|
-
const lowerKey = _.toLower(keyToFind);
|
|
296
|
-
|
|
297
|
-
if (!_.isObject(object)) {
|
|
298
|
-
return undefined;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// 在对象的所有键中查找
|
|
302
|
-
for (const key in object) {
|
|
303
|
-
if (_.toLower(key) === lowerKey) {
|
|
304
|
-
return object[key];
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
} catch (e) { }
|
|
308
|
-
|
|
309
|
-
// 如果没有找到,返回undefined
|
|
310
|
-
return undefined;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const variableReplace = (str, variables, option) => {
|
|
314
|
-
const AllVars = getInsideVariables();
|
|
315
|
-
["globals", "_globals", "environment", "iterationData", "variables"].forEach((varName) => {
|
|
316
|
-
_.assign(AllVars, _.get(variables, `${varName}`))
|
|
317
|
-
})
|
|
318
|
-
|
|
319
|
-
str = _.replace(str, /\{\{([^}]+)\}\}/g, (match, key) => {
|
|
320
|
-
return _.get(AllVars, key.trim(), match);
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
const { lang, custom_functions } = option;
|
|
324
|
-
|
|
325
|
-
try {
|
|
326
|
-
return mockExp(str, AllVars, lang, custom_functions)
|
|
327
|
-
} catch (e) {
|
|
328
|
-
return str;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const variableReplaceForCondition = (str, variables, option) => {
|
|
333
|
-
if (!_.startsWith(str, '{{') || !_.endsWith(str, '}}')) {
|
|
334
|
-
return str;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const AllVars = getInsideVariables();
|
|
338
|
-
["globals", "_globals", "environment", "iterationData", "variables"].forEach((varName) => {
|
|
339
|
-
_.assign(AllVars, _.get(variables, `${varName}`))
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
str = _.replace(str, /\{\{([^}]+)\}\}/g, (match, key) => {
|
|
343
|
-
return _.get(AllVars, key.trim(), match);
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
const { lang, custom_functions } = option;
|
|
347
|
-
|
|
348
|
-
try {
|
|
349
|
-
const finalStr = mockExp(str, AllVars, lang, custom_functions);
|
|
350
|
-
|
|
351
|
-
if (finalStr === str && _.startsWith(str, '{{') && _.endsWith(str, '}}')) {
|
|
352
|
-
return undefined
|
|
353
|
-
}
|
|
354
|
-
return finalStr;
|
|
355
|
-
} catch (e) {
|
|
356
|
-
return undefined;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const formatAutotestReportList = (eventResultList) => {
|
|
361
|
-
const list = [];
|
|
362
|
-
_.forEach(_.cloneDeep(eventResultList), (item) => {
|
|
363
|
-
const type = item?.type;
|
|
364
|
-
|
|
365
|
-
if (_.includes(['assert', 'assert_visual', 'api', 'sample', 'script', 'sql'], type)) {
|
|
366
|
-
list.push(_.assign(
|
|
367
|
-
_.pick(item?.response, ['timings', 'response_time', 'response_at', 'proxy', 'status', 'code', 'response_size']),
|
|
368
|
-
_.pick(item?.request, ['url', 'method', 'name', 'target_id', 'project_id']),
|
|
369
|
-
_.pick(item, ['type', 'event_id', 'test_id', 'iteration_id', 'startTime', 'endTime', 'currentVariables']),
|
|
370
|
-
{
|
|
371
|
-
type,
|
|
372
|
-
'status': {
|
|
373
|
-
"assert": _.isEmpty(item?.status?.success_assert) ? "OK" : item?.status?.success_assert,
|
|
374
|
-
"http": item?.status?.http || "OK"
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
))
|
|
378
|
-
} else if (_.includes(['if'], type)) {
|
|
379
|
-
list.push(_.assign(
|
|
380
|
-
_.pick(item, ['type', 'event_id', 'test_id', 'iteration_id', 'startTime', 'endTime', 'currentVariables']),
|
|
381
|
-
{
|
|
382
|
-
type,
|
|
383
|
-
'status': {
|
|
384
|
-
...item?.data
|
|
385
|
-
}
|
|
386
|
-
},
|
|
387
|
-
))
|
|
388
|
-
} else if (_.includes(['wait'], type)) {
|
|
389
|
-
list.push(_.assign(
|
|
390
|
-
_.pick(item, ['type', 'event_id', 'test_id', 'iteration_id', 'startTime', 'endTime', 'currentVariables']),
|
|
391
|
-
{
|
|
392
|
-
type,
|
|
393
|
-
'sleep': item?.data?.sleep || 0
|
|
394
|
-
},
|
|
395
|
-
))
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
})
|
|
399
|
-
|
|
400
|
-
return list;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
const formatAutotestReport = (startTimeAt, eventResultList) => {
|
|
404
|
-
const report = {
|
|
405
|
-
"assert": {
|
|
406
|
-
"total": 0,
|
|
407
|
-
"success": 0,
|
|
408
|
-
"error": 0
|
|
409
|
-
},
|
|
410
|
-
"http": {
|
|
411
|
-
"total": 0,
|
|
412
|
-
"success": 0,
|
|
413
|
-
"error": 0
|
|
414
|
-
},
|
|
415
|
-
"start_at": startTimeAt,
|
|
416
|
-
"end_at": Date.now(),
|
|
417
|
-
"total_time": Date.now() - startTimeAt,
|
|
418
|
-
"iteration_count": _.size(eventResultList),
|
|
419
|
-
"total_response_time": null,
|
|
420
|
-
"avg_response_time": null,
|
|
421
|
-
"total_response_size": 0,
|
|
422
|
-
"avg_response_size": 0
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
let totalResponseSize = 0, totalResponseTime = 0
|
|
426
|
-
|
|
427
|
-
_.forEach(_.cloneDeep(eventResultList), (item) => {
|
|
428
|
-
if (_.includes(['api', 'sample'], item?.type)) {
|
|
429
|
-
report.http.total++;
|
|
430
|
-
totalResponseSize = totalResponseSize + _.toInteger(item?.response?.response_size);
|
|
431
|
-
totalResponseTime = totalResponseTime + _.toInteger(item?.response?.response_time);
|
|
432
|
-
|
|
433
|
-
if (_.toLower(item?.status?.http) != 'ok') {
|
|
434
|
-
report.http.error++;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if (_.includes(['api', 'sample', 'assert', 'assert_visual'], item?.type) && !_.isEmpty(item?.status?.assert) && _.isArray(item?.status?.assert)) {
|
|
439
|
-
const assertFailure = _.filter(item?.status?.assert, (assertItem) => {
|
|
440
|
-
return assertItem?.passed === false
|
|
441
|
-
})
|
|
442
|
-
|
|
443
|
-
report.assert.total = report.assert.total + _.size(item?.status?.assert);
|
|
444
|
-
report.assert.error = report.assert.error + _.size(assertFailure);
|
|
445
|
-
}
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
report.http.success = report.http.total - report.http.error;
|
|
449
|
-
report.assert.success = report.assert.total - report.assert.error;
|
|
450
|
-
report.avg_response_time = _.round(totalResponseTime / report.http.total, 2) || 0;
|
|
451
|
-
report.avg_response_size = _.round(totalResponseSize / report.http.total, 2) || 0;
|
|
452
|
-
report.total_response_time = totalResponseTime;
|
|
453
|
-
report.total_response_size = totalResponseSize;
|
|
454
|
-
|
|
455
|
-
return report;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const camelCaseToSnakeCase = (obj) => {
|
|
460
|
-
["arrCookies", "fitForShow", "mimeType", "requestStart", "responseSize", "responseTime",].forEach((key) => {
|
|
461
|
-
const _key = _.snakeCase(key);
|
|
462
|
-
const objValue = _.get(obj, `response.${key}`);
|
|
463
|
-
if (!_.isUndefined(objValue)) {
|
|
464
|
-
_.set(obj, `response.${_key}`, objValue);
|
|
465
|
-
_.unset(obj, `response.${key}`);
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
return obj;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
const encodeURIComponentUnique = (str) => {
|
|
473
|
-
if (_.startsWith(str, '{{') && _.endsWith(str, '}}')) {
|
|
474
|
-
return str;
|
|
475
|
-
} else {
|
|
476
|
-
try {
|
|
477
|
-
if (decodeURIComponent(str) == str) {
|
|
478
|
-
return encodeURIComponent(str);
|
|
479
|
-
}
|
|
480
|
-
return str;
|
|
481
|
-
} catch (e) {
|
|
482
|
-
return encodeURIComponent(str);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
const jsfGenerate = (schema, mockRules = [], lang, customFunctions = {}) => {
|
|
488
|
-
jsf.option({
|
|
489
|
-
alwaysFakeOptionals: true,
|
|
490
|
-
useExamplesValue: true,
|
|
491
|
-
fillProperties: false,
|
|
492
|
-
useDefaultValue: true,
|
|
493
|
-
mockRules,
|
|
494
|
-
customFunctions,
|
|
495
|
-
lang: 'zh-cn',
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
let genResult = undefined;
|
|
499
|
-
|
|
500
|
-
if (_.some(["default", "examples", "pattern", "format", "x-mock", "enum"], (value) => _.includes(_.keys(schema?.schema || schema), value))) {
|
|
501
|
-
try {
|
|
502
|
-
genResult = jsf.generate(schema);
|
|
503
|
-
} catch (e) { }
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
if (!_.isUndefined(genResult)) {
|
|
507
|
-
return genResult;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
const getVariableActedUpon = (eventRuntimeData, varName) => {
|
|
512
|
-
let actedUpon = undefined;
|
|
513
|
-
["variables", "iterationData", "environment", "globals"].some((type) => {
|
|
514
|
-
if (_.includes(_.keys(_.get(eventRuntimeData, `variables.${type}`)), varName)) {
|
|
515
|
-
actedUpon = type;
|
|
516
|
-
return true;
|
|
517
|
-
}
|
|
518
|
-
})
|
|
519
|
-
|
|
520
|
-
return actedUpon;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
const convertEndRuntimeState = (eventRuntimeData, event_id) => {
|
|
524
|
-
try {
|
|
525
|
-
const { startTime, startVariables } = _.get(eventRuntimeData, [event_id, 'iteration'], {});
|
|
526
|
-
const endTime = Date.now();
|
|
527
|
-
const startAllVars = {};
|
|
528
|
-
const startAllActedUponVars = {};
|
|
529
|
-
|
|
530
|
-
["globals", "environment", "iterationData", "variables"].forEach((type) => {
|
|
531
|
-
_.assign(startAllVars, _.get(startVariables, `${type}`))
|
|
532
|
-
})
|
|
533
|
-
|
|
534
|
-
_.forEach(startAllVars, (value, key) => {
|
|
535
|
-
_.set(startAllActedUponVars, [key, 'value'], value);
|
|
536
|
-
|
|
537
|
-
let startActedUpon = undefined;
|
|
538
|
-
|
|
539
|
-
if (!_.isUndefined(value)) {
|
|
540
|
-
["variables", "iterationData", "environment", "globals"].some((type) => {
|
|
541
|
-
if (!_.isUndefined(_.get(startVariables, [`${type}`, key]))) {
|
|
542
|
-
startActedUpon = type;
|
|
543
|
-
return true;
|
|
544
|
-
}
|
|
545
|
-
})
|
|
546
|
-
}
|
|
547
|
-
_.set(startAllActedUponVars, [key, 'actedUpon'], startActedUpon);
|
|
548
|
-
})
|
|
549
|
-
|
|
550
|
-
// 当前变量
|
|
551
|
-
const { environment = {}, variables = {}, _globals = {}, iterationData = {} } = _.get(eventRuntimeData, 'variables', {});
|
|
552
|
-
const endVariables = { environment, variables, iterationData, globals: _globals };
|
|
553
|
-
const endAllVars = {};
|
|
554
|
-
["globals", "environment", "iterationData", "variables"].forEach((type) => {
|
|
555
|
-
_.assign(endAllVars, _.get(endVariables, `${type}`))
|
|
556
|
-
})
|
|
557
|
-
|
|
558
|
-
// 变量追踪
|
|
559
|
-
const currentVariables = {};
|
|
560
|
-
|
|
561
|
-
_.forEach(endAllVars, (value, key) => {
|
|
562
|
-
if (!_.includes(['_pm.response.code', '_pm.response.setBody'], key)) {
|
|
563
|
-
let actedUpon = undefined;
|
|
564
|
-
["variables", "iterationData", "environment", "globals"].some((type) => {
|
|
565
|
-
if (!_.isUndefined(_.get(endVariables, [`${type}`, key]))) {
|
|
566
|
-
actedUpon = type;
|
|
567
|
-
return true;
|
|
568
|
-
}
|
|
569
|
-
})
|
|
570
|
-
|
|
571
|
-
_.set(currentVariables, [key], {
|
|
572
|
-
start: _.pick(startAllActedUponVars[key], ['value', 'actedUpon']),
|
|
573
|
-
current: { value, actedUpon }
|
|
574
|
-
})
|
|
575
|
-
}
|
|
576
|
-
})
|
|
577
|
-
|
|
578
|
-
return { startTime, endTime, currentVariables };
|
|
579
|
-
} catch (e) { }
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
module.exports = {
|
|
584
|
-
atomicSleep,
|
|
585
|
-
jsfGenerate,
|
|
586
|
-
getAPIFromCollection,
|
|
587
|
-
getParentTargetIDs,
|
|
588
|
-
base64toCacheFile,
|
|
589
|
-
replace2RegExp,
|
|
590
|
-
getInsideVariables,
|
|
591
|
-
repeatArrayToLength,
|
|
592
|
-
convertEndRuntimeState,
|
|
593
|
-
returnBoolean,
|
|
594
|
-
variableReplaceForCondition,
|
|
595
|
-
getCaseInsensitive,
|
|
596
|
-
camelCaseToSnakeCase,
|
|
597
|
-
formatAutotestReportList,
|
|
598
|
-
getVariableActedUpon,
|
|
599
|
-
variableReplace,
|
|
600
|
-
// createPipeServer,
|
|
601
|
-
formatAutotestReport,
|
|
602
|
-
encodeURIComponentUnique,
|
|
603
|
-
smartUrlJoin
|
|
604
|
-
}
|