@zohodesk/testinglibrary 0.0.52-n20-experimental → 0.0.53-n20-experimental
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.
|
@@ -8,6 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
10
10
|
var _logger = require("../../utils/logger");
|
|
11
|
+
var _timeFormat = require("../../utils/timeFormat");
|
|
11
12
|
var _DataGeneratorHelper = require("./DataGeneratorHelper");
|
|
12
13
|
var _DataGeneratorError = require("./DataGeneratorError");
|
|
13
14
|
var _readConfigFile = require("../playwright/readConfigFile");
|
|
@@ -27,6 +28,9 @@ class DataGenerator {
|
|
|
27
28
|
_classPrivateFieldInitSpec(this, _generatorIndex, null);
|
|
28
29
|
}
|
|
29
30
|
async generate(testInfo, actorInfo, generatorType, generatorName, scenarioName, dataTable) {
|
|
31
|
+
const startMs = Date.now();
|
|
32
|
+
const startLabel = (0, _timeFormat.formatTimestamp)(startMs);
|
|
33
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Data generation started | generator="${generatorName}" | scenario="${scenarioName}" | startTime=${startLabel}`);
|
|
30
34
|
try {
|
|
31
35
|
let generators;
|
|
32
36
|
if (generatorType === 'API') {
|
|
@@ -37,12 +41,20 @@ class DataGenerator {
|
|
|
37
41
|
const processedGenerators = await (0, _DataGeneratorHelper.processGenerator)(generators, dataTable);
|
|
38
42
|
const apiPayload = await _assertClassBrand(_DataGenerator_brand, this, _constructApiPayload).call(this, scenarioName, processedGenerators, actorInfo);
|
|
39
43
|
const response = await (0, _DataGeneratorHelper.makeRequest)(process.env.DG_SERVICE_DOMAIN + process.env.DG_SERVICE_API_PATH, apiPayload);
|
|
44
|
+
const endMs = Date.now();
|
|
45
|
+
const endLabel = (0, _timeFormat.formatTimestamp)(endMs);
|
|
46
|
+
const totalLabel = (0, _timeFormat.formatDuration)(endMs - startMs);
|
|
40
47
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Generated response for the generator: ${generatorName} for scenario: ${scenarioName}, Response: ${JSON.stringify(response)}`);
|
|
48
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Data generation completed | generator="${generatorName}" | scenario="${scenarioName}" | startTime=${startLabel} | endTime=${endLabel} | totalTime=${totalLabel}`);
|
|
41
49
|
return {
|
|
42
50
|
response,
|
|
43
51
|
generators
|
|
44
52
|
};
|
|
45
53
|
} catch (error) {
|
|
54
|
+
const endMs = Date.now();
|
|
55
|
+
const endLabel = (0, _timeFormat.formatTimestamp)(endMs);
|
|
56
|
+
const totalLabel = (0, _timeFormat.formatDuration)(endMs - startMs);
|
|
57
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Data generation failed | generator="${generatorName}" | scenario="${scenarioName}" | startTime=${startLabel} | endTime=${endLabel} | totalTime=${totalLabel}`);
|
|
46
58
|
if (error instanceof _DataGeneratorError.DataGeneratorError) {
|
|
47
59
|
console.error(error.getMessage());
|
|
48
60
|
console.error("Stack trace:", error.stack);
|
|
@@ -8,6 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
10
10
|
var _logger = require("../../../utils/logger");
|
|
11
|
+
var _timeFormat = require("../../../utils/timeFormat");
|
|
11
12
|
var _DataGeneratorHelper = require("../../dataGenerator/DataGeneratorHelper");
|
|
12
13
|
var _readConfigFile = require("../readConfigFile");
|
|
13
14
|
var _jsonpath = _interopRequireDefault(require("jsonpath"));
|
|
@@ -80,7 +81,7 @@ async function cleanupViaOAS(config, entityId, actorInfo) {
|
|
|
80
81
|
dataPath: '$.response.body:$',
|
|
81
82
|
name: config.operationId,
|
|
82
83
|
params: {
|
|
83
|
-
id: String(entityId)
|
|
84
|
+
[config.paramName || 'id']: String(entityId)
|
|
84
85
|
}
|
|
85
86
|
}],
|
|
86
87
|
...dataGeneratorObj
|
|
@@ -93,7 +94,8 @@ async function cleanupViaOAS(config, entityId, actorInfo) {
|
|
|
93
94
|
environmentDetails.iam_url = process.env.DG_IAM_DOMAIN;
|
|
94
95
|
environmentDetails.host = new URL(process.env.domain).origin;
|
|
95
96
|
payload.environmentDetails = environmentDetails;
|
|
96
|
-
await (0, _DataGeneratorHelper.makeRequest)(process.env.DG_SERVICE_DOMAIN + process.env.DG_SERVICE_API_PATH, payload);
|
|
97
|
+
const response = await (0, _DataGeneratorHelper.makeRequest)(process.env.DG_SERVICE_DOMAIN + process.env.DG_SERVICE_API_PATH, payload);
|
|
98
|
+
return response;
|
|
97
99
|
}
|
|
98
100
|
async function cleanupViaAPI(config, entityId) {
|
|
99
101
|
const url = `${new URL(process.env.domain).origin}${config.apiPath.replace('{id}', entityId)}`;
|
|
@@ -107,10 +109,14 @@ async function cleanupViaAPI(config, entityId) {
|
|
|
107
109
|
options.body = JSON.stringify(config.body);
|
|
108
110
|
}
|
|
109
111
|
const response = await fetch(url, options);
|
|
112
|
+
const responseBody = await response.text();
|
|
110
113
|
if (!response.ok) {
|
|
111
|
-
|
|
112
|
-
throw new Error(`${config.method} ${config.apiPath} - status: ${response.status}, body: ${errorBody}`);
|
|
114
|
+
throw new Error(`${config.method} ${config.apiPath} - status: ${response.status}, body: ${responseBody}`);
|
|
113
115
|
}
|
|
116
|
+
return {
|
|
117
|
+
status: response.status,
|
|
118
|
+
body: responseBody
|
|
119
|
+
};
|
|
114
120
|
}
|
|
115
121
|
var _default = exports.default = {
|
|
116
122
|
// eslint-disable-next-line no-empty-pattern
|
|
@@ -141,7 +147,9 @@ var _default = exports.default = {
|
|
|
141
147
|
if (!cleanupRegistry) {
|
|
142
148
|
cleanupRegistry = buildCleanupRegistry();
|
|
143
149
|
}
|
|
144
|
-
|
|
150
|
+
const cleanupStartMs = Date.now();
|
|
151
|
+
const cleanupStartLabel = (0, _timeFormat.formatTimestamp)(cleanupStartMs);
|
|
152
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Cleanup started | entities=${cleanupEntries.length} | startTime=${cleanupStartLabel}`);
|
|
145
153
|
let cleaned = 0;
|
|
146
154
|
let skipped = 0;
|
|
147
155
|
let failed = 0;
|
|
@@ -152,30 +160,47 @@ var _default = exports.default = {
|
|
|
152
160
|
skipped++;
|
|
153
161
|
continue;
|
|
154
162
|
}
|
|
155
|
-
|
|
163
|
+
const entityStartMs = Date.now();
|
|
164
|
+
const entityStartLabel = (0, _timeFormat.formatTimestamp)(entityStartMs);
|
|
165
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Cleanup entity started | entity="${entry.entityName}" | generator="${entry.generatorName}" | steps=${cleanupChain.length} | startTime=${entityStartLabel}`);
|
|
156
166
|
for (const cleanupStep of cleanupChain) {
|
|
167
|
+
const stepStartMs = Date.now();
|
|
168
|
+
const stepStartLabel = (0, _timeFormat.formatTimestamp)(stepStartMs);
|
|
169
|
+
const actionDesc = cleanupStep.operationId || `${cleanupStep.method} ${cleanupStep.apiPath}`;
|
|
157
170
|
try {
|
|
158
171
|
// Find the step's response from logs by matching operationId
|
|
159
172
|
const stepLog = entry.logs.find(log => log.generationOperationId === cleanupStep.operationId || log.name === cleanupStep.operationId);
|
|
160
173
|
const stepData = parseLogBody(stepLog) || entry.data;
|
|
161
174
|
const entityId = extractId(stepData, cleanupStep.idPath);
|
|
162
|
-
|
|
163
|
-
|
|
175
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Cleanup step started | [${cleanupStep.type}] ${actionDesc} (id: ${entityId}) | startTime=${stepStartLabel}`);
|
|
176
|
+
let cleanupResponse;
|
|
164
177
|
if (cleanupStep.type === 'oas') {
|
|
165
|
-
await cleanupViaOAS(cleanupStep, entityId, entry.actorInfo);
|
|
178
|
+
cleanupResponse = await cleanupViaOAS(cleanupStep, entityId, entry.actorInfo);
|
|
166
179
|
} else if (cleanupStep.type === 'api') {
|
|
167
|
-
await cleanupViaAPI(cleanupStep, entityId);
|
|
180
|
+
cleanupResponse = await cleanupViaAPI(cleanupStep, entityId);
|
|
168
181
|
}
|
|
169
182
|
cleaned++;
|
|
170
|
-
|
|
183
|
+
const stepEndMs = Date.now();
|
|
184
|
+
const stepEndLabel = (0, _timeFormat.formatTimestamp)(stepEndMs);
|
|
185
|
+
const stepTotalLabel = (0, _timeFormat.formatDuration)(stepEndMs - stepStartMs);
|
|
186
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `Cleanup step success | ${actionDesc} (id: ${entityId}) | response=${JSON.stringify(cleanupResponse)} | startTime=${stepStartLabel} | endTime=${stepEndLabel} | totalTime=${stepTotalLabel}`);
|
|
171
187
|
} catch (err) {
|
|
172
188
|
failed++;
|
|
173
|
-
const
|
|
174
|
-
|
|
189
|
+
const stepEndMs = Date.now();
|
|
190
|
+
const stepEndLabel = (0, _timeFormat.formatTimestamp)(stepEndMs);
|
|
191
|
+
const stepTotalLabel = (0, _timeFormat.formatDuration)(stepEndMs - stepStartMs);
|
|
192
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Cleanup step failed | ${actionDesc} — ${err.message} | startTime=${stepStartLabel} | endTime=${stepEndLabel} | totalTime=${stepTotalLabel}`);
|
|
175
193
|
}
|
|
176
194
|
}
|
|
195
|
+
const entityEndMs = Date.now();
|
|
196
|
+
const entityEndLabel = (0, _timeFormat.formatTimestamp)(entityEndMs);
|
|
197
|
+
const entityTotalLabel = (0, _timeFormat.formatDuration)(entityEndMs - entityStartMs);
|
|
198
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Cleanup entity completed | entity="${entry.entityName}" | generator="${entry.generatorName}" | startTime=${entityStartLabel} | endTime=${entityEndLabel} | totalTime=${entityTotalLabel}`);
|
|
177
199
|
}
|
|
178
|
-
|
|
200
|
+
const cleanupEndMs = Date.now();
|
|
201
|
+
const cleanupEndLabel = (0, _timeFormat.formatTimestamp)(cleanupEndMs);
|
|
202
|
+
const cleanupTotalLabel = (0, _timeFormat.formatDuration)(cleanupEndMs - cleanupStartMs);
|
|
203
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Cleanup completed | cleaned=${cleaned} | skipped=${skipped} (no chain) | failed=${failed} | startTime=${cleanupStartLabel} | endTime=${cleanupEndLabel} | totalTime=${cleanupTotalLabel}`);
|
|
179
204
|
cleanupEntries.length = 0;
|
|
180
205
|
cache.clear();
|
|
181
206
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatDuration = formatDuration;
|
|
7
|
+
exports.formatTimestamp = formatTimestamp;
|
|
8
|
+
/**
|
|
9
|
+
* Format a Date (or epoch ms) as a human-readable local timestamp in 12-hour format.
|
|
10
|
+
* Example: "2026-04-10 11:35:23.123 AM"
|
|
11
|
+
*/
|
|
12
|
+
function formatTimestamp(input) {
|
|
13
|
+
const d = input instanceof Date ? input : new Date(input);
|
|
14
|
+
const pad = (n, w = 2) => String(n).padStart(w, '0');
|
|
15
|
+
const hours24 = d.getHours();
|
|
16
|
+
const period = hours24 >= 12 ? 'PM' : 'AM';
|
|
17
|
+
const hours12 = hours24 % 12 || 12;
|
|
18
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ` + `${pad(hours12)}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad(d.getMilliseconds(), 3)} ${period}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Format a duration in milliseconds as a human-readable string.
|
|
23
|
+
* Examples: "850ms", "4.32s", "1m 23.45s", "1h 02m 03.45s"
|
|
24
|
+
*/
|
|
25
|
+
function formatDuration(ms) {
|
|
26
|
+
if (ms < 1000) {
|
|
27
|
+
return `${ms}ms`;
|
|
28
|
+
}
|
|
29
|
+
const totalSeconds = ms / 1000;
|
|
30
|
+
if (totalSeconds < 60) {
|
|
31
|
+
return `${totalSeconds.toFixed(2)}s`;
|
|
32
|
+
}
|
|
33
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
34
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
35
|
+
const seconds = totalSeconds % 60;
|
|
36
|
+
const pad = n => String(n).padStart(2, '0');
|
|
37
|
+
if (hours > 0) {
|
|
38
|
+
return `${hours}h ${pad(minutes)}m ${seconds.toFixed(2)}s`;
|
|
39
|
+
}
|
|
40
|
+
return `${minutes}m ${seconds.toFixed(2)}s`;
|
|
41
|
+
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/testinglibrary",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53-n20-experimental",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@zohodesk/testinglibrary",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.53-n20-experimental",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|