runner-runtime 1.0.16 → 1.0.18

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
@@ -2264,18 +2264,26 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
2264
2264
  }
2265
2265
 
2266
2266
  // 写入到自动化测试结果
2267
- if (scene === 'auto_test' && _.includes(['assert', 'assert_visual', 'api', 'sample'], event?.type)) {
2268
- eventResultList.push(_.assign(camelCaseToSnakeCase(_.get(eventRuntimeData, event?.event_id)), _.pick(event, ['type', 'event_id', 'test_id', 'iteration_id'])))
2269
- }
2270
-
2271
- resolve(_.assign({
2272
- action: 'request',
2267
+ const finalRequestResult = _.assign({
2268
+ action: 'httpRequestCompleted',
2273
2269
  data: camelCaseToSnakeCase(_.get(eventRuntimeData, event?.event_id)),
2274
2270
  error: _.get(eventRuntimeData, [event?.event_id, 'error', 'message']) || null,
2275
2271
  event_id: event?.event_id,
2276
- iteration_id: _.get(eventRuntimeData, [event?.event_id, 'iteration_id']),
2277
- type: 'request'
2278
- }, _.pick(requestJson, ['parent_id', 'project_id', 'test_id', 'target_id'])))
2272
+ iteration_id: _.get(eventRuntimeData, [event?.event_id, 'iteration_id'])
2273
+ }, _.pick(requestJson, ['parent_id', 'project_id', 'test_id', 'target_id']));
2274
+
2275
+ if (scene === 'auto_test' && _.includes(['assert', 'assert_visual', 'api', 'sample'], event?.type)) {
2276
+ eventResultList.push(_.assign(camelCaseToSnakeCase(_.get(eventRuntimeData, event?.event_id)), _.pick(event, ['type', 'event_id', 'test_id', 'iteration_id'])));
2277
+
2278
+ resolve({
2279
+ action: 'request',
2280
+ data: _.assign(finalRequestResult, {
2281
+ type: 'request'
2282
+ })
2283
+ })
2284
+ } else {
2285
+ resolve(finalRequestResult)
2286
+ }
2279
2287
  }
2280
2288
  }
2281
2289
  })
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
- const { repeatArrayToLength, formatAutotestReport } = require('./libs/utils');
1
+ const { repeatArrayToLength, formatAutotestReport,formatAutotestReportList } = require('./libs/utils');
2
2
  const _ = require('lodash');
3
+ const moment = require('moment');
4
+ const aTools = require("apipost-tools");
3
5
  const { executeEvent, iterationEvent } = require('./events');
4
6
  const ABORT_RECURSION_ERROR = ['stystemError']; //需要跳出递归的错误
5
7
 
@@ -52,13 +54,19 @@ const run = async (events, option, callback) => {
52
54
  callback({
53
55
  action: 'complete',
54
56
  data: _.assign(formatAutotestReport(startTimeAt, eventResultList), {
55
- list: eventResultList
56
- })
57
+ list: formatAutotestReportList(eventResultList),
58
+ variables: _.get(eventRuntimeData, 'variables')
59
+ },
60
+ _.pick(_.get(option, 'env', {}), ['env_id', 'env_name']),
61
+ { testing_id: _.get(_.first(eventResultList), 'test_id') },
62
+ { report_name: `${moment().format('YYYY-MM-DD HH:mm:ss')}` },
63
+ { report_id: aTools.snowflakeId() }
64
+ )
57
65
  })
58
66
  }
59
67
  }
60
68
 
