runner-runtime 1.0.27 → 1.0.30
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/events/api.js +56 -17
- package/events/index.js +15 -0
- package/index.js +19 -6
- package/libs/utils.js +9 -1
- package/package.json +1 -1
- package/tmp/request.js +104 -1345
package/events/api.js
CHANGED
|
@@ -414,7 +414,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
414
414
|
_.forEach(parameter, (item) => {
|
|
415
415
|
if (_.isObject(item)) {
|
|
416
416
|
if (item.is_checked > 0 && autoReplaceMockVar(item.key) != '') {
|
|
417
|
-
if (bodyMode == "form-data" && item.field_type
|
|
417
|
+
if (bodyMode == "form-data" && _.toLower(item.field_type) === "file") {
|
|
418
418
|
const src = base64toCacheFile(
|
|
419
419
|
item.key,
|
|
420
420
|
item.value,
|
|
@@ -1761,6 +1761,7 @@ const preProcessMockExp = (request, requestPara, AllVars, option) => {
|
|
|
1761
1761
|
|
|
1762
1762
|
// 初始化api请求参数
|
|
1763
1763
|
const initRequestJson = (event, option) => {
|
|
1764
|
+
|
|
1764
1765
|
// 获取具体的请求详情
|
|
1765
1766
|
const requestJson = _.assign(_.pick(event, ['event_id', 'test_id']), _.pick(event?.data, ['target_id', 'project_id']));
|
|
1766
1767
|
|
|
@@ -2019,7 +2020,16 @@ const initRequestJson = (event, option) => {
|
|
|
2019
2020
|
})
|
|
2020
2021
|
|
|
2021
2022
|
_.set(requestJson, "initVarReplacedUrl", initVarReplacedUrl);
|
|
2022
|
-
} else if (_.includes(['script'
|
|
2023
|
+
} else if (_.includes(['script'], event?.type)) { // 脚本、断言 todo... 断言需要做成可视化的
|
|
2024
|
+
_.set(requestJson, "request.pre_tasks", [
|
|
2025
|
+
{
|
|
2026
|
+
type: "customScript",
|
|
2027
|
+
enabled: 1,
|
|
2028
|
+
data: event?.data?.content,
|
|
2029
|
+
},
|
|
2030
|
+
]);
|
|
2031
|
+
} else if (_.includes(['assert'], event?.type)) { // 脚本、断言 todo... 断言需要做成可视化的
|
|
2032
|
+
_.set(requestJson, "name", "脚本断言");
|
|
2023
2033
|
_.set(requestJson, "request.pre_tasks", [
|
|
2024
2034
|
{
|
|
2025
2035
|
type: "customScript",
|
|
@@ -2043,9 +2053,10 @@ const initRequestJson = (event, option) => {
|
|
|
2043
2053
|
}
|
|
2044
2054
|
])
|
|
2045
2055
|
} else if (_.includes(['assert_visual'], event?.type)) {
|
|
2046
|
-
const { type, expression } = event?.data || {};
|
|
2056
|
+
const { type, expression } = event?.data?.data || {};
|
|
2047
2057
|
|
|
2048
2058
|
if (_.isString(type) && !_.isEmpty(expression)) {
|
|
2059
|
+
_.set(requestJson, "name", "可视化断言");
|
|
2049
2060
|
_.set(requestJson, "request.pre_tasks", [
|
|
2050
2061
|
{
|
|
2051
2062
|
"type": "assert",
|
|
@@ -2075,6 +2086,8 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
2075
2086
|
return new Promise((resolve) => {
|
|
2076
2087
|
try {
|
|
2077
2088
|
const { requestJson, postmanJSON } = initRequestJson(event, option)
|
|
2089
|
+
|
|
2090
|
+
console.log(requestJson,`eventeventeventeventeventeventeventeventeventeventevent`)
|
|
2078
2091
|
const collection = new sdk.Item({
|
|
2079
2092
|
name: _.get(requestJson, "name") || "New request", request: postmanJSON, event: [], protocolProfileBehavior: {
|
|
2080
2093
|
disableBodyPruning: true,
|
|
@@ -2107,14 +2120,16 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
2107
2120
|
// script error
|
|
2108
2121
|
exception(cursor, err) {
|
|
2109
2122
|
if (err) {
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2123
|
+
if (!_.includes(['assert_visual', 'assert'], event?.type)) {
|
|
2124
|
+
const scriptType = _.get(cursor, cursor?.scriptId);
|
|
2125
|
+
_.set(eventRuntimeData, [event?.event_id, "exception", scriptType], err);
|
|
2126
|
+
_.set(eventRuntimeData, [event?.event_id, 'error'], {
|
|
2127
|
+
error_type: scriptType,
|
|
2128
|
+
message: err?.message
|
|
2129
|
+
})
|
|
2130
|
+
if (scriptType === 'prerequest') {
|
|
2131
|
+
run.abort();
|
|
2132
|
+
}
|
|
2118
2133
|
}
|
|
2119
2134
|
}
|
|
2120
2135
|
},
|
|
@@ -2156,7 +2171,15 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
2156
2171
|
const currentVar = _.get(result, `result.${varType}`);
|
|
2157
2172
|
try {
|
|
2158
2173
|
_.forEach(currentVar.toObject(), (val, key) => {
|
|
2159
|
-
|
|
2174
|
+
let setPath = varType;
|
|
2175
|
+
if (varType === '_variables') {
|
|
2176
|
+
setPath = 'variables';
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
if (varType === 'globals' && !_.includes(_.keys(getInsideVariables()), key)) {
|
|
2180
|
+
_.set(eventRuntimeData, ["variables", '_globals', key], val)
|
|
2181
|
+
}
|
|
2182
|
+
_.set(eventRuntimeData, ["variables", setPath, key], val)
|
|
2160
2183
|
})
|
|
2161
2184
|
} catch (e) { }
|
|
2162
2185
|
})
|
|
@@ -2170,7 +2193,7 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
2170
2193
|
_.set(eventRuntimeData, [event?.event_id, "response"], await convert2EchoResponse(response, history));
|
|
2171
2194
|
}
|
|
2172
2195
|
} else {
|
|
2173
|
-
if (!_.includes(['script', 'sql'], event?.type)) {
|
|
2196
|
+
if (!_.includes(['script', 'sql', 'assert_visual', 'assert'], event?.type)) {
|
|
2174
2197
|
_.set(eventRuntimeData, [event?.event_id, "exception", 'prerequest'], String(err));
|
|
2175
2198
|
_.set(eventRuntimeData, [event?.event_id, 'error'], {
|
|
2176
2199
|
error_type: 'prerequest',
|
|
@@ -2211,7 +2234,15 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
2211
2234
|
const currentVar = _.get(result, `result.${varType}`);
|
|
2212
2235
|
try {
|
|
2213
2236
|
_.forEach(currentVar.toObject(), (val, key) => {
|
|
2214
|
-
|
|
2237
|
+
let setPath = varType;
|
|
2238
|
+
if (varType === '_variables') {
|
|
2239
|
+
setPath = 'variables';
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
if (varType === 'globals' && !_.includes(_.keys(getInsideVariables()), key)) {
|
|
2243
|
+
_.set(eventRuntimeData, ["variables", '_globals', key], val)
|
|
2244
|
+
}
|
|
2245
|
+
_.set(eventRuntimeData, ["variables", setPath, key], val)
|
|
2215
2246
|
})
|
|
2216
2247
|
} catch (e) { }
|
|
2217
2248
|
})
|
|
@@ -2269,16 +2300,24 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
2269
2300
|
}
|
|
2270
2301
|
|
|
2271
2302
|
// 写入到自动化测试结果
|
|
2303
|
+
const tempVars = _.pick(_.get(eventRuntimeData, 'variables'), ['environment', '_globals']);
|
|
2272
2304
|
const finalRequestResult = _.assign({
|
|
2273
|
-
action: '
|
|
2274
|
-
data:
|
|
2305
|
+
action: 'request',
|
|
2306
|
+
data: _.assign(
|
|
2307
|
+
{
|
|
2308
|
+
variables: {
|
|
2309
|
+
global: _.get(tempVars, '_globals', {}),
|
|
2310
|
+
environment: _.get(tempVars, 'environment', {})
|
|
2311
|
+
}
|
|
2312
|
+
},
|
|
2313
|
+
camelCaseToSnakeCase(_.get(eventRuntimeData, event?.event_id))),
|
|
2275
2314
|
error: _.get(eventRuntimeData, [event?.event_id, 'error', 'message']) || null,
|
|
2276
2315
|
event_id: event?.event_id,
|
|
2277
2316
|
iteration_id: _.get(eventRuntimeData, [event?.event_id, 'iteration_id'])
|
|
2278
2317
|
}, _.pick(requestJson, ['parent_id', 'project_id', 'test_id', 'target_id']));
|
|
2279
2318
|
|
|
2280
2319
|
if (scene === 'auto_test' && _.includes(['assert', 'assert_visual', 'api', 'sample'], event?.type)) {
|
|
2281
|
-
eventResultList.push(_.assign(camelCaseToSnakeCase(_.get(eventRuntimeData, event?.event_id)), _.pick(event, ['type', 'event_id', 'test_id', 'iteration_id'])));
|
|
2320
|
+
eventResultList.push(_.assign(camelCaseToSnakeCase(_.get(_.cloneDeep(eventRuntimeData), event?.event_id)), _.pick(event, ['type', 'event_id', 'test_id', 'iteration_id'])));
|
|
2282
2321
|
|
|
2283
2322
|
resolve({
|
|
2284
2323
|
action: 'request',
|
package/events/index.js
CHANGED
|
@@ -57,6 +57,7 @@ const events = {
|
|
|
57
57
|
const { iterationData, enable_data } = data;
|
|
58
58
|
|
|
59
59
|
if (_.toInteger(enable_data) > 0) {
|
|
60
|
+
console.log(_.assign(_.cloneDeep(option), { iterationData }),11111111111111)
|
|
60
61
|
await iterationEvent(children, _.assign(_.cloneDeep(option), { iterationData }), callback, eventRuntimeData, eventResultList)
|
|
61
62
|
} else {
|
|
62
63
|
await iterationEvent(children, option, callback, eventRuntimeData, eventResultList)
|
|
@@ -201,6 +202,20 @@ const executeEvent = (event, option, callback, eventRuntimeData, eventResultList
|
|
|
201
202
|
iteration_id: aTools.snowflakeId()
|
|
202
203
|
});
|
|
203
204
|
}
|
|
205
|
+
|
|
206
|
+
const environment = _.get(option, 'env.environment', {});
|
|
207
|
+
const globals = _.get(option, 'globals', {});
|
|
208
|
+
const iterationData = _.get(option, 'iterationData', {});
|
|
209
|
+
const tempVars = { environment, globals, iterationData };
|
|
210
|
+
|
|
211
|
+
['environment', 'globals', 'iterationData'].forEach((type) => {
|
|
212
|
+
_.forEach(tempVars[type], (value, key) => {
|
|
213
|
+
if (_.isUndefined(_.get(eventRuntimeData, ['variables', type, key]))) {
|
|
214
|
+
_.set(eventRuntimeData, ['variables', type, key], value)
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
})
|
|
218
|
+
|
|
204
219
|
const eventCall = _.get(events, `${event?.type}`);
|
|
205
220
|
|
|
206
221
|
if (_.isFunction(eventCall)) {
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { repeatArrayToLength, formatAutotestReport,formatAutotestReportList } = require('./libs/utils');
|
|
1
|
+
const { repeatArrayToLength, formatAutotestReport, formatAutotestReportList } = require('./libs/utils');
|
|
2
2
|
const _ = require('lodash');
|
|
3
3
|
const moment = require('moment');
|
|
4
4
|
const aTools = require("apipost-tools");
|
|
@@ -12,8 +12,14 @@ const run = async (events, option, callback) => {
|
|
|
12
12
|
const iterationDataArr = repeatArrayToLength(iterationData, _.size(tempEvents));
|
|
13
13
|
const eventOptions = _.pick(option, ["scene", "lang", "project", "env", "globals", "cookies", "system_configs", "custom_functions", "collection", "database_configs", "enable_sandbox", "sleep", "name", "testing_id"]);
|
|
14
14
|
const eventRuntimeData = {
|
|
15
|
-
variables: {
|
|
15
|
+
variables: {
|
|
16
|
+
environment: {},
|
|
17
|
+
globals: {},
|
|
18
|
+
_globals: {},
|
|
19
|
+
iterationData: {},
|
|
20
|
+
}
|
|
16
21
|
};
|
|
22
|
+
|
|
17
23
|
const eventResultList = [];
|
|
18
24
|
const startTimeAt = Date.now();
|
|
19
25
|
|
|
@@ -51,12 +57,19 @@ const run = async (events, option, callback) => {
|
|
|
51
57
|
})
|
|
52
58
|
}
|
|
53
59
|
|
|
60
|
+
const tempVars = _.pick(_.get(eventRuntimeData, 'variables'), ['environment', '_globals']);
|
|
61
|
+
|
|
54
62
|
callback({
|
|
55
63
|
action: 'complete',
|
|
56
|
-
data: _.assign(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
data: _.assign(
|
|
65
|
+
formatAutotestReport(startTimeAt, eventResultList),
|
|
66
|
+
{
|
|
67
|
+
list: formatAutotestReportList(eventResultList),
|
|
68
|
+
variables: {
|
|
69
|
+
global: option?.enable_sandbox > 0 ? {} : _.get(tempVars, '_globals', {}),
|
|
70
|
+
environment: option?.enable_sandbox > 0 ? {} : _.get(tempVars, 'environment', {})
|
|
71
|
+
}
|
|
72
|
+
},
|
|
60
73
|
_.pick(_.get(option, 'env', {}), ['env_id', 'env_name']),
|
|
61
74
|
{ testing_id: _.get(_.first(eventResultList), 'test_id') },
|
|
62
75
|
{ report_name: `${moment().format('YYYY-MM-DD HH:mm:ss')}` },
|
package/libs/utils.js
CHANGED
|
@@ -439,11 +439,19 @@ const variableReplace = (str, variables, option) => {
|
|
|
439
439
|
const formatAutotestReportList = (eventResultList) => {
|
|
440
440
|
const list = []
|
|
441
441
|
_.forEach(eventResultList, (item) => {
|
|
442
|
+
let type = item?.type;
|
|
443
|
+
|
|
444
|
+
if (_.includes(['assert_visual', 'assert'], item?.type)) {
|
|
445
|
+
type = 'api';
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// console.log(item?.response,3333333333)
|
|
442
449
|
list.push(_.assign(
|
|
443
450
|
_.pick(item?.response, ['timings', 'response_time', 'response_at', 'proxy', 'status', 'code', 'response_size']),
|
|
444
451
|
_.pick(item?.request, ['url', 'method', 'name', 'target_id', 'project_id']),
|
|
445
452
|
_.pick(item, ['type', 'event_id', 'test_id', 'iteration_id']),
|
|
446
453
|
{
|
|
454
|
+
type,
|
|
447
455
|
'status': {
|
|
448
456
|
"assert": _.isEmpty(item?.status?.success_assert) ? "OK" : item?.status?.success_assert,
|
|
449
457
|
"http": item?.status?.http || "OK"
|
|
@@ -451,7 +459,7 @@ const formatAutotestReportList = (eventResultList) => {
|
|
|
451
459
|
},
|
|
452
460
|
))
|
|
453
461
|
})
|
|
454
|
-
|
|
462
|
+
console.log(JSON.stringify(list, null,2))
|
|
455
463
|
return list;
|
|
456
464
|
}
|
|
457
465
|
|