@testomatio/reporter 1.0.9-beta.2 → 1.0.10

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.
@@ -13,11 +13,9 @@ program
13
13
  .option('--launch', 'Start a new run and return its ID')
14
14
  .option('--finish', 'Finish Run by its ID')
15
15
  .option("--env-file <envfile>", "Load environment variables from env file")
16
- .option("--filter <filter>", "Additional execution filter")
17
- .action(async (opts) => {
18
- const { launch, finish, filter } = opts;
19
- let { command } = opts;
16
+ .action(opts => {
20
17
 
18
+ const { command, launch, finish } = opts;
21
19
  if (opts.envFile) require('dotenv').config(opts.envFile); // eslint-disable-line
22
20
 
23
21
  const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || process.env.TESTOMATIO;
@@ -53,27 +51,6 @@ program
53
51
 
54
52
  let exitCode = 0;
55
53
 
56
- const client = new TestomatClient({ apiKey, title, parallel: true });
57
-
58
- if(filter) {
59
- const [pipe, ...optsArray] = filter.split(":");
60
- const opts = optsArray.join(":");
61
-
62
- try {
63
- const tests = await client.prepareRun({pipe, opts});
64
-
65
- if(!tests || tests.length === 0) {
66
- return;
67
- }
68
-
69
- const grep = ` --grep (${tests.join('|')})`;
70
- command += grep;
71
- }
72
- catch(err) {
73
- console.log(APP_PREFIX, err);
74
- }
75
- }
76
-
77
54
  if (!command.split) {
78
55
  process.exitCode = 255;
79
56
  console.log(APP_PREFIX, `No command provided. Use -c option to launch a test runner.`);
@@ -96,6 +73,8 @@ program
96
73
  return;
97
74
  }
98
75
 
76
+ const client = new TestomatClient({ apiKey, title, parallel: true });
77
+
99
78
  client.createRun().then(() => {
100
79
  const cmd = spawn(testCmds[0], testCmds.slice(1), { stdio: 'inherit' });
101
80
 
package/lib/client.js CHANGED
@@ -27,60 +27,9 @@ class Client {
27
27
  this.queue = Promise.resolve();
28
28
  this.totalUploaded = 0;
29
29
  this.version = JSON.parse(fs.readFileSync(join(__dirname, '..', 'package.json')).toString()).version;
30
- this.executionList = Promise.resolve();
31
-
32
30
  console.log(APP_PREFIX, `Testomatio Reporter v${this.version}`);
33
31
  }
34
32
 
35
- /**
36
- * Asynchronously prepares the execution list for running tests through various pipes.
37
- * Each pipe in the client is checked for enablement,
38
- * and if all pipes are disabled, the function returns a resolved Promise.
39
- * Otherwise, it executes the `prepareRun` method for each enabled pipe and collects the results.
40
- * The results are then filtered to remove any undefined values.
41
- * If no valid results are found, the function returns undefined.
42
- * Otherwise, it returns the first non-empty array from the filtered results.
43
- *
44
- * @param {Object} params - The options for preparing the test execution list.
45
- * @param {string} params.pipe - Name of the executed pipe.
46
- * @param {string} params.opts - Filter option.
47
- * @returns {Promise<any>} - A Promise that resolves to an
48
- * array containing the prepared execution list,
49
- * or resolves to undefined if no valid results are found or if all pipes are disabled.
50
- */
51
- async prepareRun(params) {
52
- const { pipe, opts } = params;
53
- // all pipes disabled, skipping
54
- if (!this.pipes.some(p => p.isEnabled)) {
55
- return Promise.resolve();
56
- }
57
-
58
- try {
59
- if (pipe.toLowerCase() !== "testomatio") {
60
- //TODO: for the future for the another pipes
61
- console.warn(APP_PREFIX, `At the moment processing is available only for the "testomatio" key. Example: "testomatio:tag-name=xxx"`)
62
- return;
63
- }
64
-
65
- const results = await Promise.all(this.pipes.map(async p => {
66
- return { pipe: p.toString(), result: await p.prepareRun(opts) };
67
- }));
68
-
69
- const result = results.filter(p => p.pipe.includes('Testomatio'))[0]?.result;
70
-
71
- if (!result || result.length === 0) {
72
- return;
73
- }
74
-
75
- debug('Execution tests list', result);
76
-
77
- return result;
78
- } catch (err) {
79
- console.error(APP_PREFIX, err);
80
- return;
81
- }
82
- }
83
-
84
33
  /**
85
34
  * Used to create a new Test run
86
35
  *
package/lib/pipe/csv.js CHANGED
@@ -40,8 +40,6 @@ class CsvPipe {
40
40
  }
41
41
  }
42
42
 
43
- async prepareRun(opts) {}
44
-
45
43
  async createRun() {
46
44
  // empty
47
45
  }
@@ -6,7 +6,6 @@ const merge = require('lodash.merge');
6
6
  const { Octokit } = require('@octokit/rest');
7
7
  const { APP_PREFIX } = require('../constants');
8
8
  const { ansiRegExp, isSameTest } = require('../util');
9
- const { statusEmoji, fullName } = require('./misc');
10
9
 
11
10
  /**
12
11
  * @typedef {import('../../types').Pipe} Pipe
@@ -38,8 +37,6 @@ class GitHubPipe {
38
37
  debug('GitHub Pipe: Enabled');
39
38
  }
40
39
 
41
- async prepareRun(opts) {}
42
-
43
40
  async createRun() {}
44
41
 
45
42
  addTest(test) {
@@ -185,6 +182,21 @@ class GitHubPipe {
185
182
  }
186
183
  }
187
184
 
185
+ function statusEmoji(status) {
186
+ if (status === 'passed') return '🟢';
187
+ if (status === 'failed') return '🔴';
188
+ if (status === 'skipped') return '🟡';
189
+ return '';
190
+ }
191
+
192
+ function fullName(t) {
193
+ let line = '';
194
+ if (t.suite_title) line = `${t.suite_title}: `;
195
+ line += `**${t.title}**`;
196
+ if (t.example) line += ` \`[${Object.values(t.example)}]\``;
197
+ return line;
198
+ }
199
+
188
200
  async function deletePreviousReport(octokit, owner, repo, issue, hiddenCommentData) {
189
201
  if (process.env.GH_KEEP_OUTDATED_REPORTS) return;
190
202
 
@@ -6,7 +6,6 @@ const merge = require('lodash.merge');
6
6
  const path = require('path');
7
7
  const { APP_PREFIX } = require('../constants');
8
8
  const { ansiRegExp, isSameTest } = require('../util');
9
- const { statusEmoji, fullName } = require('./misc');
10
9
 
11
10
  //! GITLAB_PAT environment variable is required for this functionality to work
12
11
  //! and your pipeline trigger should be merge_request
@@ -47,8 +46,6 @@ class GitLabPipe {
47
46
  debug('GitLab Pipe: Enabled');
48
47
  }
49
48
 
50
- async prepareRun(opts) {}
51
-
52
49
  async createRun() {}
53
50
 
54
51
  addTest(test) {
@@ -182,6 +179,21 @@ class GitLabPipe {
182
179
  updateRun() {}
183
180
  }
184
181
 
182
+ function statusEmoji(status) {
183
+ if (status === 'passed') return '🟢';
184
+ if (status === 'failed') return '🔴';
185
+ if (status === 'skipped') return '🟡';
186
+ return '';
187
+ }
188
+
189
+ function fullName(t) {
190
+ let line = '';
191
+ if (t.suite_title) line = `${t.suite_title}: `;
192
+ line += `**${t.title}**`;
193
+ if (t.example) line += ` \`[${Object.values(t.example)}]\``;
194
+ return line;
195
+ }
196
+
185
197
  async function deletePreviousReport(axiosInstance, commentsRequestURL, hiddenCommentData, token) {
186
198
  if (process.env.GITLAB_KEEP_OUTDATED_REPORTS) return;
187
199
 
@@ -3,8 +3,8 @@ const chalk = require('chalk');
3
3
  const axios = require('axios');
4
4
  const JsonCycle = require('json-cycle');
5
5
  const { APP_PREFIX, STATUS } = require('../constants');
6
- const { isValidUrl, foundedTestLog } = require('../util');
7
- const { parseFilterParams, generateFilterRequestParams, setS3Credentials, } = require('./misc');
6
+ const { isValidUrl } = require('../util');
7
+ const { resetConfig } = require('../fileUploader');
8
8
 
9
9
  const { TESTOMATIO_RUN } = process.env;
10
10
  if (TESTOMATIO_RUN) {
@@ -33,12 +33,7 @@ class TestomatioPipe {
33
33
  this.sharedRun = !!process.env.TESTOMATIO_SHARED_RUN;
34
34
  this.groupTitle = params.groupTitle || process.env.TESTOMATIO_RUNGROUP_TITLE;
35
35
  this.env = process.env.TESTOMATIO_ENV;
36
-
37
- this.axios = axios.create({
38
- baseURL: `${this.url.trim()}`,
39
- timeout: 20000
40
- });
41
-
36
+ this.axios = axios.create();
42
37
  this.isEnabled = true;
43
38
  // do not finish this run (for parallel testing)
44
39
  this.proceed = process.env.TESTOMATIO_PROCEED;
@@ -52,50 +47,6 @@ class TestomatioPipe {
52
47
  }
53
48
  }
54
49
 
55
- /**
56
- * Asynchronously prepares and retrieves the Testomat.io test grepList based on the provided options.
57
- * @param {Object} opts - The options for preparing the test grepList.
58
- * @returns {Promise<string[]>} - An array containing the retrieved
59
- * test grepList, or an empty array if no tests are found or the request is disabled.
60
- * @throws {Error} - Throws an error if there was a problem while making the request.
61
- */
62
- async prepareRun(opts) {
63
- if (!this.isEnabled) return [];
64
-
65
- const { type, id } = parseFilterParams(opts);
66
-
67
- try {
68
- const q = generateFilterRequestParams({
69
- type,
70
- id,
71
- apiKey: this.apiKey.trim()
72
- });
73
-
74
- if (!q) {
75
- return;
76
- }
77
-
78
- const resp = await this.axios.get('/api/test_grep', q);
79
- const { data } = resp;
80
-
81
- if (Array.isArray(data?.tests) && data?.tests?.length > 0) {
82
- foundedTestLog(APP_PREFIX, data.tests);
83
- return data.tests;
84
- }
85
- else {
86
- console.log(APP_PREFIX, `⛔ No tests found for your --filter --> ${type}=${id}`);
87
- return;
88
- }
89
- }
90
- catch (err) {
91
- console.error(
92
- APP_PREFIX,
93
- `🚩 Error getting Testomat.io test grepList: ${err}`,
94
- );
95
- return;
96
- }
97
- }
98
-
99
50
  /**
100
51
  * @returns Promise<void>
101
52
  */
@@ -120,12 +71,15 @@ class TestomatioPipe {
120
71
 
121
72
  if (buildUrl && !buildUrl.startsWith('http')) buildUrl = undefined;
122
73
 
74
+ const accessEvent = process.env.TESTOMATIO_PUBLISH ? 'publish' : null;
75
+
123
76
  const runParams = Object.fromEntries(
124
77
  Object.entries({
125
78
  ci_build_url: buildUrl,
126
79
  parallel: this.parallel,
127
80
  api_key: this.apiKey.trim(),
128
81
  group_title: this.groupTitle,
82
+ access_event: accessEvent,
129
83
  env: this.env,
130
84
  title: this.title,
131
85
  shared_run: this.sharedRun,
@@ -133,20 +87,22 @@ class TestomatioPipe {
133
87
  );
134
88
 
135
89
  if (this.runId) {
136
- const resp = await this.axios.put(`/api/reporter/${this.runId}`, runParams);
90
+ const resp = await this.axios.put(`${this.url.trim()}/api/reporter/${this.runId}`, runParams);
137
91
  if (resp.data.artifacts) setS3Credentials(resp.data.artifacts);
138
92
  return;
139
93
  }
140
94
 
141
95
  try {
142
- const resp = await this.axios.post(`/api/reporter`, runParams, {
96
+ const resp = await this.axios.post(`${this.url.trim()}/api/reporter`, runParams, {
143
97
  maxContentLength: Infinity,
144
98
  maxBodyLength: Infinity,
145
99
  });
146
100
  this.runId = resp.data.uid;
147
101
  this.runUrl = `${this.url}/${resp.data.url.split('/').splice(3).join('/')}`;
102
+ this.runPublicUrl = resp.data.public_url;
148
103
  if (resp.data.artifacts) setS3Credentials(resp.data.artifacts);
149
104
  this.store.runUrl = this.runUrl;
105
+ this.store.runPublicUrl = this.runPublicUrl;
150
106
  this.store.runId = this.runId;
151
107
  console.log(APP_PREFIX, '📊 Report created. Report ID:', this.runId);
152
108
  process.env.runId = this.runId;
@@ -170,7 +126,7 @@ class TestomatioPipe {
170
126
  data.create = this.createNewTests;
171
127
  const json = JsonCycle.stringify(data);
172
128
 
173
- return this.axios.post(`/api/reporter/${this.runId}/testrun`, json, {
129
+ return this.axios.post(`${this.url}/api/reporter/${this.runId}/testrun`, json, {
174
130
  maxContentLength: Infinity,
175
131
  maxBodyLength: Infinity,
176
132
  headers: {
@@ -218,7 +174,7 @@ class TestomatioPipe {
218
174
 
219
175
  try {
220
176
  if (this.runId && !this.proceed) {
221
- await this.axios.put(`/api/reporter/${this.runId}`, {
177
+ await this.axios.put(`${this.url}/api/reporter/${this.runId}`, {
222
178
  api_key: this.apiKey,
223
179
  status_event,
224
180
  tests: params.tests,
@@ -226,6 +182,10 @@ class TestomatioPipe {
226
182
  if (this.runUrl) {
227
183
  console.log(APP_PREFIX, '📊 Report Saved. Report URL:', chalk.magenta(this.runUrl));
228
184
  }
185
+ if (this.runPublicUrl) {
186
+ console.log(APP_PREFIX, '🌟 Public URL:', chalk.magenta(this.runPublicUrl));
187
+ }
188
+
229
189
  }
230
190
  if (this.runUrl && this.proceed) {
231
191
  const notFinishedMessage = chalk.yellow.bold('Run was not finished because of $TESTOMATIO_PROCEED');
@@ -258,3 +218,18 @@ class TestomatioPipe {
258
218
  }
259
219
 
260
220
  module.exports = TestomatioPipe;
221
+
222
+
223
+ function setS3Credentials(artifacts) {
224
+ if (!Object.keys(artifacts).length) return;
225
+
226
+ console.log(APP_PREFIX, 'S3 were credentials obtained from Testomat.io...');
227
+
228
+ if (artifacts.ACCESS_KEY_ID) process.env.S3_ACCESS_KEY_ID = artifacts.ACCESS_KEY_ID;
229
+ if (artifacts.SECRET_ACCESS_KEY) process.env.S3_SECRET_ACCESS_KEY = artifacts.SECRET_ACCESS_KEY;
230
+ if (artifacts.REGION) process.env.S3_REGION = artifacts.REGION;
231
+ if (artifacts.BUCKET) process.env.S3_BUCKET = artifacts.BUCKET;
232
+ if (artifacts.ENDPOINT) process.env.S3_ENDPOINT = artifacts.ENDPOINT;
233
+ if (artifacts.presign) process.env.TESTOMATIO_PRIVATE_ARTIFACTS = '1';
234
+ resetConfig();
235
+ }
package/lib/util.js CHANGED
@@ -192,15 +192,6 @@ const fileSystem = {
192
192
  }
193
193
  };
194
194
 
195
-
196
- const foundedTestLog = (app, tests) => {
197
- const n = tests.length;
198
-
199
- return (n === 1)
200
- ? console.log(app, `✅ We found only one test!`)
201
- : console.log(app, `✅ We found ${n} tests!`);
202
- }
203
-
204
195
  const humanize = (text) => {
205
196
  text = decamelize(text);
206
197
  return text.replace(/_./g, match => ` ${ match.charAt(1).toUpperCase()}`)
@@ -259,5 +250,4 @@ module.exports = {
259
250
  parseTest,
260
251
  parseSuite,
261
252
  humanize,
262
- foundedTestLog
263
- }
253
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "1.0.9-beta.2",
3
+ "version": "1.0.10",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "typings": "typings/index.d.ts",
package/lib/pipe/misc.js DELETED
@@ -1,135 +0,0 @@
1
- const { resetConfig } = require('../fileUploader');
2
- const { APP_PREFIX } = require('../constants');
3
-
4
- /**
5
- * Set S3 credentials from the provided artifacts object.
6
- * @param {Object} artifacts - The artifacts object containing S3 credentials.
7
- */
8
- function setS3Credentials(artifacts) {
9
- if (!Object.keys(artifacts).length) return;
10
-
11
- console.log(APP_PREFIX, 'S3 were credentials obtained from Testomat.io...');
12
-
13
- if (artifacts.ACCESS_KEY_ID) process.env.S3_ACCESS_KEY_ID = artifacts.ACCESS_KEY_ID;
14
- if (artifacts.SECRET_ACCESS_KEY) process.env.S3_SECRET_ACCESS_KEY = artifacts.SECRET_ACCESS_KEY;
15
- if (artifacts.REGION) process.env.S3_REGION = artifacts.REGION;
16
- if (artifacts.BUCKET) process.env.S3_BUCKET = artifacts.BUCKET;
17
- if (artifacts.ENDPOINT) process.env.S3_ENDPOINT = artifacts.ENDPOINT;
18
- if (artifacts.presign) process.env.TESTOMATIO_PRIVATE_ARTIFACTS = '1';
19
- resetConfig();
20
- }
21
- /**
22
- * Generates mode request parameters based on the input params.
23
- * @param {Object} params - The input parameters for the request.
24
- * @param {string} params.type - The type of the request (e.g., "tag").
25
- * @param {string} params.id - The ID associated with the request.
26
- * @param {string} params.apiKey - The API key for authentication.
27
- * @returns {Object|null} - An object containing the generated request parameters, or null if the type is invalid.
28
- */
29
- function generateFilterRequestParams(params) {
30
- const { type, id, apiKey } = params;
31
-
32
- if (!type) {
33
- return;
34
- }
35
-
36
- if (!id) {
37
- console.error(APP_PREFIX, `Please make sure your settings "${type.toUpperCase()}"= "${id}" is correct!`);
38
- return;
39
- }
40
-
41
- return {
42
- params: {
43
- type,
44
- id: encodeURIComponent(id),
45
- api_key: apiKey
46
- },
47
- responseType: "json"
48
- }
49
- }
50
-
51
- /**
52
- * Parse filter parameters from a string in the format "type=id".
53
- * @param {string} opts - The input string containing the filter parameters.
54
- * @returns {Object} An object containing the parsed filter parameters.
55
- * The object has properties "type" and "id".
56
- */
57
- function parseFilterParams(opts) {
58
- const [type, id] = opts.split("=");
59
- const validType = updateFilterType(type);
60
-
61
- return {
62
- type: validType,
63
- id
64
- };
65
- }
66
-
67
- /**
68
- * Update and validate the filter type.
69
- * @param {string} type - The original filter type.
70
- * @returns {string|undefined} The updated and validated filter type.
71
- * Returns undefined if the type is not valid.
72
- */
73
- function updateFilterType(type) {
74
- const typeLowerCase = type.toLowerCase();
75
-
76
- const filterTypes = [
77
- "tag-name",
78
- "plan-id",
79
- "label",
80
- "jira-ticket",
81
- ];
82
-
83
- const filterApi = [
84
- "tag",
85
- "plan",
86
- "label",
87
- "jira",
88
- // "ims-issue", //TODO: WIP
89
- ];
90
-
91
- if (!filterTypes.includes(typeLowerCase)) {
92
- console.log(APP_PREFIX, `❗❗❗ Invalid "filter=${type}" start settings! Available option list: ${filterTypes}`);
93
- return;
94
- }
95
-
96
- const index = filterTypes.indexOf(typeLowerCase);
97
-
98
- return (index !== -1)
99
- ? filterApi[index]
100
- : undefined
101
- }
102
-
103
- /**
104
- * Return an emoji based on the provided status.
105
- * @param {string} status - The status value ('passed', 'failed', or 'skipped').
106
- * @returns {string} - An emoji corresponding to the provided status.
107
- */
108
- function statusEmoji(status) {
109
- if (status === 'passed') return '🟢';
110
- if (status === 'failed') return '🔴';
111
- if (status === 'skipped') return '🟡';
112
- return '';
113
- }
114
-
115
- /**
116
- * Generate a full name string based on the provided test object.
117
- * @param {object} t - The test object.
118
- * @returns {string} - A formatted full name string for the test object.
119
- */
120
- function fullName(t) {
121
- let line = '';
122
- if (t.suite_title) line = `${t.suite_title}: `;
123
- line += `**${t.title}**`;
124
- if (t.example) line += ` \`[${Object.values(t.example)}]\``;
125
- return line;
126
- }
127
-
128
- module.exports = {
129
- updateFilterType,
130
- parseFilterParams,
131
- generateFilterRequestParams,
132
- setS3Credentials,
133
- statusEmoji,
134
- fullName
135
- };