61
- const getHar = async (events, option) => {
69
+ const request2HAR = async (events, option) => {
62
70
  const eventOptions = _.pick(option, ["scene", "lang", "project", "env", "globals", "cookies", "system_configs", "custom_functions", "collection", "database_configs", "enable_sandbox", "sleep", "name", "testing_id"]);
63
71
  const eventRuntimeData = {
64
72
  variables: {}
@@ -76,4 +84,4 @@ const getHar = async (events, option) => {
76
84
  }
77
85
  }
78
86
  }
79
- module.exports = { run, getHar }
87
+ module.exports = { run, request2HAR }
package/libs/2har.js CHANGED
@@ -18,6 +18,7 @@
18
18
  * @returns {Object} HAR format JSON object.
19
19
  */
20
20
  function generateHarFromRequest(options) {
21
+ console.log(options)
21
22
  const {
22
23
  url,
23
24
  method = 'GET',
@@ -37,13 +38,34 @@ function generateHarFromRequest(options) {
37
38
  {
38
39
  request: {
39
40
  method: method.toUpperCase(),
40
- url: appendQueryParams(url, queryParams),
41
+ httpVersion: "HTTP/1.1",
42
+ url: String(options?.url || ''),
41
43
  headers: processHeaders(headers),
42
44
  queryString: processQueryString(queryParams),
43
45
  postData: processBody(body),
44
46
  headersSize: -1, // Optional, usually auto-calculated
45
47
  bodySize: -1, // Optional, usually auto-calculated
46
48
  },
49
+ response: {
50
+ status: 200,
51
+ statusText: "OK",
52
+ httpVersion: "HTTP/1.1",
53
+ cookies: [],
54
+ headers: [],
55
+ content: {
56
+ size: 0,
57
+ mimeType: "application/json", // Assume JSON, update as necessary
58
+ },
59
+ redirectURL: "",
60
+ headersSize: -1,
61
+ bodySize: -1,
62
+ },
63
+ cache: {},
64
+ timings: {
65
+ send: 0,
66
+ wait: 0,
67
+ receive: 0,
68
+ },
47
69
  startedDateTime: new Date().toISOString(),
48
70
  time: 0, // Mock timing data (replace with actual timing if needed)
49
71
  },
@@ -54,23 +76,6 @@ function generateHarFromRequest(options) {
54
76
  return har;
55
77
  }
56
78
 
57
- /**
58
- * Appends query parameters to a URL.
59
- * @param {string} url - The base URL.
60
- * @param {Array} queryParams - Array of { key: string, value: string }.
61
- * @returns {string} URL with query parameters appended.
62
- */
63
- function appendQueryParams(url, queryParams) {
64
- if (!queryParams || queryParams.length === 0) return url;
65
-
66
- const searchParams = new URLSearchParams();
67
- queryParams.forEach(({ key, value }) => {
68
- searchParams.append(key, value);
69
- });
70
-
71
- return `${url}?${searchParams.toString()}`;
72
- }
73
-
74
79
  /**
75
80
  * Converts Postman-style headers into HAR format.
76
81
  * @param {Array} headers - Array of { key: string, value: string }.
@@ -101,6 +106,7 @@ function processQueryString(queryParams) {
101
106
  * @returns {Object|undefined} HAR postData object.
102
107
  */
103
108
  function processBody(body) {
109
+ // console.log(body)
104
110
  const { mode } = body;
105
111
 
106
112
  if (mode === 'none') {
package/libs/utils.js CHANGED
@@ -436,14 +436,34 @@ const variableReplace = (str, variables, option) => {
436
436
  // });
437
437
  // }
438
438
 
439
+ const formatAutotestReportList = (eventResultList) => {
440
+ const list = []
441
+ _.forEach(eventResultList, (item) => {
442
+ list.push(_.assign({
443
+ 'status': {
444
+ "assert": _.isEmpty(item?.status?.success_assert) ? "OK" : item?.status?.success_assert,
445
+ "http": item?.status?.http || "OK"
446
+ }
447
+ },
448
+ _.pick(item?.request, ['timings', 'response_time', 'response_at', 'proxy', 'status', 'code', 'response_size']),
449
+ _.pick(item?.response, ['url', 'method', 'name', 'target_id', 'project_id']),
450
+ _.pick(item, ['type', 'event_id', 'test_id', 'iteration_id']),
451
+ ))
452
+ })
453
+
454
+ return list;
455
+ }
456
+
439
457
  const formatAutotestReport = (startTimeAt, eventResultList) => {
440
458
  const report = {
441
459
  "assert": {
442
460
  "total": 0,
461
+ "success": 0,
443
462
  "error": 0
444
463
  },
445
464
  "http": {
446
465
  "total": 0,
466
+ "success": 0,
447
467
  "error": 0
448
468
  },
449
469
  "start_at": startTimeAt,
@@ -479,6 +499,8 @@ const formatAutotestReport = (startTimeAt, eventResultList) => {
479
499
  }
480
500
  })
481
501
 
502
+ report.http.success.total = report.http.total - report.http.error;
503
+ report.assert.success.total = report.assert.total - report.assert.error;
482
504
  report.avg_response_time = _.round(totalResponseTime / report.http.total, 2);
483
505
  report.avg_response_size = _.round(totalResponseSize / report.http.total, 2);
484
506
  report.total_response_time = totalResponseTime;
@@ -510,6 +532,7 @@ module.exports = {
510
532
  returnBoolean,
511
533
  getCaseInsensitive,
512
534
  camelCaseToSnakeCase,
535
+ formatAutotestReportList,
513
536
  variableReplace,
514
537
  // createPipeServer,
515
538
  formatAutotestReport,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "runner-runtime",
3
- "version": "1.0.16",
4
- "description": "Processing data returned by AI.",
3
+ "version": "1.0.18",
4
+ "description": "runner-runtime.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -11,7 +11,7 @@
11
11
  "url": "git+https://github.com/Apipost-Team/runner-runtime.git"
12
12
  },
13
13
  "keywords": [
14
- "auto-json-faker"
14
+ "runner-runtime"
15
15
  ],
16
16
  "author": "Daniel Anderson <support@echoapi.com> (https://github.com/Apipost-Team)",
17
17
  "license": "MIT",
@@ -36,6 +36,7 @@
36
36
  "mime": "^3.0.0",
37
37
  "minimatch": "^9.0.4",
38
38
  "mockjs5-pro": "^1.0.3",
39
+ "moment": "^2.30.1",
39
40
  "msgpack5": "^6.0.2",
40
41
  "net": "^1.0.2",
41
42
  "postman-collection": "^5.0.2",
package/test.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const _ =require('lodash');
2
- const { getHar } = require('./index');
2
+ const { run } = require('./index');
3
3
 
4
4
  // 以下为调用示例
5
5
  const callback = (res) => {
@@ -121,4 +121,4 @@ const callback = (res) => {
121
121
  })();
122
122
  //pip end
123
123
  const { option, test_events } = require('./tmp/request'); // tmp todo...
124
- getHar(test_events, option, callback);
124
+ run(test_events, option, callback);
package/tmp/request.js CHANGED
@@ -127,7 +127,7 @@ module.exports = {
127
127
  "type": "inherit"
128
128
  },
129
129
  "body": {
130
- "mode": "form-data",
130
+ "mode": "none",
131
131
  "parameter": [
132
132
  {
133
133
  "param_id": "17e6c2b93e4002",