runner-runtime 1.0.17 → 1.0.19

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/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,8 +54,14 @@ 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
  }
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,35 @@ 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
+ {
444
+ 'status': {
445
+ "assert": _.isEmpty(item?.status?.success_assert) ? "OK" : item?.status?.success_assert,
446
+ "http": item?.status?.http || "OK"
447
+ }
448
+ },
449
+ _.pick(item?.response, ['timings', 'response_time', 'response_at', 'proxy', 'status', 'code', 'response_size']),
450
+ _.pick(item?.request, ['url', 'method', 'name', 'target_id', 'project_id']),
451
+ _.pick(item, ['type', 'event_id', 'test_id', 'iteration_id']),
452
+ ))
453
+ })
454
+
455
+ return list;
456
+ }
457
+
439
458
  const formatAutotestReport = (startTimeAt, eventResultList) => {
440
459
  const report = {
441
460
  "assert": {
442
461
  "total": 0,
462
+ "success": 0,
443
463
  "error": 0
444
464
  },
445
465
  "http": {
446
466
  "total": 0,
467
+ "success": 0,
447
468
  "error": 0
448
469
  },
449
470
  "start_at": startTimeAt,
@@ -479,6 +500,8 @@ const formatAutotestReport = (startTimeAt, eventResultList) => {
479
500
  }
480
501
  })
481
502
 
503
+ report.http.success.total = report.http.total - report.http.error;
504
+ report.assert.success.total = report.assert.total - report.assert.error;
482
505
  report.avg_response_time = _.round(totalResponseTime / report.http.total, 2);
483
506
  report.avg_response_size = _.round(totalResponseSize / report.http.total, 2);
484
507
  report.total_response_time = totalResponseTime;
@@ -510,6 +533,7 @@ module.exports = {
510
533
  returnBoolean,
511
534
  getCaseInsensitive,
512
535
  camelCaseToSnakeCase,
536
+ formatAutotestReportList,
513
537
  variableReplace,
514
538
  // createPipeServer,
515
539
  formatAutotestReport,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runner-runtime",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "runner-runtime.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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 { request2HAR } = 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
- request2HAR(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",