@testomatio/reporter 2.3.7-beta.4-stack-artifacts → 2.3.7-beta.6-stack-artifacts

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/lib/bin/cli.js CHANGED
File without changes
File without changes
File without changes
File without changes
package/lib/client.js CHANGED
@@ -51,7 +51,9 @@ const node_url_1 = require("node:url");
51
51
  const uploader_js_1 = require("./uploader.js");
52
52
  const utils_js_1 = require("./utils/utils.js");
53
53
  const filesize_1 = require("filesize");
54
+ const util_1 = require("util");
54
55
  const debug = (0, debug_1.default)('@testomatio/reporter:client');
56
+ const stripColors = util_1.stripVTControlCharacters || ((str) => str?.replace(/\x1b\[[0-9;]*m/g, '') || '');
55
57
  // removed __dirname usage, because:
56
58
  // 1. replaced with ESM syntax (import.meta.url), but it throws an error on tsc compilation;
57
59
  // 2. got error "__dirname already defined" in compiles js code (cjs dir)
@@ -171,34 +173,9 @@ class Client {
171
173
  * @type {TestData}
172
174
  */
173
175
  const { rid, error = null, steps: originalSteps, title, suite_title, } = testData;
174
- let steps = originalSteps;
176
+ const steps = originalSteps;
175
177
  const uploadedFiles = [];
176
178
  const stackArtifactsEnabled = (0, utils_js_1.transformEnvVarToBoolean)(process.env.TESTOMATIO_STACK_ARTIFACTS);
177
- let formattedSteps;
178
- if (stackArtifactsEnabled) {
179
- const timestamp = +new Date;
180
- formattedSteps = Array.isArray(steps) ? steps.map(step => (0, utils_js_1.formatStep)(step)).flat().join('\n') : '';
181
- if (error?.stack?.length > 5000) {
182
- uploadedFiles.push(this.uploader.uploadFileAsBuffer(Buffer.from(error.stack, 'utf8'), [this.runId, rid, `stack_${timestamp}.log`]));
183
- }
184
- if (formattedSteps?.length > 10000) {
185
- uploadedFiles.push(this.uploader.uploadFileAsBuffer(Buffer.from(JSON.stringify(steps, null, 2), 'utf8'), [this.runId, rid, `steps_${timestamp}.json`]));
186
- }
187
- }
188
- if (!this.pipes || !this.pipes.length)
189
- this.pipes = await (0, index_js_1.pipesFactory)(this.paramsForPipesFactory || {}, this.pipeStore);
190
- if (!this.pipes?.filter(p => p.isEnabled).length) {
191
- if (uploadedFiles.length > 0) {
192
- await Promise.all(uploadedFiles);
193
- }
194
- return [];
195
- }
196
- if (isTestShouldBeExculedFromReport(testData))
197
- return [];
198
- if (status === constants_js_1.STATUS.SKIPPED && process.env.TESTOMATIO_EXCLUDE_SKIPPED) {
199
- debug('Skipping test from report', testData?.title);
200
- return [];
201
- }
202
179
  const { time = 0, example = null, files = [], filesBuffers = [], code = null, file, suite_id, test_id, timestamp, links, manuallyAttachedArtifacts, overwrite, tags, } = testData;
203
180
  let { message = '', meta = {} } = testData;
204
181
  meta = Object.entries(meta)
@@ -214,20 +191,25 @@ class Client {
214
191
  errorFormatted += this.formatError(error) || '';
215
192
  message = error?.message;
216
193
  }
194
+ let fullLogs = this.formatLogs({ error: errorFormatted, steps, logs: testData.logs });
217
195
  if (stackArtifactsEnabled) {
218
- if (error?.stack?.length > 5000)
219
- errorFormatted = `[Large stack saved as artifact]`;
220
- if (formattedSteps?.length > 10000)
221
- steps = null;
196
+ const timestamp = +new Date;
197
+ uploadedFiles.push(this.uploader.uploadFileAsBuffer(Buffer.from(stripColors(fullLogs), 'utf8'), [this.runId, rid, `logs_${timestamp}.log`]));
198
+ fullLogs = null;
222
199
  }
223
- else {
224
- formattedSteps = Array.isArray(steps) ? steps.map(step => (0, utils_js_1.formatStep)(step)).flat().join('\n') : '';
200
+ if (!this.pipes || !this.pipes.length)
201
+ this.pipes = await (0, index_js_1.pipesFactory)(this.paramsForPipesFactory || {}, this.pipeStore);
202
+ if (!this.pipes?.filter(p => p.isEnabled).length) {
203
+ if (uploadedFiles.length > 0) {
204
+ await Promise.all(uploadedFiles);
205
+ }
206
+ return [];
225
207
  }
226
- let fullLogs = this.formatLogs({ error: errorFormatted, steps, logs: testData.logs });
227
- if (stackArtifactsEnabled && fullLogs.length > 5000) {
228
- const timestamp = +new Date;
229
- uploadedFiles.push(this.uploader.uploadFileAsBuffer(Buffer.from(fullLogs, 'utf8'), [this.runId, rid, `logs_${timestamp}.log`]));
230
- fullLogs = fullLogs.slice(0, 5000) + '\n\n[Full logs saved as artifact]';
208
+ if (isTestShouldBeExculedFromReport(testData))
209
+ return [];
210
+ if (status === constants_js_1.STATUS.SKIPPED && process.env.TESTOMATIO_EXCLUDE_SKIPPED) {
211
+ debug('Skipping test from report', testData?.title);
212
+ return [];
231
213
  }
232
214
  if (manuallyAttachedArtifacts?.length)
233
215
  files.push(...manuallyAttachedArtifacts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "2.3.7-beta.4-stack-artifacts",
3
+ "version": "2.3.7-beta.6-stack-artifacts",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "engines": {
6
6
  "node": ">=18"
package/src/client.js CHANGED
@@ -19,9 +19,12 @@ import {
19
19
  transformEnvVarToBoolean
20
20
  } from './utils/utils.js';
21
21
  import { filesize as prettyBytes } from 'filesize';
22
+ import { stripVTControlCharacters } from 'util';
22
23
 
23
24
  const debug = createDebugMessages('@testomatio/reporter:client');
24
25
 
26
+ const stripColors = stripVTControlCharacters || ((str) => str?.replace(/\x1b\[[0-9;]*m/g, '') || '');
27
+
25
28
  // removed __dirname usage, because:
26
29
  // 1. replaced with ESM syntax (import.meta.url), but it throws an error on tsc compilation;
27
30
  // 2. got error "__dirname already defined" in compiles js code (cjs dir)
@@ -167,50 +170,12 @@ class Client {
167
170
  title,
168
171
  suite_title,
169
172
  } = testData;
170
- let steps = originalSteps;
173
+ const steps = originalSteps;
171
174
 
172
175
  const uploadedFiles = [];
173
176
  const stackArtifactsEnabled = transformEnvVarToBoolean(process.env.TESTOMATIO_STACK_ARTIFACTS);
174
177
 
175
- let formattedSteps;
176
- if (stackArtifactsEnabled) {
177
- const timestamp = +new Date;
178
- formattedSteps = Array.isArray(steps) ? steps.map(step => formatStep(step)).flat().join('\n') : '';
179
-
180
- if (error?.stack?.length > 5000) {
181
- uploadedFiles.push(
182
- this.uploader.uploadFileAsBuffer(
183
- Buffer.from(error.stack, 'utf8'),
184
- [this.runId, rid, `stack_${timestamp}.log`]
185
- )
186
- );
187
- }
188
- if (formattedSteps?.length > 10000) {
189
- uploadedFiles.push(
190
- this.uploader.uploadFileAsBuffer(
191
- Buffer.from(JSON.stringify(steps, null, 2), 'utf8'),
192
- [this.runId, rid, `steps_${timestamp}.json`]
193
- )
194
- );
195
- }
196
- }
197
- if (!this.pipes || !this.pipes.length)
198
- this.pipes = await pipesFactory(this.paramsForPipesFactory || {}, this.pipeStore);
199
-
200
- if (!this.pipes?.filter(p => p.isEnabled).length) {
201
- if (uploadedFiles.length > 0) {
202
- await Promise.all(uploadedFiles);
203
- }
204
- return [];
205
- }
206
-
207
- if (isTestShouldBeExculedFromReport(testData)) return [];
208
-
209
- if (status === STATUS.SKIPPED && process.env.TESTOMATIO_EXCLUDE_SKIPPED) {
210
- debug('Skipping test from report', testData?.title);
211
- return [];
212
- }
213
-
178
+
214
179
  const {
215
180
  time = 0,
216
181
  example = null,
@@ -243,24 +208,35 @@ class Client {
243
208
  message = error?.message;
244
209
  }
245
210
 
246
- if (stackArtifactsEnabled) {
247
- if (error?.stack?.length > 5000) errorFormatted = `[Large stack saved as artifact]`;
248
- if (formattedSteps?.length > 10000) steps = null;
249
- } else {
250
- formattedSteps = Array.isArray(steps) ? steps.map(step => formatStep(step)).flat().join('\n') : '';
251
- }
252
-
253
211
  let fullLogs = this.formatLogs({ error: errorFormatted, steps, logs: testData.logs });
254
212
 
255
- if (stackArtifactsEnabled && fullLogs.length > 5000) {
213
+ if (stackArtifactsEnabled) {
256
214
  const timestamp = +new Date;
257
215
  uploadedFiles.push(
258
216
  this.uploader.uploadFileAsBuffer(
259
- Buffer.from(fullLogs, 'utf8'),
217
+ Buffer.from(stripColors(fullLogs), 'utf8'),
260
218
  [this.runId, rid, `logs_${timestamp}.log`]
261
219
  )
262
220
  );
263
- fullLogs = fullLogs.slice(0, 5000) + '\n\n[Full logs saved as artifact]';
221
+ fullLogs = null;
222
+ }
223
+
224
+
225
+ if (!this.pipes || !this.pipes.length)
226
+ this.pipes = await pipesFactory(this.paramsForPipesFactory || {}, this.pipeStore);
227
+
228
+ if (!this.pipes?.filter(p => p.isEnabled).length) {
229
+ if (uploadedFiles.length > 0) {
230
+ await Promise.all(uploadedFiles);
231
+ }
232
+ return [];
233
+ }
234
+
235
+ if (isTestShouldBeExculedFromReport(testData)) return [];
236
+
237
+ if (status === STATUS.SKIPPED && process.env.TESTOMATIO_EXCLUDE_SKIPPED) {
238
+ debug('Skipping test from report', testData?.title);
239
+ return [];
264
240
  }
265
241
 
266
242
  if (manuallyAttachedArtifacts?.length) files.push(...manuallyAttachedArtifacts);