@testomatio/reporter 2.3.9 → 2.5.0

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/src/bin/cli.js CHANGED
@@ -7,7 +7,7 @@ import createDebugMessages from 'debug';
7
7
  import TestomatClient from '../client.js';
8
8
  import XmlReader from '../xmlReader.js';
9
9
  import { APP_PREFIX, STATUS } from '../constants.js';
10
- import { cleanLatestRunId, getPackageVersion } from '../utils/utils.js';
10
+ import { cleanLatestRunId, getPackageVersion, applyFilter } from '../utils/utils.js';
11
11
  import { config } from '../config.js';
12
12
  import { readLatestRunId } from '../utils/utils.js';
13
13
  import pc from 'picocolors';
@@ -81,6 +81,7 @@ program
81
81
  .description('Run tests with the specified command')
82
82
  .argument('<command>', 'Test runner command')
83
83
  .option('--filter <filter>', 'Additional execution filter')
84
+ .option('--filter-list <filter>', 'Get a list of all tests by filter before running')
84
85
  .option('--kind <type>', 'Specify run type: automated, manual, or mixed')
85
86
  .action(async (command, opts) => {
86
87
  const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config.TESTOMATIO;
@@ -93,17 +94,39 @@ program
93
94
 
94
95
  const client = new TestomatClient({ apiKey, title });
95
96
 
96
- if (opts.filter) {
97
- const [pipe, ...optsArray] = opts.filter.split(':');
97
+ if (opts.filter || opts.filterList) {
98
+ // Example of use: npx @testomatio/reporter run "npx jest" --filter "testomatio:tag-name=frontend"
99
+ // Example of use: npx @testomatio/reporter run "npx jest" --filter "coverage:file=coverage.yml"
100
+ // Example of use: npx @testomatio/reporter run "npx jest" --filter-list "coverage:file=coverage.yml"
101
+ const [pipe, ...optsArray] = opts?.filter ? opts?.filter.split(':') : opts?.filterList.split(':');
98
102
  const pipeOptions = optsArray.join(':');
99
103
 
104
+ const prepareRunParams = { pipe, pipeOptions };
105
+
100
106
  try {
101
- const tests = await client.prepareRun({ pipe, pipeOptions });
102
- if (tests && tests.length > 0) {
103
- command += ` --grep (${tests.join('|')})`;
107
+ const tests = await client.prepareRun(prepareRunParams);
108
+
109
+ if (!tests || tests.length === 0) {
110
+ console.log(APP_PREFIX, pc.yellow('No tests found.'));
111
+ return;
104
112
  }
105
- } catch (err) {
106
- console.log(APP_PREFIX, err);
113
+
114
+ const pattern = `(${tests.join('|')})`;
115
+ const filteredCommand = applyFilter(command, tests);
116
+
117
+ debug(`Execution pattern: "${pattern}"`);
118
+
119
+ if(opts.filterList) {
120
+ console.log(APP_PREFIX, pc.blue(`Matched test/suite IDs: ${tests.join(', ')}`));
121
+ console.log(APP_PREFIX, pc.green(`Full Running Command: ${filteredCommand}`));
122
+ return;
123
+ }
124
+
125
+ command = filteredCommand;
126
+ }
127
+ catch (err) {
128
+ console.log(APP_PREFIX, err.message || err);
129
+ return;
107
130
  }
108
131
  }
109
132
 
@@ -113,7 +136,7 @@ program
113
136
  const testCmds = command.split(' ');
114
137
  const cmd = spawn(testCmds[0], testCmds.slice(1), {
115
138
  stdio: 'inherit',
116
- env: { ...process.env, TESTOMATIO_PROCEED: 'true', runId: client.runId },
139
+ env: { ...process.env, TESTOMATIO_PROCEED: 'true', runId: client.runId, TESTOMATIO_RUN: client.runId },
117
140
  });
118
141
 
119
142
  cmd.on('close', async code => {
@@ -128,6 +151,9 @@ program
128
151
  };
129
152
 
130
153
  const createRunParams = {};
154
+ if (title) {
155
+ createRunParams.title = title;
156
+ }
131
157
  if (opts.kind) {
132
158
  createRunParams.kind = opts.kind;
133
159
  }
package/src/client.js CHANGED
@@ -65,35 +65,43 @@ class Client {
65
65
  * array containing the prepared execution list,
66
66
  * or resolves to undefined if no valid results are found or if all pipes are disabled.
67
67
  */
68
+
68
69
  async prepareRun(params) {
69
- this.pipes = await pipesFactory(params || this.paramsForPipesFactory || {}, this.pipeStore);
70
70
  const { pipe, pipeOptions } = params;
71
+
72
+ // ❗ Validation: pipe is required
73
+ if (!pipe || !pipeOptions) {
74
+ console.warn(`❗ No valid pipe found in filter cmd. Expected format: <pipe>:<options>
75
+ Examples:
76
+ --filter "testomatio:tag-name=frontend"
77
+ --filter "coverage:file=coverage.yml"
78
+ --filter-list "coverage:file=coverage.yml"
79
+ Received: "${params}"`);
80
+ return;
81
+ }
82
+
83
+ this.pipes = await pipesFactory(params || this.paramsForPipesFactory || {}, this.pipeStore);
84
+
71
85
  // all pipes disabled, skipping
72
86
  if (!this.pipes.some(p => p.isEnabled)) {
73
87
  return Promise.resolve();
74
88
  }
75
89
 
76
90
  try {
77
- const filterPipe = this.pipes.find(p => p.constructor.name.toLowerCase() === `${pipe.toLowerCase()}pipe`);
91
+ const p = this.pipes.find(p => p.constructor.name.toLowerCase() === `${pipe.toLowerCase()}pipe`);
92
+ // const p = this.pipes.find(p => p.id === `${pipe.toLowerCase()}`); TODO: as future updates
78
93
 
79
- if (!filterPipe?.isEnabled) {
80
- // TODO:for the future for the another pipes
94
+ if (!p?.isEnabled) {
81
95
  console.warn(
82
96
  APP_PREFIX,
83
- `At the moment processing is available only for the "testomatio" key. Example: "testomatio:tag-name=xxx"`,
97
+ "🚫 No active pipes were found in the system. Execution aborted!"
84
98
  );
85
99
  return;
86
100
  }
87
101
 
88
- const results = await Promise.all(
89
- this.pipes.map(async p => ({ pipe: p.toString(), result: await p.prepareRun(pipeOptions) })),
90
- );
91
-
92
- const result = results.filter(p => p.pipe.includes('Testomatio'))[0]?.result;
93
-
94
- if (!result || result.length === 0) {
95
- return;
96
- }
102
+ // Run only the selected pipe
103
+ const rawResult = await p.prepareRun(pipeOptions);
104
+ const result = Array.isArray(rawResult) ? rawResult : [];
97
105
 
98
106
  debug('Execution tests list', result);
99
107
 
package/src/helpers.js ADDED
@@ -0,0 +1 @@
1
+ export const isPlaywright = Boolean(process.env.PLAYWRIGHT_TEST || process.env.PLAYWRIGHT);
@@ -0,0 +1,440 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import yaml from 'js-yaml';
4
+ import { execSync } from 'child_process';
5
+ import { Gaxios } from 'gaxios';
6
+ import { minimatch } from 'minimatch';
7
+ import { APP_PREFIX, AXIOS_TIMEOUT, REPORTER_REQUEST_RETRIES } from '../constants.js';
8
+ import { generateFilterRequestParams } from '../utils/pipe_utils.js';
9
+ import { parsePipeOptions } from '../utils/pipe_utils.js';
10
+ import { config } from '../config.js';
11
+ import createDebugMessages from 'debug';
12
+
13
+ const debug = createDebugMessages('@testomatio/reporter:pipe:csv');
14
+
15
+ // Example of use 'coverage:file=coverage/coverage.yml,diff=master' cmd:
16
+ // | Option | Git command | Notes |
17
+ // | --- | --- | --- |
18
+ // | --filter "coverage:file=coverage/coverage.yml,diff=new-branch" | ✅ git diff new-branch --name-only | - |
19
+ // | --filter "coverage:diff=master,file=coverage.yml" | ✅ git diff master --name-only | - |
20
+ // | --filter "coverage:file=coverage/coverage.yml" | ✅ git diff master --name-only | default branch = "master" |
21
+ // | --filter "coverage:file=coverage.yml,dif=noexist-branch" | ❌ Git command failed ...| - |
22
+ // | --filter "coverage:file=coverage.yml,diff=noexist-branch" | ❌ Git command failed ...| because no branch found |
23
+ // | --filter "coverage:file=no-exist-coverage.yml" | ❌ Coverage file not found: <>filename>.yml | - |
24
+ // | --filter "coverage:filepath=coverage.yml" | 🚫 Missing required parameter: "file"... | - |
25
+ // | --filter "coverage:diff=my-branch" | 🚫 Missing required parameter: "file"...| - |
26
+
27
+ //maybe GitChanges or GitCoverage
28
+ class CoveragePipe { // or Changes for the future???
29
+ #GIT = {
30
+ default_branch: 'master',
31
+ diff_command: 'git diff',
32
+ only_file_opt: '--name-only',
33
+ uncommitted_marker: 'uncommitted',
34
+ // test_defaultGitChangedFile - uses only for unit tests in "coverage_pipe_test.js" file
35
+ test_defaultGitChangedFile: ['todomvc-tests/edit-todos_test.js'],
36
+ };
37
+
38
+ constructor(params, store) {
39
+ this.id = 'coverage'; // as future updates -> find by id in client.js
40
+ this.store = store || {};
41
+ this.branch = undefined;
42
+ this.isDefaultGitChanges = false; // COVERAGE_BY_DEFAULT_GIT_FILE env uses only for unit tests
43
+ this.isEnabled = false;
44
+
45
+ const { pipeOptions } = params;
46
+ const options = parsePipeOptions(pipeOptions || "");
47
+ debug("Pipe options", options);
48
+
49
+ // this.isDefaultGitChanges - COVERAGE_BY_DEFAULT_GIT_FILE env uses only for unit tests
50
+ this.isDefaultGitChanges = process.env.COVERAGE_BY_DEFAULT_GIT_FILE === '1'? true : false;
51
+ this.coverageFilePath = options?.file || process.env.COVERAGE_FILEPATH || undefined ;
52
+
53
+ if (!this.coverageFilePath) return;
54
+
55
+ this.branch = options?.diff || process.env.COVERAGE_BRANCH || this.#GIT.default_branch;
56
+ this.isBranchDefault = !options.diff && !process.env.COVERAGE_BRANCH;
57
+
58
+ if (this.isBranchDefault) {
59
+ console.log(
60
+ APP_PREFIX,
61
+ `🟡 No "diff" branch provided. That's why we use default one = "${this.branch}".\n` +
62
+ '👉 You can set it via --filter "coverage:file=coverage.yml,diff=your-branch"'
63
+ );
64
+ }
65
+
66
+ // Client config section
67
+ this.formattedDate = new Date().toISOString().replace(/T/, '-').replace(/:/g, '-').split('.')[0];
68
+ this.title = process.env.TESTOMATIO_TITLE || `Testomatio Coverage Test Execution - ${this.formattedDate}`;
69
+ this.apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config.TESTOMATIO;
70
+
71
+ this.url = params.testomatioUrl || process.env.TESTOMATIO_URL || 'https://app.testomat.io';
72
+ const proxyUrl = process.env.HTTP_PROXY || process.env.HTTPS_PROXY || null;
73
+ const proxy = proxyUrl ? new URL(proxyUrl) : null;
74
+
75
+ // Create a new instance of gaxios with a custom config
76
+ this.client = new Gaxios({
77
+ baseURL: `${this.url.trim()}`,
78
+ timeout: AXIOS_TIMEOUT,
79
+ proxy: proxy ? proxy.toString() : undefined,
80
+ retry: true,
81
+ retryConfig: {
82
+ retry: REPORTER_REQUEST_RETRIES.retriesPerRequest,
83
+ retryDelay: REPORTER_REQUEST_RETRIES.retryTimeout,
84
+ httpMethodsToRetry: ['GET','PUT','HEAD','OPTIONS','DELETE','POST'],
85
+ shouldRetry: (error) => {
86
+ if (!error.response) return false;
87
+ switch (error.response?.status) {
88
+ case 400: // Bad request (probably wrong API key)
89
+ case 404: // Test not matched
90
+ case 429: // Rate limit exceeded
91
+ case 500: // Internal server error
92
+ return false;
93
+ default:
94
+ break;
95
+ }
96
+ return error.response?.status >= 401; // Retry on 401+ and 5xx
97
+ }
98
+ }
99
+ });
100
+
101
+ // In case if we have all needed data
102
+ this.isEnabled = true;
103
+
104
+ debug('Coverage Pipe initialized', {
105
+ branch: this.branch,
106
+ coverageFilePath: this.coverageFilePath,
107
+ });
108
+
109
+ this.parsedCoverage = {};
110
+ this.changedFiles = [];
111
+ this.matchedLines = new Set();
112
+ this.tests = new Set();
113
+ this.suiteIds = new Set();
114
+ this.tagLabels = new Set();
115
+
116
+ this.results = [];
117
+
118
+ debug(`Coverage Pipe: is Enabled = ${this.isEnabled}`);
119
+ }
120
+
121
+ async prepareRun(opts) {
122
+ // Reset internal mutable state for isolation
123
+ this.tests.clear();
124
+ this.suiteIds.clear();
125
+ this.tagLabels.clear();
126
+ this.results = [];
127
+
128
+ if (!this.isEnabled) return [];
129
+
130
+ // Step 1: Validate coverage file path & Git changes & Coverage parsing
131
+ if (!this.getGitChangedFiles()?.validateCoverageFile()?.parseCoverageFile()) return [];
132
+
133
+ // Step 2: Extract all available tests and compare with coverage file
134
+ const lines = await this.extractRelevantTestsFromChanges();
135
+
136
+ if (lines.size === 0) {
137
+ console.log(APP_PREFIX, 'ℹ️ No matching entries in coverage file for provided Git changes.');
138
+ return [];
139
+ }
140
+
141
+ // Step 3: Handle tag labels tests from the server
142
+ // if (this.tagLabels && this.tagLabels.size > 0) { //TODO: in case if we add labels in future!!!
143
+ if (this.tagLabels.size > 0) {
144
+ for (const tag of this.tagLabels) {
145
+ const tagType = 'tag';
146
+ const tests = await this.#getTestomatioTestsByParam(tagType, tag);
147
+
148
+ if (!tests) return [];
149
+
150
+ console.log(
151
+ APP_PREFIX,
152
+ `✅ We found ${tests.length === 1 ? 'one entry' : `${tests.length} (test/suite) entries`}` +
153
+ ' in Testomat.io service side.'
154
+ );
155
+
156
+ tests.forEach(testId => this.tests.add(testId));
157
+ }
158
+ }
159
+
160
+ if (this.tests.size === 0) {
161
+ console.log(APP_PREFIX, 'ℹ️ No tests found for execution based on Git changes.');
162
+ return [];
163
+ }
164
+
165
+ this.results = [...this.tests];
166
+
167
+ return this.results;
168
+ }
169
+
170
+ addTest(data) {}
171
+
172
+ async createRun() {}
173
+
174
+ updateRun() {}
175
+
176
+ async finishRun(runParams) {}
177
+
178
+ toString() {
179
+ return 'Coverage Reporter';
180
+ }
181
+
182
+ /**
183
+ * Fetches a list of tests from the Testomat.io server based on a given filter parameter.
184
+ *
185
+ * The method parses the provided filter (`type=id`), builds the appropriate request parameters,
186
+ * sends a GET request to the Testomat.io `/api/test_grep` endpoint, and returns the matching tests.
187
+ *
188
+ * If the filter is invalid, no query is generated, or the server responds with no matching tests,
189
+ * it logs relevant information and returns `undefined`.
190
+ *
191
+ * @async function
192
+ * @param {string} type - The filter string in the format like `tag-name` for tag by.
193
+ * @param {string} id - The filter string in the format like `smoke`.
194
+ * @returns {Promise<Array<Object>|undefined>} Resolves to an array of test objects if found, otherwise `undefined`.
195
+ */
196
+ async #getTestomatioTestsByParam(type, id) {
197
+ // Get tests from the server
198
+ try {
199
+ const q = generateFilterRequestParams({
200
+ type,
201
+ id,
202
+ apiKey: this?.apiKey?.trim(),
203
+ });
204
+
205
+ if (!q) {
206
+ return;
207
+ }
208
+
209
+ const resp = await this.client.request({
210
+ method: 'GET',
211
+ url: '/api/test_grep',
212
+ ...q,
213
+ });
214
+
215
+ if (!Array.isArray(resp.data?.tests) && resp.data?.tests?.length === 0) {
216
+ console.log(APP_PREFIX, `🔍 No test by ${type}=${id} were found on the Testomat.io server side!`);
217
+
218
+ return undefined;
219
+ }
220
+
221
+ return resp.data.tests;
222
+ }
223
+ catch (err) {
224
+ console.error(
225
+ APP_PREFIX,
226
+ `🚩 Error getting available tests from the Testomat.io by "test_grep" option: ${err}`
227
+ );
228
+
229
+ return undefined;
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Executes a Git command to retrieve a list of changed files.
235
+ *
236
+ * @param {string} cmd - The Git command to execute.
237
+ * @returns {string[]} An array of changed file paths. Returns an empty array if an error occurs
238
+ * (e.g., not a Git repository or command failure).
239
+ */
240
+ #getChangedFilesFromGit(cmd) {
241
+ try {
242
+ const result = execSync(cmd, {
243
+ encoding: 'utf-8',
244
+ stdio: ['pipe', 'pipe', 'ignore']
245
+ });
246
+
247
+ return result
248
+ .split('\n')
249
+ .map(f => f.trim())
250
+ .filter(Boolean);
251
+ }
252
+ catch (err) {
253
+ const errorMessage = err.message || '';
254
+ // Git edge: Not a git repository or other error
255
+ if (errorMessage.includes('Not a git repository')) {
256
+ console.error(APP_PREFIX, '❌ Error: This folder is not a Git repository.');
257
+ }
258
+ else {
259
+ throw new Error(`❌ Git command failed ("${cmd}"):\n`, errorMessage);
260
+ }
261
+
262
+ return [];
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Builds a Git command string to list file changes between the current state
268
+ * and a specified Git branch using `git diff --name-only`.
269
+ *
270
+ * Private pipe function
271
+ * @throws {Error} Throws an error if `this.branch` is not defined.
272
+ * @returns {string} A Git command string, e.g., 'git diff <branch> --name-only'.
273
+ */
274
+ #buildGitCommand() {
275
+ if (!this.branch) throw new Error(`❌ Invalid changes option for setted branch!`);
276
+
277
+ return `git diff ${this.branch} --name-only`; // Example: 'git diff <master> --name-only'
278
+ }
279
+
280
+ /**
281
+ * Retrieves the list of files changed in the current Git working directory
282
+ * compared to a specified branch.
283
+ *
284
+ * This method builds a Git diff command and attempts to retrieve the changed
285
+ * files using that command. It logs helpful information and errors during the process.
286
+ *
287
+ * If no changed files are found, or an error occurs at any stage, the method logs
288
+ * the issue and returns `undefined`.
289
+ *
290
+ * @returns {this | undefined} Returns the current instance (`this`) if changed files are found;
291
+ * otherwise, returns `undefined`.
292
+ */
293
+ getGitChangedFiles() {
294
+ let cmd;
295
+
296
+ try {
297
+ cmd = this.#buildGitCommand();
298
+ }
299
+ catch (err) {
300
+ console.error(APP_PREFIX, err.message);
301
+ return undefined;
302
+ }
303
+
304
+ console.error(APP_PREFIX, `ℹ️ We will use '${cmd}' Git command.`);
305
+
306
+ try {
307
+ // For clear unit testing process -> Like test_defaultGitChangedFile = todomvc-tests/edit-todos_test.js
308
+ if (this.isDefaultGitChanges) {
309
+ this.changedFiles = this.#GIT.test_defaultGitChangedFile;
310
+ }
311
+ else {
312
+ this.changedFiles = this.#getChangedFilesFromGit(cmd);
313
+
314
+ if (this.changedFiles.length === 0) {
315
+ console.log(
316
+ APP_PREFIX,
317
+ 'ℹ️ No files changed in the latest Git commit. Skipping coverage processing.'
318
+ );
319
+
320
+ return undefined;
321
+ }
322
+ }
323
+ }
324
+ catch (err) {
325
+ console.error(APP_PREFIX, err.message);
326
+ console.error(APP_PREFIX, "🔍 Pls, check this Git command manually to understand the original problem.");
327
+ return undefined;
328
+ }
329
+
330
+ console.log(APP_PREFIX, `📑 GIT changed files:\n - ${this.changedFiles.join('\n - ')}`);
331
+ return this;
332
+ }
333
+
334
+ /**
335
+ * Validates the coverage file path (stored in `this.coverageFilePath`).
336
+ *
337
+ * This method checks:
338
+ * - That the file exists on disk.
339
+ * - That it is a regular file (not a directory or special file).
340
+ * - That it has a `.yml` extension to ensure it's a YAML file.
341
+ *
342
+ * Logs descriptive error messages for any failures.
343
+ *
344
+ * @returns {this | undefined} "true" in case if coverage file is valid and we can keep going;
345
+ * otherwise, `undefined`.
346
+ */
347
+ validateCoverageFile() {
348
+ // Validate the presence of the coverage filepath
349
+ if (!fs.existsSync(this.coverageFilePath)) {
350
+ console.log(APP_PREFIX, '❌ Coverage file not found:', this.coverageFilePath);
351
+ return undefined;
352
+ }
353
+
354
+ // Ensure the given path is a file (not a directory or other type)
355
+ const stat = fs.statSync(this.coverageFilePath);
356
+ if (!stat.isFile()) {
357
+ console.log(APP_PREFIX, '❌ Provided coverage path is not a file:', this.coverageFilePath);
358
+ return undefined;
359
+ }
360
+
361
+ // Validate the file extension to be ".yml" to ensure it's a YAML file
362
+ if (path.extname(this.coverageFilePath) !== ".yml") {
363
+ console.log(APP_PREFIX, '❌ Coverage file must have a .yml extension:', this.coverageFilePath);
364
+ return undefined;
365
+ }
366
+
367
+ debug('Coverage file validation is OK!');
368
+
369
+ return this;
370
+ }
371
+
372
+ /**
373
+ * Parses the YAML coverage file (located at `this.coverageFilePath`) into a JavaScript object.
374
+ *
375
+ * - Reads the file content using UTF-8 encoding.
376
+ * - Parses it as YAML using the `yaml` library.
377
+ * - Stores the result in `this.parsedCoverage`.
378
+ * - If parsing fails, logs an error and returns `undefined`.
379
+ *
380
+ * @returns {this | undefined} The current parsed coverage yml file change lines, or "undefined" if parsing fails.
381
+ */
382
+ parseCoverageFile() {
383
+ try {
384
+ // Read the contents of the YAML file and attempt to parse the YAML into a JavaScript object
385
+ const rawYml = fs.readFileSync(this.coverageFilePath, 'utf8');
386
+ this.parsedCoverage = yaml.load(rawYml) || {};
387
+
388
+ debug(`Coverage filepath = ${this.coverageFilePath})`);
389
+ console.log(APP_PREFIX, `✅ Coverage file parsed successfully: ${this.coverageFilePath}`);
390
+
391
+ return this;
392
+ }
393
+ catch (err) {
394
+ console.error(APP_PREFIX, '❌ Failed to parse YAML:', err.message);
395
+ return undefined;
396
+ }
397
+ }
398
+
399
+ /**
400
+ * Extracts relevant test identifiers from changed files based on coverage mapping.
401
+ *
402
+ * Iterates over changed files and matches them against patterns in the parsed coverage data.
403
+ * For each match, it extracts test IDs or tags and stores them in corresponding sets:
404
+ * - Test IDs (starting with '@T' or '@S') are stored in `this.tests`
405
+ * - Tag labels (starting with 'tag:') are stored in `this.tagLabels`
406
+ * - Matched file paths are stored in `this.matchedLines`
407
+ *
408
+ * @returns {Promise <Set<string>>} A set of file paths that matched coverage patterns (`this.matchedLines`).
409
+ */
410
+ async extractRelevantTestsFromChanges() {
411
+ for (const changedFile of this.changedFiles) {
412
+ for (const [pattern, ids] of Object.entries(this.parsedCoverage)) {
413
+ if (minimatch(changedFile, pattern)) {
414
+ this.matchedLines.add(changedFile);
415
+
416
+ ids.forEach(id => {
417
+ // Example: "@Tt74099t1"
418
+ if (id.startsWith('@T')) {
419
+ this.tests.add(id.slice(1));
420
+ }
421
+ // Example: "@Sd74099c1"
422
+ else if (id.startsWith('@S')) {
423
+ this.tests.add(id.slice(1));
424
+ }
425
+ // Example: "tag:@TestSmoke"
426
+ else if (id.startsWith('tag')) {
427
+ this.tagLabels.add(id.split(':')[1].slice(1));
428
+ }
429
+ });
430
+ }
431
+ }
432
+ }
433
+
434
+ debug(`Matched lines: ${this.matchedLines}`);
435
+
436
+ return this.matchedLines;
437
+ }
438
+ }
439
+
440
+ export default CoveragePipe;
package/src/pipe/index.js CHANGED
@@ -7,6 +7,7 @@ import GitHubPipe from './github.js';
7
7
  import GitLabPipe from './gitlab.js';
8
8
  import CsvPipe from './csv.js';
9
9
  import HtmlPipe from './html.js';
10
+ import CoveragePipe from './coverage.js';
10
11
  import { BitbucketPipe } from './bitbucket.js';
11
12
  import { DebugPipe } from './debug.js';
12
13
 
@@ -48,6 +49,7 @@ export async function pipesFactory(params, opts) {
48
49
  new CsvPipe(params, opts),
49
50
  new HtmlPipe(params, opts),
50
51
  new BitbucketPipe(params, opts),
52
+ new CoveragePipe(params, opts),
51
53
  new DebugPipe(params, opts),
52
54
  ...extraPipes,
53
55
  ];
@@ -3,7 +3,12 @@ import pc from 'picocolors';
3
3
  import { Gaxios } from 'gaxios';
4
4
  import JsonCycle from 'json-cycle';
5
5
  import { APP_PREFIX, STATUS, AXIOS_TIMEOUT, REPORTER_REQUEST_RETRIES } from '../constants.js';
6
- import { isValidUrl, foundedTestLog, readLatestRunId, transformEnvVarToBoolean } from '../utils/utils.js';
6
+ import { isValidUrl,
7
+ foundedTestLog,
8
+ readLatestRunId,
9
+ transformEnvVarToBoolean,
10
+ getGitCommitSha
11
+ } from '../utils/utils.js';
7
12
  import { parseFilterParams, generateFilterRequestParams, setS3Credentials } from '../utils/pipe_utils.js';
8
13
  import { config } from '../config.js';
9
14
 
@@ -46,7 +51,25 @@ class TestomatioPipe {
46
51
  this.store = store || {};
47
52
  this.title = params.title || process.env.TESTOMATIO_TITLE;
48
53
  this.sharedRun = !!process.env.TESTOMATIO_SHARED_RUN;
49
- this.sharedRunTimeout = !!process.env.TESTOMATIO_SHARED_RUN_TIMEOUT;
54
+ this.sharedRunTimeout = process.env.TESTOMATIO_SHARED_RUN_TIMEOUT
55
+ ? parseInt(process.env.TESTOMATIO_SHARED_RUN_TIMEOUT, 10)
56
+ : undefined;
57
+
58
+ if (this.sharedRunTimeout && !this.sharedRun) {
59
+ debug('Auto-enabling sharedRun because sharedRunTimeout is set');
60
+ this.sharedRun = true;
61
+ }
62
+
63
+ if (!this.title && (this.sharedRun || this.sharedRunTimeout)) {
64
+ const sha = getGitCommitSha();
65
+ if (sha) {
66
+ this.title = `Shared Run - ${sha}`;
67
+ console.log(APP_PREFIX, `🔄 Auto-generated title for shared run: ${this.title}`);
68
+ } else {
69
+ console.log(APP_PREFIX, pc.red('Failed to resolve git commit SHA for shared run title.'));
70
+ console.log(APP_PREFIX, 'Please run the tests inside a Git repository or set TESTOMATIO_TITLE explicitly.');
71
+ }
72
+ }
50
73
  this.groupTitle = params.groupTitle || process.env.TESTOMATIO_RUNGROUP_TITLE;
51
74
  this.env = process.env.TESTOMATIO_ENV;
52
75
  this.label = process.env.TESTOMATIO_LABEL;
@@ -129,17 +152,23 @@ class TestomatioPipe {
129
152
  async prepareRun(opts) {
130
153
  if (!this.isEnabled) return [];
131
154
 
132
- const { type, id } = parseFilterParams(opts);
155
+ const clearOptions = parseFilterParams(opts);
156
+
157
+ if (!clearOptions) {
158
+ return [];
159
+ }
160
+
161
+ const { type, id } = clearOptions;
133
162
 
134
163
  try {
135
164
  const q = generateFilterRequestParams({
136
165
  type,
137
166
  id,
138
- apiKey: this.apiKey.trim(),
167
+ apiKey: this?.apiKey?.trim(),
139
168
  });
140
169
 
141
170
  if (!q) {
142
- return;
171
+ return [];
143
172
  }
144
173
 
145
174
  const resp = await this.client.request({