runner-runtime 1.0.47 → 1.0.48
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 +18 -12
- package/events/index.js +11 -3
- package/index.js +1 -0
- package/package.json +2 -2
- package/tmp/request.js +146 -87
package/events/api.js
CHANGED
|
@@ -22,7 +22,6 @@ const { v4: uuidv4 } = require("uuid");
|
|
|
22
22
|
const fs = require("fs");
|
|
23
23
|
const { minimatch } = require("minimatch");
|
|
24
24
|
const runtime = require("postman-runtime-pro");
|
|
25
|
-
const { error } = require("console");
|
|
26
25
|
|
|
27
26
|
// 将api转postman请求参数
|
|
28
27
|
const convert2PostmanRequest = (request, option) => {
|
|
@@ -423,7 +422,7 @@ const convert2PostmanRequest = (request, option) => {
|
|
|
423
422
|
}
|
|
424
423
|
}
|
|
425
424
|
}
|
|
426
|
-
} catch (e) {}
|
|
425
|
+
} catch (e) { }
|
|
427
426
|
|
|
428
427
|
// 处理body
|
|
429
428
|
const body = {};
|
|
@@ -597,7 +596,7 @@ const convert2PostmanOptions = (request, option, variables) => {
|
|
|
597
596
|
const globals = new sdk.VariableScope({
|
|
598
597
|
values: globalsVariables,
|
|
599
598
|
});
|
|
600
|
-
|
|
599
|
+
|
|
601
600
|
const requester = {
|
|
602
601
|
strictSSL: false,
|
|
603
602
|
protocolVersion: requestJson?.protocol == 'http/1.1' ? 'http1' : 'http2',
|
|
@@ -1142,11 +1141,11 @@ const convert2PostmanEvent = (request, listen, option) => {
|
|
|
1142
1141
|
exec = `${exec}
|
|
1143
1142
|
! await (async function(){
|
|
1144
1143
|
const dbData = ${JSON.stringify(item.data || { query: '' })}
|
|
1145
|
-
const query = pm.variables.replaceIn(
|
|
1146
|
-
const method = pm.variables.replaceIn(
|
|
1144
|
+
const query = pm.variables.replaceIn(lodashv4.get(dbData, "query"));
|
|
1145
|
+
const method = pm.variables.replaceIn(lodashv4.get(dbData, "method") || "");
|
|
1147
1146
|
|
|
1148
1147
|
try{
|
|
1149
|
-
let dbResultList = await pm.queryDatabase(
|
|
1148
|
+
let dbResultList = await pm.queryDatabase(lodashv4.assign(${dbconfig},{
|
|
1150
1149
|
method:method,
|
|
1151
1150
|
query:query
|
|
1152
1151
|
}));
|
|
@@ -1157,14 +1156,14 @@ const convert2PostmanEvent = (request, listen, option) => {
|
|
|
1157
1156
|
if(${item.data?.isConsoleOutput} > 0){
|
|
1158
1157
|
console.log(query, result)
|
|
1159
1158
|
}
|
|
1160
|
-
if(
|
|
1161
|
-
|
|
1162
|
-
let extra_value = jsonpath.value(result,
|
|
1159
|
+
if(lodashv4.isObject(result)){
|
|
1160
|
+
lodashv4.forEach(${JSON.stringify(item.data?.variables || [])}, (item) => {
|
|
1161
|
+
let extra_value = jsonpath.value(result, lodashv4.trim(item?.pattern));
|
|
1163
1162
|
pm[item?.type].set(item?.name, extra_value);
|
|
1164
1163
|
});
|
|
1165
1164
|
}else{
|
|
1166
|
-
if(!
|
|
1167
|
-
|
|
1165
|
+
if(!lodashv4.isObject(result)){
|
|
1166
|
+
lodashv4.forEach(${JSON.stringify(item.data?.variables || [])}, (item) => {
|
|
1168
1167
|
let extra_value = result;
|
|
1169
1168
|
pm[item?.type].set(item?.name, extra_value);
|
|
1170
1169
|
});
|
|
@@ -2297,6 +2296,7 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
2297
2296
|
},
|
|
2298
2297
|
|
|
2299
2298
|
assertion(cursor, assertions) {
|
|
2299
|
+
console.log(JSON.stringify(assertions, null, 2), 111111)
|
|
2300
2300
|
if (!_.includes(['get_parsed_request'], scene)) {
|
|
2301
2301
|
if (!_.isEmpty(assertions) && _.isArray(assertions)) {
|
|
2302
2302
|
if (_.isUndefined(_.get(eventRuntimeData, [event?.event_id, "assertions"]))) {
|
|
@@ -2345,11 +2345,17 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
|
|
|
2345
2345
|
}
|
|
2346
2346
|
|
|
2347
2347
|
// 返回结果
|
|
2348
|
+
// 增加控制器开始时间
|
|
2349
|
+
_.set(eventRuntimeData, [event.event_id, 'iteration', 'endTime'], Date.now());
|
|
2350
|
+
|
|
2351
|
+
// 增加初始化变量
|
|
2352
|
+
const { environment = {}, variables = {}, _globals = {}, iterationData = {} } = _.get(eventRuntimeData, 'variables', {});
|
|
2353
|
+
_.set(eventRuntimeData, [event.event_id, 'iteration', 'endVariables'], { environment, variables, iterationData, globals: _globals });
|
|
2348
2354
|
const tempVars = _.pick(_.get(eventRuntimeData, 'variables'), ['environment', '_globals']);
|
|
2349
2355
|
const toLowerResponseJson = camelCaseToSnakeCase(_.get(eventRuntimeData, event?.event_id));
|
|
2350
2356
|
const finalRequestResult = _.assign(
|
|
2351
2357
|
_.pick(requestJson, ['parent_id', 'project_id', 'test_id', 'target_id']),
|
|
2352
|
-
_.defaults(_.pick(toLowerResponseJson, ['error', 'iteration_id']), { error: null }),
|
|
2358
|
+
_.defaults(_.pick(toLowerResponseJson, ['error', 'iteration_id','iteration']), { error: null }),
|
|
2353
2359
|
{
|
|
2354
2360
|
action: 'request',
|
|
2355
2361
|
type: 'request',
|
package/events/index.js
CHANGED
|
@@ -230,22 +230,30 @@ const events = {
|
|
|
230
230
|
|
|
231
231
|
// 调度器核心函数,用于递归执行具体场景步骤
|
|
232
232
|
const executeEvent = (event, option, callback, eventRuntimeData, eventResultList) => {
|
|
233
|
+
// console.log(_.cloneDeep(eventRuntimeData?.variables),1111111)
|
|
233
234
|
return new Promise((resolve, reject) => {
|
|
234
235
|
if (_.isUndefined(event.event_id) && option?.scene === 'http_request') {
|
|
235
236
|
_.set(event, 'event_id', _.get(event, 'data.target_id'))
|
|
236
237
|
}
|
|
237
|
-
|
|
238
|
+
|
|
238
239
|
_.assign(eventRuntimeData?.variables?.iterationData, _.get(option, 'iterationData'))
|
|
239
240
|
_.set(eventRuntimeData, [event.event_id, 'iteration_id'], aTools.snowflakeId());
|
|
240
241
|
|
|
241
242
|
const eventCall = _.get(events, `${event?.type}`);
|
|
242
243
|
|
|
243
244
|
if (_.isFunction(eventCall)) {
|
|
245
|
+
const { total, scene } = option;
|
|
246
|
+
|
|
247
|
+
// 增加控制器开始时间
|
|
248
|
+
_.set(eventRuntimeData, [event.event_id, 'iteration', 'startTime'], Date.now());
|
|
249
|
+
|
|
250
|
+
// 增加初始化变量
|
|
251
|
+
const { environment = {}, variables = {}, _globals = {}, iterationData = {} } = _.get(eventRuntimeData, 'variables', {});
|
|
252
|
+
_.set(eventRuntimeData, [event.event_id, 'iteration', 'startVariables'], _.cloneDeep({ environment, variables, iterationData, globals: _globals }));
|
|
253
|
+
|
|
244
254
|
try {
|
|
245
255
|
eventCall(event, option, callback, eventRuntimeData, eventResultList).then((data) => {
|
|
246
256
|
resolve(data);
|
|
247
|
-
|
|
248
|
-
const { total, scene } = option;
|
|
249
257
|
if (scene == 'auto_test' && _.isInteger(event?.progress)) {
|
|
250
258
|
callback({
|
|
251
259
|
action: 'process',
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "runner-runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.48",
|
|
4
4
|
"description": "runner-runtime.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"is-image": "^3.0.0",
|
|
31
31
|
"is-svg": "^4.3.2",
|
|
32
32
|
"json-bigint": "^1.0.0",
|
|
33
|
-
"json-schema-faker-pro": "^0.5.
|
|
33
|
+
"json-schema-faker-pro": "^0.5.15",
|
|
34
34
|
"json5": "^2.2.3",
|
|
35
35
|
"jsonpath": "^1.1.1",
|
|
36
36
|
"lodash": "^4.17.21",
|
package/tmp/request.js
CHANGED
|
@@ -70,6 +70,13 @@ module.exports = {
|
|
|
70
70
|
"server_id": "1",
|
|
71
71
|
"server_type": 1,
|
|
72
72
|
"uri": ""
|
|
73
|
+
},
|
|
74
|
+
"1a9074f63fc07001": {
|
|
75
|
+
"sort": 600,
|
|
76
|
+
"name": "Idea_apipost-demo",
|
|
77
|
+
"server_id": "1a9074f63fc07001",
|
|
78
|
+
"server_type": -1,
|
|
79
|
+
"uri": ""
|
|
73
80
|
}
|
|
74
81
|
},
|
|
75
82
|
"environment": {}
|
|
@@ -108,126 +115,178 @@ module.exports = {
|
|
|
108
115
|
"custom_functions": {},
|
|
109
116
|
"collection": [
|
|
110
117
|
{
|
|
111
|
-
"target_id": "
|
|
118
|
+
"target_id": "1a9078f904007002",
|
|
112
119
|
"target_type": "api",
|
|
113
|
-
"parent_id": "
|
|
114
|
-
"name": "
|
|
120
|
+
"parent_id": "1a9078d81a407002",
|
|
121
|
+
"name": "/t3/save10",
|
|
115
122
|
"request": {
|
|
116
123
|
"auth": {
|
|
117
|
-
"type": "
|
|
124
|
+
"type": "noauth"
|
|
118
125
|
},
|
|
119
126
|
"header": {
|
|
120
|
-
"parameter": [
|
|
121
|
-
{
|
|
122
|
-
"description": "",
|
|
123
|
-
"field_type": "string",
|
|
124
|
-
"is_checked": 1,
|
|
125
|
-
"key": "h1",
|
|
126
|
-
"value": "",
|
|
127
|
-
"not_null": 1,
|
|
128
|
-
"schema": {
|
|
129
|
-
"type": "string",
|
|
130
|
-
"x-mock": "{{'123456'|md5}}"
|
|
131
|
-
},
|
|
132
|
-
"param_id": "604725e36e00e"
|
|
133
|
-
}
|
|
134
|
-
]
|
|
127
|
+
"parameter": []
|
|
135
128
|
},
|
|
136
129
|
"query": {
|
|
137
130
|
"query_add_equal": 1,
|
|
138
|
-
"parameter": [
|
|
139
|
-
{
|
|
140
|
-
"description": "",
|
|
141
|
-
"field_type": "string",
|
|
142
|
-
"is_checked": 1,
|
|
143
|
-
"key": "q1",
|
|
144
|
-
"value": "",
|
|
145
|
-
"not_null": 1,
|
|
146
|
-
"schema": {
|
|
147
|
-
"type": "string",
|
|
148
|
-
"x-mock": "{{'222'|md5}}"
|
|
149
|
-
},
|
|
150
|
-
"param_id": "604365b39b00c"
|
|
151
|
-
}
|
|
152
|
-
]
|
|
131
|
+
"parameter": []
|
|
153
132
|
},
|
|
154
133
|
"restful": {
|
|
155
134
|
"parameter": []
|
|
156
135
|
},
|
|
157
136
|
"cookie": {
|
|
158
137
|
"cookie_encode": 1,
|
|
159
|
-
"parameter": [
|
|
138
|
+
"parameter": []
|
|
139
|
+
},
|
|
140
|
+
"body": {
|
|
141
|
+
"mode": "json",
|
|
142
|
+
"parameter": [],
|
|
143
|
+
"binary": "",
|
|
144
|
+
"raw": "{\n \"map2\": {\n \"KEY\": {\n \"roleId\": 1,\n \"roleName\": \"\"\n }\n }\n}",
|
|
145
|
+
"raw_parameter": [
|
|
160
146
|
{
|
|
147
|
+
"key": "map2",
|
|
148
|
+
"value": "",
|
|
149
|
+
"type": "Text",
|
|
161
150
|
"description": "",
|
|
162
|
-
"field_type": "string",
|
|
163
151
|
"is_checked": 1,
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"not_null": 1,
|
|
167
|
-
"schema": {
|
|
168
|
-
"type": "string"
|
|
169
|
-
},
|
|
170
|
-
"param_id": "6042d1bb5e00a"
|
|
152
|
+
"not_null": "0",
|
|
153
|
+
"field_type": "Object"
|
|
171
154
|
},
|
|
172
155
|
{
|
|
173
|
-
"
|
|
174
|
-
"field_type": "string",
|
|
175
|
-
"is_checked": 1,
|
|
176
|
-
"key": "cookie11111",
|
|
156
|
+
"key": "map2.KEY",
|
|
177
157
|
"value": "",
|
|
178
|
-
"
|
|
179
|
-
"static": true,
|
|
180
|
-
"schema": {
|
|
181
|
-
"type": "string"
|
|
182
|
-
},
|
|
183
|
-
"param_id": "604398079b00d"
|
|
184
|
-
}
|
|
185
|
-
]
|
|
186
|
-
},
|
|
187
|
-
"body": {
|
|
188
|
-
"mode": "urlencoded",
|
|
189
|
-
"parameter": [
|
|
190
|
-
{
|
|
158
|
+
"type": "Text",
|
|
191
159
|
"description": "",
|
|
192
|
-
"field_type": "string",
|
|
193
160
|
"is_checked": 1,
|
|
194
|
-
"
|
|
195
|
-
"
|
|
196
|
-
"not_null": 1,
|
|
197
|
-
"schema": {
|
|
198
|
-
"type": "string",
|
|
199
|
-
"x-mock": "{{$mockjs.telephone()}}"
|
|
200
|
-
},
|
|
201
|
-
"param_id": "600c409771006"
|
|
161
|
+
"not_null": "0",
|
|
162
|
+
"field_type": "Object"
|
|
202
163
|
},
|
|
203
164
|
{
|
|
204
|
-
"
|
|
205
|
-
"
|
|
165
|
+
"key": "map2.KEY.roleId",
|
|
166
|
+
"value": "1",
|
|
167
|
+
"type": "Text",
|
|
168
|
+
"description": "角色id",
|
|
206
169
|
"is_checked": 1,
|
|
207
|
-
"
|
|
170
|
+
"not_null": "0",
|
|
171
|
+
"field_type": "Integer"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"key": "map2.KEY.roleName",
|
|
208
175
|
"value": "",
|
|
209
|
-
"
|
|
210
|
-
"
|
|
211
|
-
"
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
"param_id": "6043189b5e00b"
|
|
176
|
+
"type": "Text",
|
|
177
|
+
"description": "角色名称",
|
|
178
|
+
"is_checked": 1,
|
|
179
|
+
"not_null": "0",
|
|
180
|
+
"field_type": "String"
|
|
215
181
|
}
|
|
216
182
|
],
|
|
217
|
-
"binary": "",
|
|
218
|
-
"raw": "",
|
|
219
|
-
"raw_parameter": [],
|
|
220
183
|
"raw_schema": {
|
|
221
|
-
"type": "object"
|
|
184
|
+
"type": "object",
|
|
185
|
+
"properties": {},
|
|
186
|
+
"APIPOST_ORDERS": [
|
|
187
|
+
"1a909547a042b003"
|
|
188
|
+
],
|
|
189
|
+
"APIPOST_REFS": {
|
|
190
|
+
"1a909547a042b003": {}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
"pre_tasks": [
|
|
195
|
+
{
|
|
196
|
+
"type": "customScript",
|
|
197
|
+
"id": "b40b7cc7d600d",
|
|
198
|
+
"name": "自定义脚本",
|
|
199
|
+
"enabled": 1,
|
|
200
|
+
"data": "pm.environment.set(\"key\", \"value\");\npm.variables.set(\"haha\",\"666666\")"
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
"post_tasks": [
|
|
204
|
+
{
|
|
205
|
+
"type": "customScript",
|
|
206
|
+
"id": "b121041317005",
|
|
207
|
+
"name": "自定义脚本",
|
|
208
|
+
"enabled": -1,
|
|
209
|
+
"data": "apt.test(\"响应时间小于 200ms\", function () {\n apt.expect(apt.response.responseTime).to.be.below(200);\n });\napt.test(\"成功的POST请求\", function () {\n apt.expect(apt.response.code).to.be.oneOf([201, 202]);\n });\napt.test(\"状态码包含字符串\", function () {\n apt.response.to.have.status(\"Created\");\n });\nvar jsonObject = xml2Json(responseBody);\nvar schema = {\n \"items\": {\n \"type\": \"boolean\"\n }\n };\n\n var data1 = [true, false];\n var data2 = [true, 123];\n\n apt.test('Schema is valid', function () {\n apt.expect(tv4.validate(data1, schema)).to.be.true;\n apt.expect(tv4.validate(data2, schema)).to.be.true;\n });\npm.response.setBody(\"Response Body\");\napt.test(\"响应码为 200\", function () {\n apt.response.to.have.status(200);\n });"
|
|
222
210
|
}
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
"parents": [
|
|
214
|
+
{
|
|
215
|
+
"target_id": "1a9078d81a407002",
|
|
216
|
+
"target_type": "folder"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"target_id": "1a9078d816407002",
|
|
220
|
+
"target_type": "folder",
|
|
221
|
+
"server_id": "1a9074f63fc07001"
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
"server_id": "1a9074f63fc07001",
|
|
225
|
+
"method": "POST",
|
|
226
|
+
"protocol": "http/1.1",
|
|
227
|
+
"url": "https://httpbin.org/anything",
|
|
228
|
+
"pre_url": ""
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"target_id": "1a9078d816407002",
|
|
232
|
+
"target_type": "folder",
|
|
233
|
+
"parent_id": "0",
|
|
234
|
+
"name": "apipost-demo",
|
|
235
|
+
"request": {
|
|
236
|
+
"header": {
|
|
237
|
+
"parameter": []
|
|
238
|
+
},
|
|
239
|
+
"query": {
|
|
240
|
+
"parameter": []
|
|
241
|
+
},
|
|
242
|
+
"body": {
|
|
243
|
+
"parameter": []
|
|
244
|
+
},
|
|
245
|
+
"cookie": {
|
|
246
|
+
"parameter": []
|
|
247
|
+
},
|
|
248
|
+
"auth": {
|
|
249
|
+
"type": "noauth"
|
|
223
250
|
},
|
|
224
251
|
"pre_tasks": [],
|
|
225
252
|
"post_tasks": []
|
|
226
253
|
},
|
|
227
254
|
"parents": [],
|
|
228
|
-
"
|
|
229
|
-
"
|
|
230
|
-
|
|
255
|
+
"server_id": "1a9074f63fc07001",
|
|
256
|
+
"pre_url": ""
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"target_id": "1a9078d81a407002",
|
|
260
|
+
"target_type": "folder",
|
|
261
|
+
"parent_id": "1a9078d816407002",
|
|
262
|
+
"name": "测试类3",
|
|
263
|
+
"request": {
|
|
264
|
+
"header": {
|
|
265
|
+
"parameter": []
|
|
266
|
+
},
|
|
267
|
+
"query": {
|
|
268
|
+
"parameter": []
|
|
269
|
+
},
|
|
270
|
+
"body": {
|
|
271
|
+
"parameter": []
|
|
272
|
+
},
|
|
273
|
+
"cookie": {
|
|
274
|
+
"parameter": []
|
|
275
|
+
},
|
|
276
|
+
"auth": {
|
|
277
|
+
"type": "noauth"
|
|
278
|
+
},
|
|
279
|
+
"pre_tasks": [],
|
|
280
|
+
"post_tasks": []
|
|
281
|
+
},
|
|
282
|
+
"parents": [
|
|
283
|
+
{
|
|
284
|
+
"target_id": "1a9078d816407002",
|
|
285
|
+
"target_type": "folder",
|
|
286
|
+
"server_id": "1a9074f63fc07001"
|
|
287
|
+
}
|
|
288
|
+
],
|
|
289
|
+
"server_id": "0",
|
|
231
290
|
"pre_url": ""
|
|
232
291
|
}
|
|
233
292
|
],
|
|
@@ -237,9 +296,9 @@ module.exports = {
|
|
|
237
296
|
{
|
|
238
297
|
"type": "api",
|
|
239
298
|
"data": {
|
|
240
|
-
"target_id": "
|
|
299
|
+
"target_id": "1a9078f904007002",
|
|
241
300
|
"project_id": "1a8b7f4d6f51e002",
|
|
242
|
-
"parent_id": "
|
|
301
|
+
"parent_id": "1a9078d81a407002",
|
|
243
302
|
"target_type": "api"
|
|
244
303
|
}
|
|
245
304
|
}
|