runner-runtime 1.0.71 → 1.0.73

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 CHANGED
@@ -614,7 +614,7 @@ const convert2PostmanOptions = (request, option, variables) => {
614
614
  values: globalsVariables,
615
615
  });
616
616
 
617
- const protocolVersion = requestJson?.protocol == 'http/1.1' ? 'http1' : (requestJson?.protocol == 'auto' ? 'auto' : 'http2');
617
+ const protocolVersion = (requestJson?.protocol == 'http/1.1' || _.includes(['sse'], requestJson?.target_type) || _.isEmpty(requestJson?.target_type)) ? 'http1' : (requestJson?.protocol == 'auto' ? 'auto' : 'http2');
618
618
  const requester = {
619
619
  strictSSL: false,
620
620
  protocolVersion,
@@ -893,10 +893,9 @@ const convert2PostmanEvent = (request, listen, option) => {
893
893
  }
894
894
  };
895
895
 
896
- // pm.execute
897
- pm.execute = async (file, args, option) => {
898
- const { createUnixClient } = require('net'),
899
- socketPath = getMainProcessSocketPath();
896
+ // pm.execute/Async
897
+ pm.executeAsync = pm.execute = async (file, args, option) => {
898
+ const { createUnixClient } = require('net'), socketPath = getMainProcessSocketPath();
900
899
 
901
900
  try {
902
901
  const result = await createUnixClient(socketPath, JSON.stringify({
@@ -912,8 +911,7 @@ const convert2PostmanEvent = (request, listen, option) => {
912
911
  console.error("pm.execute error: " + String(resultObj?.result))
913
912
  throw new Error(resultObj?.result);
914
913
  }
915
- }
916
- catch (e) {
914
+ }catch (e) {
917
915
  console.error("pm.execute error: " + String(e))
918
916
  throw new Error(e);
919
917
  }
@@ -2243,8 +2241,31 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
2243
2241
  _.forEach(results, (result) => {
2244
2242
  _.forEach(['_variables', 'environment', 'globals'], (varType) => {
2245
2243
  const currentVar = _.get(result, `result.${varType}`);
2244
+ const currentVarObject = {};
2245
+
2246
+ try {
2247
+ _.forEach(_.get(currentVar.toJSON(), 'values'), (item) => {
2248
+ currentVarObject[item?.key] = item?.value;
2249
+ })
2250
+ } catch (e) { }
2251
+
2246
2252
  try {
2247
- _.forEach(currentVar.toObject(), (val, key) => {
2253
+ // Delete the variables that have been destroyed
2254
+ const unsetKeys = _.difference(_.keys(_.get(eventRuntimeData, ['variables', varType])), _.keys(currentVarObject));
2255
+
2256
+ _.forEach(unsetKeys, (unsetKey) => {
2257
+ if (varType == 'globals' && !_.includes(_.keys(getInsideVariables()), unsetKey)) {
2258
+ _.unset(eventRuntimeData, ['variables', '_globals', unsetKey])
2259
+ _.unset(eventRuntimeData, ['variables', varType, unsetKey])
2260
+ } else if (varType == '_variables') {
2261
+ _.unset(eventRuntimeData, ['variables', 'variables', unsetKey])
2262
+ } else {
2263
+ _.unset(eventRuntimeData, ['variables', varType, unsetKey])
2264
+ }
2265
+ })
2266
+
2267
+ // Set new variable values for the undestroyed ones
2268
+ _.forEach(currentVarObject, (val, key) => {
2248
2269
  let setPath = varType;
2249
2270
  if (varType === '_variables') {
2250
2271
  setPath = 'variables';
@@ -2320,9 +2341,31 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
2320
2341
  _.forEach(results, (result) => {
2321
2342
  _.forEach(['_variables', 'environment', 'globals'], (varType) => {
2322
2343
  const currentVar = _.get(result, `result.${varType}`);
2344
+ const currentVarObject = {};
2323
2345
 
2324
2346
  try {
2325
- _.forEach(currentVar.toObject(), (val, key) => {
2347
+ _.forEach(_.get(currentVar.toJSON(), 'values'), (item) => {
2348
+ currentVarObject[item?.key] = item?.value;
2349
+ })
2350
+ } catch (e) { }
2351
+
2352
+ try {
2353
+ // Delete the variables that have been destroyed
2354
+ const unsetKeys = _.difference(_.keys(_.get(eventRuntimeData, ['variables', varType])), _.keys(currentVarObject));
2355
+
2356
+ _.forEach(unsetKeys, (unsetKey) => {
2357
+ if (varType == 'globals' && !_.includes(_.keys(getInsideVariables()), unsetKey)) {
2358
+ _.unset(eventRuntimeData, ['variables', '_globals', unsetKey])
2359
+ _.unset(eventRuntimeData, ['variables', varType, unsetKey])
2360
+ } else if (varType == '_variables') {
2361
+ _.unset(eventRuntimeData, ['variables', 'variables', unsetKey])
2362
+ } else {
2363
+ _.unset(eventRuntimeData, ['variables', varType, unsetKey])
2364
+ }
2365
+ })
2366
+
2367
+ // Set new variable values for the undestroyed ones
2368
+ _.forEach(currentVarObject, (val, key) => {
2326
2369
  let setPath = varType;
2327
2370
  if (varType === '_variables') {
2328
2371
  setPath = 'variables';
@@ -2349,7 +2392,7 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
2349
2392
  _.set(eventRuntimeData, [event?.event_id, "response", "body"], tmpResponseBody)
2350
2393
  }
2351
2394
 
2352
- if (tmpResponseCode >= 0) {
2395
+ if (tmpResponseCode > 0) {
2353
2396
  _.set(eventRuntimeData, [event?.event_id, "response", "code"], tmpResponseCode)
2354
2397
  }
2355
2398
  }
@@ -2397,10 +2440,15 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
2397
2440
  return item?.passed === false
2398
2441
  })
2399
2442
 
2443
+ let httpCode = 'Ok';
2444
+
2445
+ if (!_.inRange(_.toInteger(_.get(eventRuntimeData, [event?.event_id, 'response', 'code'])), 200, 300)) {
2446
+ httpCode = _.get(eventRuntimeData, [event?.event_id, 'response', 'status']) || _.get(eventRuntimeData, [event?.event_id, 'error', 'message']);
2447
+ }
2400
2448
  _.set(eventRuntimeData, [event?.event_id, "status"], {
2401
2449
  assert: _.get(eventRuntimeData, [event?.event_id, "assertions"], []),
2402
2450
  success_assert,
2403
- http: _.get(eventRuntimeData, [event?.event_id, 'response', 'status']) || _.get(eventRuntimeData, [event?.event_id, 'error', 'message'])
2451
+ http: httpCode
2404
2452
  });
2405
2453
  }
2406
2454
 
package/index.js CHANGED
@@ -102,9 +102,33 @@ const run = async (events, option, callback) => {
102
102
  const request2HAR = (events, option) => {
103
103
  return new Promise(async (resolve, reject) => {
104
104
  const eventOptions = _.pick(option, ["scene", "lang", "project", "env", "globals", "cookies", "system_configs", "custom_functions", "collection", "database_configs", "enable_sandbox", "sleep", "name", "testing_id"]);
105
+
106
+ // 初始化变量
105
107
  const eventRuntimeData = {
106
- variables: {}
108
+ variables: {
109
+ environment: {},
110
+ variables: {},
111
+ globals: {},
112
+ _globals: {},
113
+ iterationData: {},
114
+ iterationDataArr: []
115
+ }
107
116
  };
117
+
118
+ const tempVars = { environment: _.get(option, 'env.environment', {}), globals: _.get(option, 'globals', {}) };
119
+
120
+ ['environment', 'globals'].forEach((type) => {
121
+ _.forEach(tempVars[type], (value, key) => {
122
+ if (_.isUndefined(_.get(eventRuntimeData, ['variables', type, key]))) {
123
+ _.set(eventRuntimeData, ['variables', type, key], value);
124
+
125
+ if (type === 'globals') {
126
+ _.set(eventRuntimeData, ['variables', `_${type}`, key], value);
127
+ }
128
+ }
129
+ })
130
+ });
131
+
108
132
  const eventResultList = [];
109
133
  const event = _.first(events);
110
134
 
package/libs/utils.js CHANGED
@@ -436,7 +436,7 @@ const formatAutotestReport = (startTimeAt, eventResultList) => {
436
436
  }
437
437
 
438
438
  if (_.includes(['api', 'sample', 'assert', 'assert_visual'], item?.type) && !_.isEmpty(item?.status?.assert) && _.isArray(item?.status?.assert)) {
439
- const assertFailure = _.map(item?.status?.assert, (assertItem) => {
439
+ const assertFailure = _.filter(item?.status?.assert, (assertItem) => {
440
440
  return assertItem?.passed === false
441
441
  })
442
442
 
@@ -451,6 +451,7 @@ const formatAutotestReport = (startTimeAt, eventResultList) => {
451
451
  report.avg_response_size = _.round(totalResponseSize / report.http.total, 2) || 0;
452
452
  report.total_response_time = totalResponseTime;
453
453
  report.total_response_size = totalResponseSize;
454
+
454
455
  return report;
455
456
  }
456
457
 
@@ -495,7 +496,7 @@ const jsfGenerate = (schema, mockRules = [], lang) => {
495
496
 
496
497
  let genResult = undefined;
497
498
 
498
- if (_.some(["default", "examples", "pattern", "format", "x-mock", "enum"], (value) => _.includes(_.keys(schema?.schema), value))) {
499
+ if (_.some(["default", "examples", "pattern", "format", "x-mock", "enum"], (value) => _.includes(_.keys(schema?.schema || schema), value))) {
499
500
  try {
500
501
  genResult = jsf.generate(schema);
501
502
  } catch (e) { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runner-runtime",
3
- "version": "1.0.71",
3
+ "version": "1.0.73",
4
4
  "description": "runner-runtime.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tmp/request.js CHANGED
@@ -1,7 +1,11 @@
1
1
  module.exports = {
2
2
  "option": {
3
- "scene": "http_request",
4
- "globals": {},
3
+ "scene": "auto_test",
4
+ "globals": {
5
+ "Quanju2": "test2",
6
+ "a": "quanju",
7
+ "Quanju1": "test"
8
+ },
5
9
  "project": {
6
10
  "request": {
7
11
  "header": {
@@ -68,164 +72,254 @@ module.exports = {
68
72
  "name": "默认服务",
69
73
  "sort": 1000,
70
74
  "uri": ""
75
+ },
76
+ "44a04516ec01000": {
77
+ "server_id": "44a04516ec01000",
78
+ "name": "服务2",
79
+ "sort": 2000,
80
+ "uri": "cc.apipost.cc:6002/post"
81
+ },
82
+ "44a04588b401000": {
83
+ "server_id": "44a04588b401000",
84
+ "name": "服务3",
85
+ "sort": 3000,
86
+ "uri": ""
71
87
  }
72
88
  },
73
- "environment": {}
89
+ "environment": {
90
+ "1111": "2222",
91
+ "GraphQL": "https://countries.trevorblades.com/",
92
+ "H-code": "AD",
93
+ "Houzhixing": "222",
94
+ "Yuzhixing": "111111",
95
+ "a": "环境",
96
+ "ccc": "test"
97
+ }
74
98
  },
75
99
  "cookies": {
76
100
  "switch": 1,
77
101
  "data": [
78
102
  {
79
- "key": "security_session_verify",
80
- "value": "d0f1daeaa990e130b35bbda1e947a503",
81
- "expires": "2025-05-10T19:46:19.000Z",
103
+ "project_id": "449ee12ee401000",
104
+ "cookie_id": "a07f7c57a300d",
82
105
  "path": "/",
83
- "httpOnly": true,
84
- "creation": "2025-05-07T11:46:19.440Z",
85
- "name": "security_session_verify",
86
- "cookie_id": "1ecc0422764032",
87
- "domain": "echo.apipost.cn",
88
- "project_id": "2a8c4e3bbc65001"
106
+ "key": "newCookie_1",
107
+ "value": "valuevaluevaluevaluevaluevaluevalue",
108
+ "domain": "https://httpbin.org",
109
+ "expires": "Tue, 21 Apr 2026 08:40:09 GMT",
110
+ "maxAge": ""
89
111
  },
90
112
  {
91
- "key": "security_session_verify",
92
- "value": "d0f1daeaa990e130b35bbda1e947a503",
93
- "expires": "2025-05-10T19:46:19.000Z",
113
+ "key": "liveCookie",
114
+ "value": "gin",
115
+ "maxAge": 120,
116
+ "domain": "go.apipost.cn",
94
117
  "path": "/",
118
+ "secure": true,
95
119
  "httpOnly": true,
96
- "creation": "2025-05-07T11:46:19.441Z",
97
- "name": "security_session_verify",
98
- "cookie_id": "1ecc0422764033",
99
- "domain": "echo.apipost.cn",
100
- "project_id": "2a8c4e3bbc65001"
120
+ "creation": "2025-04-24T08:34:57.284Z",
121
+ "name": "liveCookie",
122
+ "cookie_id": "a1aa4827a30dc",
123
+ "expires": "Thu, 24 Apr 2025 08:36:57 GMT",
124
+ "project_id": "449ee12ee401000"
101
125
  },
102
126
  {
103
- "key": "security_session_verify",
104
- "value": "d0f1daeaa990e130b35bbda1e947a503",
105
- "expires": "2025-05-10T19:46:19.000Z",
127
+ "key": "loseCookie",
128
+ "value": "gin",
129
+ "maxAge": 0,
130
+ "domain": "go.apipost.cn",
106
131
  "path": "/",
132
+ "secure": true,
107
133
  "httpOnly": true,
108
- "creation": "2025-05-07T11:46:19.441Z",
109
- "name": "security_session_verify",
110
- "cookie_id": "1ecc0422764034",
111
- "domain": "echo.apipost.cn",
112
- "project_id": "2a8c4e3bbc65001"
134
+ "creation": "2025-04-24T08:34:57.284Z",
135
+ "name": "loseCookie",
136
+ "cookie_id": "a1aa482ba30dd",
137
+ "expires": "Thu, 24 Apr 2025 08:34:57 GMT",
138
+ "project_id": "449ee12ee401000"
139
+ },
140
+ {
141
+ "key": "BD_NOT_HTTPS",
142
+ "value": "1",
143
+ "maxAge": 300,
144
+ "path": "/",
145
+ "creation": "2025-04-22T03:08:02.407Z",
146
+ "name": "BD_NOT_HTTPS",
147
+ "cookie_id": "b058ba17a3070",
148
+ "domain": "www.baidu.com",
149
+ "expires": "Tue, 22 Apr 2025 03:13:03 GMT",
150
+ "project_id": "449ee12ee401000"
151
+ },
152
+ {
153
+ "key": "BDSVRTM",
154
+ "value": "4",
155
+ "path": "/",
156
+ "creation": "2025-04-22T03:09:53.849Z",
157
+ "name": "BDSVRTM",
158
+ "cookie_id": "b05ddb1fa3079",
159
+ "domain": "www.baidu.com",
160
+ "project_id": "449ee12ee401000"
161
+ },
162
+ {
163
+ "key": "BD_HOME",
164
+ "value": "1",
165
+ "path": "/",
166
+ "creation": "2025-04-22T03:09:53.849Z",
167
+ "name": "BD_HOME",
168
+ "cookie_id": "b05ddb1fa307a",
169
+ "domain": "www.baidu.com",
170
+ "project_id": "449ee12ee401000"
171
+ },
172
+ {
173
+ "key": "BIDUPSID",
174
+ "value": "84078AD8954AC3C0E8CE44C8451A8CEC",
175
+ "expires": "Sun, 10 May 2093 06:22:10 GMT",
176
+ "maxAge": 2147483647,
177
+ "domain": "baidu.com",
178
+ "path": "/",
179
+ "creation": "2025-04-22T03:08:02.407Z",
180
+ "name": "BIDUPSID",
181
+ "cookie_id": "b058ba17a3071",
182
+ "project_id": "449ee12ee401000"
183
+ },
184
+ {
185
+ "key": "PSTM",
186
+ "value": "1745291282",
187
+ "expires": "Sun, 10 May 2093 06:22:10 GMT",
188
+ "maxAge": 2147483647,
189
+ "domain": "baidu.com",
190
+ "path": "/",
191
+ "creation": "2025-04-22T03:08:02.408Z",
192
+ "name": "PSTM",
193
+ "cookie_id": "b058ba17a3072",
194
+ "project_id": "449ee12ee401000"
195
+ },
196
+ {
197
+ "key": "BAIDUID",
198
+ "value": "301699BF1D4C1204DF96F5EA21DB3233:FG=1",
199
+ "expires": "Wed, 22 Apr 2026 03:09:55 GMT",
200
+ "maxAge": 31536000,
201
+ "domain": "baidu.com",
202
+ "path": "/",
203
+ "extensions": [
204
+ "version=1",
205
+ "comment=bd"
206
+ ],
207
+ "creation": "2025-04-22T03:09:53.849Z",
208
+ "name": "BAIDUID",
209
+ "cookie_id": "b058ba17a3073",
210
+ "project_id": "449ee12ee401000"
211
+ },
212
+ {
213
+ "key": "H_PS_PSSID",
214
+ "value": "60279_61027_61675_62325_62639_62833_62868_62880_62889_62905_62928_62969_62955_63019",
215
+ "expires": "2026-04-22T03:09:53.000Z",
216
+ "domain": "baidu.com",
217
+ "path": "/",
218
+ "creation": "2025-04-22T03:09:53.849Z",
219
+ "name": "H_PS_PSSID",
220
+ "cookie_id": "b05ddb1fa3078",
221
+ "project_id": "449ee12ee401000"
113
222
  }
114
223
  ]
115
224
  },
116
225
  "system_configs": {
117
226
  "send_timeout": 0,
118
- "auto_redirect": -1,
119
- "max_redirect_time": 5,
227
+ "auto_redirect": 1,
228
+ "max_redirect_time": 6,
120
229
  "auto_gen_mock_url": 1,
121
- "request_param_auto_json": -1,
230
+ "request_param_auto_json": 1,
122
231
  "proxy": {
123
232
  "type": 2,
124
233
  "envfirst": 1,
125
234
  "bypass": [],
126
235
  "protocols": [
127
- "http"
236
+ "http",
237
+ "https"
128
238
  ],
129
239
  "auth": {
130
240
  "authenticate": -1,
131
- "host": "",
241
+ "host": "114.242.33.198:80",
132
242
  "username": "",
133
243
  "password": ""
134
244
  }
135
245
  },
136
246
  "ca_cert": {
137
247
  "open": -1,
138
- "path": ""
248
+ "path": "",
249
+ "base64": ""
139
250
  },
140
- "client_cert": {}
251
+ "client_cert": {
252
+ "https://cc.apipost.cc:6003": {
253
+ "crt": {
254
+ "file_base64": "data:application/x-x509-ca-cert;base64,LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURuVENDQW9VQ0ZFcDd4Z3J2VVhteWEzTEdmcEFpenRNUkJvN3ZNQTBHQ1NxR1NJYjNEUUVCQ3dVQU1JR0sKTVFzd0NRWURWUVFHRXdKRFRqRVFNQTRHQTFVRUNBd0hRbVZwYW1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FRRUxCUUFEZ2dFQgpBRGFCdG10NHVPaVpoVlpHdmo1Tko2RUhUUFNGZGxBaVd6U2tiSWllV2RIY1NhK0J3K2xBM1kyalJsYnZNUVVaCndiL21jaFRtNjFJRmlKbnYvN1h2MGtmMkJxUzkyMURXenJHa3FWQk5zRUdIMEdhWGVHMVMwL1pkNXg1RE4zMlEKRW9IRE95K2lOeDlwRzA2cy8ybUlGY1E3eXQ0cW9acXFQZUg4U3VIamZOanlnZnZFUGxiYUJHb0Y4V1dneFluLwp3TzlFK2pYN3VvdlZDWXVrY3NyaEprZzJwK3o5MUFVU3p2NlpTbHlnK3pGM2kyM1Q0ZXA5VDhwRTV2eXE3UlFnClNPT3BQd25uN0d5UWd2UzREbU5LMHkyazc5ZUdGb3VnTWxnS3g1Um5nMUQxNEd0ZFcvMlE0WGxNa2tHZ1ZsR2IKRVRkcGlES1JKWjNTTDJPZ1RsSFpibWM9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K",
255
+ "file_name": "client (1).crt",
256
+ "file_url": ""
257
+ },
258
+ "key": {
259
+ "file_name": "client (1).key",
260
+ "file_url": "",
261
+ "file_base64": "data:application/octet-stream;base64,LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcEFJQkFBS0NBUUVBNXdvMHFWblAweWY2c2VuYlFSQ0NjY1l0RE5ESU9kenJraURQb0MxYkpjdmNTRUVqCmNCVjRaUC94dkV2V0xjSW9OTTZYa2lrVjYrdjVyeUQ2L1pYTFFJdzVJT1BBanp5VFYybWVST3oxUTE1dkpqTVcKaW5RTXFuajNUcGVwVzdaQ1ZSTkxhU0ZTMmZFUncvWHZFMW0rQWkrRDB5dmZ1RjFCeUEwREJEQmpKbW9CQkVNTQovcmUwVEMzZWFLajliYms3MXdKNGs1M3ZEYjJtaysrUFk2VjE2TW9GcUJJbHRQRzhPbStqWDZWRU5zVDVTUnBMCkpHNTAydnRqSG82RlpDV1FwZFh2UnpXcnI1RHZXZkQ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ZIUXpBRzQ1V1lxV08Kb3Vvb2hzNXZRbUFhMjRzYzBoeXhWM1QwWDJ4WVd0Qm5jOEJsY0prT0k5THFxZUhvb29FMC9mZE0vVFEwVmRtbQpGeEJrN2xmMkVpdllycjJTbDB4bk5hYkRrK1MwdG1STUNlWGh5SzZldmJIMTY1SXBpVTcwMHpzenBXcDNneEdOCnFvMVZUd2JscHhwdkpEMStjdHJLeXNFQ2dZRUFyMlo0T3Q4Y0lCVnVGS2h2cWV5Mlc1UWt6UlJIUWV1bTkwSU0KQ2t1T2tGeGlVOXgxRWRCQjFTSGtmNzFjNG96VnlQNis4VkdsTFZkTDdVSG4ySVZQQUlPTWFKc0crSGlLRXpTdApSMHN2MzNqdmVWQVh5Wi9jMG0weWwyc0MyZUwweEJxbFo2bUl4YTJSb3BuaVFWeUpKeTl1WUJOa1BsYTk0Mi8wCnRYY0lHaDhDZ1lCbHJBaVdIOGU4aEhkWjdxTjNOTk51cVkvQjdJWFNPdzFIMEVKbjd3Ui9tZElzalFRYkJGL3gKa05YNndvZDVFeHBzRkVER2lJQ0RiQm1FbW5oaU1TWFBXREhoalZKSkFSUG5sL2Fxc0tNemt0dXdic29DbGQ2OApkT1hkbHNtbGhYZVdrcGp5ZUdCREZ5Y3hPdW80M3F6VzdOOUNpQ285dXBuNGZrSEg3Si95Znc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo="
262
+ },
263
+ "password": "",
264
+ "pfx": {
265
+ "file_base64": "",
266
+ "file_name": "",
267
+ "file_url": ""
268
+ },
269
+ "HOST": "https://cc.apipost.cc:6003"
270
+ }
271
+ }
272
+ },
273
+ "custom_functions": {
274
+ "fn_test2": "return text % 2 == 0;\n//使用 return text % 2 == 0; 来判断 text 是否为偶数。如果 text 是偶数,函数返回 true;如果 text 是奇数,函数返回 false。 ",
275
+ "fn_test1": "\n// 返回函數處理後的text,text為函數的入參 \nreturn text.includes(\"To be\");",
276
+ "fn_test4": "// 创建 Date 对象\nconst date = new Date(text);\nconsole.log(text)\n// 获取各个时间组件\nconst year = date.getFullYear();\nconst month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并补零\nconst day = String(date.getDate()).padStart(2, '0');\nconst hours = String(date.getHours()).padStart(2, '0');\nconst minutes = String(date.getMinutes()).padStart(2, '0');\nconst seconds = String(date.getSeconds()).padStart(2, '0');\n\n//返回函数处理后的text,text为函数的入参\ntext = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;\n\nreturn text;"
141
277
  },
142
- "custom_functions": {},
143
278
  "collection": [
144
279
  {
145
- "target_id": "567",
280
+ "target_id": "a1c7d6e7a3109",
146
281
  "target_type": "api",
147
- "parent_id": "f4e31",
148
- "name": "下单接口",
282
+ "parent_id": "0",
283
+ "name": "get接口",
149
284
  "request": {
150
285
  "auth": {
151
286
  "type": "inherit"
152
287
  },
153
288
  "body": {
154
289
  "mode": "json",
155
- "parameter": [
156
- {
157
- "param_id": "2a8c4e42506500e",
158
- "description": "",
159
- "field_type": "string",
160
- "is_checked": 1,
161
- "key": "",
162
- "not_null": 1,
163
- "value": "",
164
- "content_type": "",
165
- "file_name": "",
166
- "file_base64": "",
167
- "schema": {
168
- "type": "string"
169
- }
170
- }
171
- ],
290
+ "parameter": [],
172
291
  "raw": "",
173
292
  "raw_parameter": [],
174
293
  "raw_schema": {
175
294
  "type": "object"
176
295
  },
177
- "binary": {}
296
+ "binary": null
178
297
  },
179
- "pre_tasks": [
180
- {
181
- "type": "customScript",
182
- "enabled": 1,
183
- "data": "apt.setRequestBody({\"key\": \"value\"}); // 将请求的body完全替换为新的内容\n\napt.environment.set(\"new_var\", \"value\");\napt.environment.clear();\n",
184
- "name": "自定义脚本",
185
- "id": "1fd601f376400e"
186
- }
187
- ],
298
+ "pre_tasks": [],
188
299
  "post_tasks": [
189
300
  {
190
301
  "type": "customScript",
191
302
  "enabled": 1,
192
- "data": "// pm.response.setBody({\"id\":1});\n// 模板字符串 \nvar template = `<table> \n <thead> \n <tr> \n <th>ID</th> \n </tr> \n </thead> \n <tbody> \n {{#each response}} \n <tr> \n <td>{{id}}</td> \n </tr> \n {{/each}} \n </tbody> \n</table>`;\nvar responseData = pm.response.json()[\"data\"][\"list\"]; \npm.visualizer.set(template, { response: responseData });\npm.response.setBody({\"id\":1});\n",
303
+ "data": "console.log(\"123\")",
193
304
  "name": "自定义脚本",
194
- "id": "1fd60b01f6400f"
305
+ "id": "a1d382efa3150"
195
306
  }
196
307
  ],
197
308
  "header": {
198
- "parameter": [
199
- {
200
- "param_id": "2a8c4e425065010",
201
- "description": "",
202
- "field_type": "string",
203
- "is_checked": 1,
204
- "key": "",
205
- "not_null": 1,
206
- "value": "",
207
- "schema": {
208
- "type": "string"
209
- }
210
- }
211
- ]
309
+ "parameter": []
212
310
  },
213
311
  "query": {
214
312
  "query_add_equal": 1,
215
313
  "parameter": [
216
314
  {
217
- "param_id": "1fd7e2ad39b02f",
218
- "description": "这是文章ID",
315
+ "param_id": "b01413279b02d",
316
+ "description": "",
219
317
  "field_type": "string",
220
318
  "is_checked": 1,
221
- "key": "id",
319
+ "key": "2",
222
320
  "not_null": 1,
223
- "value": "",
321
+ "value": "{{name}}",
224
322
  "schema": {
225
- "enum": [
226
- "aaa",
227
- "bbb"
228
- ],
229
323
  "type": "string"
230
324
  }
231
325
  }
@@ -239,58 +333,115 @@ module.exports = {
239
333
  "parameter": []
240
334
  }
241
335
  },
242
- "parents": [
243
- {
244
- "target_id": "f4e31",
245
- "target_type": "folder",
246
- "server_id": "1"
247
- }
248
- ],
249
- "server_id": "1",
250
- "method": "POST",
336
+ "parents": [],
337
+ "method": "GET",
251
338
  "protocol": "http/1.1",
252
- "url": "https://echo.apipost.cn/array.php?id=",
339
+ "url": "go.apipost.cn?2={{name}}",
253
340
  "pre_url": ""
341
+ }
342
+ ],
343
+ "database_configs": {},
344
+ "name": "未命名测试用例",
345
+ "ignore_error": -1,
346
+ "enable_sandbox": -1,
347
+ "iterationCount": 1,
348
+ "sleep": 0,
349
+ "testing_id": "de1d0c97a3006",
350
+ "iterates_data_id": "de1d6b93a3008",
351
+ "iterationData": [
352
+ {
353
+ "url": "q"
254
354
  },
255
355
  {
256
- "target_id": "f4e31",
257
- "target_type": "folder",
258
- "parent_id": "0",
259
- "name": "备用目录-1",
260
- "request": {
261
- "auth": {
262
- "type": "inherit"
263
- },
264
- "pre_tasks": [],
265
- "post_tasks": [],
266
- "body": {
267
- "parameter": []
268
- },
269
- "header": {
270
- "parameter": []
271
- },
272
- "query": {
273
- "parameter": []
274
- },
275
- "cookie": {
276
- "parameter": []
277
- }
278
- },
279
- "parents": [],
280
- "server_id": "1",
281
- "pre_url": ""
356
+ "url": "w"
357
+ },
358
+ {
359
+ "url": "e"
360
+ },
361
+ {
362
+ "url": "ut"
363
+ },
364
+ {
365
+ "url": "g"
366
+ },
367
+ {
368
+ "url": "h"
369
+ },
370
+ {
371
+ "url": "k"
282
372
  }
283
- ],
284
- "database_configs": {}
373
+ ]
285
374
  },
286
375
  "test_events": [
287
376
  {
288
377
  "type": "api",
378
+ "auto_sync": false,
379
+ "test_id": "de1d0c97a3006",
380
+ "event_id": "de1f430fa3023",
381
+ "enabled": 1,
289
382
  "data": {
290
- "target_id": "567",
291
- "project_id": "2a8c4e3bbc65001",
292
- "parent_id": "f4e31",
293
- "target_type": "api"
383
+ "target_id": "a1c7d6e7a3109",
384
+ "project_id": "449ee12ee401000",
385
+ "parent_id": "0",
386
+ "target_type": "api",
387
+ "apiData": {
388
+ "name": "get接口",
389
+ "method": "GET",
390
+ "protocol": "http/1.1",
391
+ "url": "go.apipost.cn?2={{url}}",
392
+ "request": {
393
+ "auth": {
394
+ "type": "inherit"
395
+ },
396
+ "body": {
397
+ "mode": "json",
398
+ "parameter": [],
399
+ "raw": "",
400
+ "raw_parameter": [],
401
+ "raw_schema": {
402
+ "type": "object"
403
+ },
404
+ "binary": null
405
+ },
406
+ "pre_tasks": [],
407
+ "post_tasks": [
408
+ {
409
+ "type": "customScript",
410
+ "enabled": 1,
411
+ "data": "console.log(\"123\")",
412
+ "name": "自定义脚本",
413
+ "id": "a1d382efa3150"
414
+ }
415
+ ],
416
+ "header": {
417
+ "parameter": []
418
+ },
419
+ "query": {
420
+ "query_add_equal": 1,
421
+ "parameter": [
422
+ {
423
+ "param_id": "b01413279b02d",
424
+ "description": "",
425
+ "field_type": "string",
426
+ "is_checked": 1,
427
+ "key": "2",
428
+ "not_null": 1,
429
+ "value": "{{url}}",
430
+ "schema": {
431
+ "type": "string"
432
+ }
433
+ }
434
+ ]
435
+ },
436
+ "cookie": {
437
+ "cookie_encode": 1,
438
+ "parameter": []
439
+ },
440
+ "restful": {
441
+ "parameter": []
442
+ }
443
+ }
444
+ }
294
445
  }
295
446
  }
296
447
  ]
package/test.js DELETED
@@ -1,124 +0,0 @@
1
- const _ = require('lodash');
2
- const { run, request2HAR } = require('./index');
3
-
4
- // 以下为调用示例
5
- const callback = (res) => {
6
- console.warn("callback", JSON.stringify(res, null, 2))
7
- }
8
-
9
-
10
- /// pip start
11
- (function () {
12
- const net = require('net');
13
- const fs = require('fs');
14
- const path = require('path');
15
- const mainProcessSocketPath = path.join(__dirname, 'my_socket.sock');
16
- const { DatabaseQuery } = require('database-query');
17
- _.set(process, 'env.main_process_socket_path', mainProcessSocketPath);
18
-
19
- // 如果套接字文件已存在,删除它
20
- if (fs.existsSync(mainProcessSocketPath)) {
21
- fs.unlinkSync(mainProcessSocketPath);
22
- }
23
-
24
- const server = net.createServer((socket) => {
25
- socket.on('data', async (stream) => {
26
- const { action, data } = JSON.parse(String(Buffer.from(stream)));
27
- try {
28
- switch (action) {
29
- case 'queryDatabase':
30
- const { dbconfig, query } = data;
31
- const result = await DatabaseQuery(dbconfig, query);
32
- socket.write(JSON.stringify(result));
33
- break;
34
- case 'execute':
35
- const { execSync } = require('child_process');
36
- const { file, args, option } = data;
37
- const ext = file.split('.').pop().toLowerCase();
38
- let command;
39
- try {
40
- switch (ext) {
41
- case 'jar':
42
- const jarPath = path.resolve(__dirname, `jar-main-1.0-SNAPSHOT.jar`);
43
- const { className, method } = option || {};
44
- if (_.isObject(option)) {
45
- if (_.isString(className) && _.isString(method)) {
46
- let para = new Buffer(JSON.stringify({ methodName: method, args: args })).toString("base64");
47
- command = `java -jar ${jarPath} ${file} ${className} '${para}'`;
48
- }
49
- } else {
50
- command = `java -jar ${file} ${_.join(_.map(args, JSON.stringify), " ")}`;
51
- }
52
-
53
- break;
54
- case 'php':
55
- command = `php -f ${file} ${args.join(' ')}`;
56
- break;
57
- case 'js':
58
- command = `node ${file} ${args.join(' ')}`;
59
- break;
60
- case 'py':
61
- command = `python ${file} ${args.join(' ')}`;
62
- break;
63
- case 'py3':
64
- command = `python3 ${file} ${args.join(' ')}`;
65
- break;
66
- case 'bsh':
67
- command = `bsh ${file} ${args.join(' ')}`;
68
- break;
69
- case 'go':
70
- command = `go run ${file} ${args.join(' ')}`;
71
- break;
72
- case 'sh':
73
- command = `sh ${file} ${args.join(' ')}`;
74
- break;
75
- case 'rb':
76
- case 'ruby':
77
- command = `ruby ${file} ${args.join(' ')}`;
78
- break;
79
- case 'lua':
80
- command = `lua ${file} ${args.join(' ')}`;
81
- break;
82
- case 'rs':
83
- command = `rustc ${file} && ./${file.replace(/\.rs$/, '')} ${args.join(' ')}`;
84
- break;
85
- case 'bat':
86
- command = `${file} ${args.join(' ')}`;
87
- break;
88
- case 'ps1':
89
- command = `powershell -File ${file} ${args.join(' ')}`;
90
- break;
91
- default:
92
- throw new Error(`Unsupported file suffixes <${ext}>`);
93
- }
94
-
95
- const isWindows = process.platform === 'win32';
96
- const options = _.assign(isWindows ? { encoding: 'cp936' } : { encoding: 'utf8' }, option);
97
- const output = execSync(command, options);
98
- socket.write(JSON.stringify({
99
- err: 'success',
100
- result: String(output)
101
- }));
102
- } catch (e) {
103
- socket.write(JSON.stringify({
104
- err: 'error',
105
- result: String(e)
106
- }));
107
- }
108
- break;
109
- }
110
-
111
- } catch (e) {
112
- socket.write(JSON.stringify(e));
113
- }
114
-
115
- });
116
- });
117
-
118
- server.listen(mainProcessSocketPath, () => {
119
- // console.log(`服务器已启动,监听路径 ${mainProcessSocketPath}`);
120
- });
121
- })();
122
- //pip end
123
- const { option, test_events } = require('./tmp/request'); // tmp todo...
124
- run(test_events, option, callback);