@testomatio/reporter 2.3.7-beta.5-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "2.3.7-beta.5-stack-artifacts",
3
+ "version": "2.3.7-beta.6-stack-artifacts",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -18,7 +18,7 @@ const newArgs = ['run'];
18
18
  let i = 0;
19
19
  while (i < args.length) {
20
20
  const arg = args[i];
21
-
21
+
22
22
  if (arg === '-c' || arg === '--command') {
23
23
  // Map -c/--command to positional argument for run command
24
24
  i++;
@@ -33,7 +33,7 @@ while (i < args.length) {
33
33
  // Map --launch to start command
34
34
  newArgs[0] = 'start';
35
35
  } else if (arg === '--finish') {
36
- // Map --finish to finish command
36
+ // Map --finish to finish command
37
37
  newArgs[0] = 'finish';
38
38
  } else {
39
39
  // Pass through other arguments
@@ -45,9 +45,9 @@ while (i < args.length) {
45
45
  // Execute the main CLI with mapped arguments
46
46
 
47
47
  const child = spawn(process.execPath, [cliPath, ...newArgs], {
48
- stdio: 'inherit',
48
+ stdio: 'inherit'
49
49
  });
50
50
 
51
- child.on('exit', code => {
51
+ child.on('exit', (code) => {
52
52
  process.exit(code);
53
- });
53
+ });
package/src/client.js CHANGED
@@ -10,11 +10,21 @@ import { glob } from 'glob';
10
10
  import path, { sep } from 'path';
11
11
  import { fileURLToPath } from 'node:url';
12
12
  import { S3Uploader } from './uploader.js';
13
- import { formatStep, truncate, readLatestRunId, storeRunId, validateSuiteId } from './utils/utils.js';
13
+ import {
14
+ formatStep,
15
+ truncate,
16
+ readLatestRunId,
17
+ storeRunId,
18
+ validateSuiteId,
19
+ transformEnvVarToBoolean
20
+ } from './utils/utils.js';
14
21
  import { filesize as prettyBytes } from 'filesize';
22
+ import { stripVTControlCharacters } from 'util';
15
23
 
16
24
  const debug = createDebugMessages('@testomatio/reporter:client');
17
25
 
26
+ const stripColors = stripVTControlCharacters || ((str) => str?.replace(/\x1b\[[0-9;]*m/g, '') || '');
27
+
18
28
  // removed __dirname usage, because:
19
29
  // 1. replaced with ESM syntax (import.meta.url), but it throws an error on tsc compilation;
20
30
  // 2. got error "__dirname already defined" in compiles js code (cjs dir)
@@ -139,19 +149,6 @@ class Client {
139
149
  * @returns {Promise<PipeResult[]>}
140
150
  */
141
151
  async addTestRun(status, testData) {
142
- if (!this.pipes || !this.pipes.length)
143
- this.pipes = await pipesFactory(this.paramsForPipesFactory || {}, this.pipeStore);
144
-
145
- // all pipes disabled, skipping
146
- if (!this.pipes?.filter(p => p.isEnabled).length) return [];
147
-
148
- if (isTestShouldBeExculedFromReport(testData)) return [];
149
-
150
- if (status === STATUS.SKIPPED && process.env.TESTOMATIO_EXCLUDE_SKIPPED) {
151
- debug('Skipping test from report', testData?.title);
152
- return []; // do not log skipped tests
153
- }
154
-
155
152
  if (!testData)
156
153
  testData = {
157
154
  title: 'Unknown test',
@@ -169,15 +166,23 @@ class Client {
169
166
  const {
170
167
  rid,
171
168
  error = null,
169
+ steps: originalSteps,
170
+ title,
171
+ suite_title,
172
+ } = testData;
173
+ const steps = originalSteps;
174
+
175
+ const uploadedFiles = [];
176
+ const stackArtifactsEnabled = transformEnvVarToBoolean(process.env.TESTOMATIO_STACK_ARTIFACTS);
177
+
178
+
179
+ const {
172
180
  time = 0,
173
181
  example = null,
174
182
  files = [],
175
183
  filesBuffers = [],
176
- steps,
177
184
  code = null,
178
- title,
179
185
  file,
180
- suite_title,
181
186
  suite_id,
182
187
  test_id,
183
188
  timestamp,
@@ -188,7 +193,6 @@ class Client {
188
193
  } = testData;
189
194
  let { message = '', meta = {} } = testData;
190
195
 
191
- // stringify meta values and limit keys and values length to 255
192
196
  meta = Object.entries(meta)
193
197
  .filter(([, value]) => value !== null && value !== undefined)
194
198
  .reduce((acc, [key, value]) => {
@@ -196,7 +200,6 @@ class Client {
196
200
  return acc;
197
201
  }, {});
198
202
 
199
- // Get links from storage using the test context
200
203
  const testContext = suite_title ? `${suite_title} ${title}` : title;
201
204
 
202
205
  let errorFormatted = '';
@@ -205,13 +208,38 @@ class Client {
205
208
  message = error?.message;
206
209
  }
207
210
 
208
- // Attach logs
209
- const fullLogs = this.formatLogs({ error: errorFormatted, steps, logs: testData.logs });
211
+ let fullLogs = this.formatLogs({ error: errorFormatted, steps, logs: testData.logs });
210
212
 
211
- // add artifacts
212
- if (manuallyAttachedArtifacts?.length) files.push(...manuallyAttachedArtifacts);
213
+ if (stackArtifactsEnabled) {
214
+ const timestamp = +new Date;
215
+ uploadedFiles.push(
216
+ this.uploader.uploadFileAsBuffer(
217
+ Buffer.from(stripColors(fullLogs), 'utf8'),
218
+ [this.runId, rid, `logs_${timestamp}.log`]
219
+ )
220
+ );
221
+ fullLogs = null;
222
+ }
213
223
 
214
- const uploadedFiles = [];
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 [];
240
+ }
241
+
242
+ if (manuallyAttachedArtifacts?.length) files.push(...manuallyAttachedArtifacts);
215
243
 
216
244
  for (let f of files) {
217
245
  if (!f) continue; // f === null
@@ -472,7 +472,7 @@ class TestomatioPipe {
472
472
  if (this.runUrl && this.proceed) {
473
473
  const notFinishedMessage = pc.yellow(pc.bold('Run was not finished because of $TESTOMATIO_PROCEED'));
474
474
  console.log(APP_PREFIX, `📊 ${notFinishedMessage}. Report URL: ${pc.magenta(this.runUrl)}`);
475
- console.log(APP_PREFIX, `🛬 Run to finish it: TESTOMATIO_RUN=${this.runId} npx @testomatio/reporter finish`);
475
+ console.log(APP_PREFIX, `🛬 Run to finish it: TESTOMATIO_RUN=${this.runId} npx start-test-run --finish`);
476
476
  }
477
477
 
478
478
  if (this.hasUnmatchedTests) {
package/src/reporter.js CHANGED
@@ -1,8 +1,10 @@
1
- // import TestomatClient from './client.js';
2
- // import * as TRConstants from './constants.js';
1
+ import Client from './client.js';
2
+ import * as TestomatioConstants from './constants.js';
3
3
  import { services } from './services/index.js';
4
4
  import reporterFunctions from './reporter-functions.js';
5
5
 
6
+ export { Client };
7
+ export const STATUS = TestomatioConstants.STATUS;
6
8
  export const artifact = reporterFunctions.artifact;
7
9
  export const log = reporterFunctions.log;
8
10
  export const logger = services.logger;
@@ -35,6 +37,7 @@ export default {
35
37
  linkTest: reporterFunctions.linkTest,
36
38
  linkJira: reporterFunctions.linkJira,
37
39
 
38
- // TestomatClient,
39
- // TRConstants,
40
+ TestomatioClient: Client,
41
+ STATUS,
42
+
40
43
  };