@testomatio/reporter 1.1.2-beta-fix-config → 1.1.2-beta-fix-config-3

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.
@@ -5,7 +5,7 @@ const fs = require('fs');
5
5
  const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../../constants');
6
6
  const TestomatClient = require('../../client');
7
7
  const { parseTest, fileSystem } = require('../../utils/utils');
8
- const { TESTOMATIO } = require('../../config');
8
+ const config = require('../../config');
9
9
  const { services } = require('../../services');
10
10
 
11
11
  const { GherkinDocumentParser, PickleParser } = formatterHelpers;
@@ -30,7 +30,7 @@ class CucumberReporter extends Formatter {
30
30
  this.failures = [];
31
31
  this.cases = [];
32
32
 
33
- this.client = new TestomatClient({ apiKey: options.apiKey || TESTOMATIO });
33
+ this.client = new TestomatClient({ apiKey: options.apiKey || config.TESTOMATIO });
34
34
  this.status = STATUS.PASSED;
35
35
  }
36
36
 
@@ -4,7 +4,7 @@ const chalk = require('chalk');
4
4
  const { parseTest, fileSystem } = require('../../utils/utils');
5
5
  const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../../constants');
6
6
  const TestomatClient = require('../../client');
7
- const { TESTOMATIO } = require('../../config');
7
+ const config = require('../../config');
8
8
 
9
9
  const createTestomatFormatter = apiKey => {
10
10
  if (!apiKey || apiKey === '') {
@@ -152,4 +152,4 @@ const createTestomatFormatter = apiKey => {
152
152
  };
153
153
  };
154
154
 
155
- module.exports = createTestomatFormatter(TESTOMATIO);
155
+ module.exports = createTestomatFormatter(config.TESTOMATIO);
@@ -1,14 +1,14 @@
1
1
  const { STATUS } = require('../../constants');
2
2
  const { parseTest, parseSuite } = require('../../utils/utils');
3
3
  const TestomatClient = require('../../client');
4
- const { TESTOMATIO } = require('../../config');
4
+ const config = require('../../config');
5
5
 
6
6
  const testomatioReporter = on => {
7
- if (!TESTOMATIO) {
7
+ if (!config.TESTOMATIO) {
8
8
  console.log('TESTOMATIO key is empty, ignoring reports');
9
9
  return;
10
10
  }
11
- const client = new TestomatClient({ apiKey: TESTOMATIO });
11
+ const client = new TestomatClient({ apiKey: config.TESTOMATIO });
12
12
 
13
13
  on('before:run', async run => {
14
14
  // TODO: looks like client.env does not exist
@@ -4,7 +4,7 @@ const chalk = require('chalk');
4
4
  const TestomatClient = require('../client');
5
5
  const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
6
6
  const { parseTest, fileSystem } = require('../utils/utils');
7
- const { TESTOMATIO } = require('../config');
7
+ const config = require('../config');
8
8
  const { services } = require('../services');
9
9
 
10
10
  const {
@@ -26,7 +26,7 @@ function MochaReporter(runner, opts) {
26
26
  let skipped = 0;
27
27
  // let artifactStore;
28
28
 
29
- const apiKey = opts?.reporterOptions?.apiKey || TESTOMATIO;
29
+ const apiKey = opts?.reporterOptions?.apiKey || config.TESTOMATIO;
30
30
 
31
31
  const client = new TestomatClient({ apiKey });
32
32
 
@@ -5,7 +5,7 @@ const chalk = require('chalk');
5
5
  const TestomatClient = require('../client');
6
6
  const { APP_PREFIX, STATUS } = require('../constants');
7
7
  const { version } = require('../../package.json');
8
- const { TESTOMATIO } = require('../config');
8
+ const config = require('../config');
9
9
 
10
10
  console.log(chalk.cyan.bold(` 🤩 Testomat.io Reporter v${version}`));
11
11
 
@@ -21,7 +21,7 @@ program
21
21
 
22
22
  if (opts.envFile) require('dotenv').config(opts.envFile); // eslint-disable-line
23
23
 
24
- const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || TESTOMATIO;
24
+ const apiKey = process.env['INPUT_TESTOMATIO-KEY'] || config.TESTOMATIO;
25
25
  const title = process.env.TESTOMATIO_TITLE;
26
26
 
27
27
  if (launch) {
package/lib/config.js CHANGED
@@ -1,16 +1,24 @@
1
- // This file is used to read environment variables from .env file and process.env
1
+ // This file is used to read environment variables from .env file
2
+
3
+ if (process.env.TESTOMATIO_ENV_FILE_PATH) {
4
+ require('dotenv').config({ path: process.env.TESTOMATIO_ENV_FILE_PATH });
5
+ }
2
6
 
3
- // ! uncommenting next line leads ro reading vars from .env file
4
- // require('dotenv').config();
5
7
  const debug = require('debug')('@testomatio/reporter:config');
6
8
 
7
9
  /* for possibility to use multiple env files (reading different paths)
8
10
  const dotenv = require('dotenv');
9
11
  const envFileVars = dotenv.config({ path: '.env' }).parsed; */
10
12
 
11
- const TESTOMATIO = process.env.TESTOMATIO || process.env.TESTOMATIO_API_KEY || process.env.TESTOMATIO_TOKEN || '';
12
- if (TESTOMATIO === 'undefined') console.error('TESTOMATIO is "undefined". Something went wrong. Contact dev team.');
13
- process.env.TESTOMATIO = TESTOMATIO;
13
+ if (process.env.TESTOMATIO_API_KEY) {
14
+ process.env.TESTOMATIO = process.env.TESTOMATIO_API_KEY;
15
+ }
16
+ if (process.env.TESTOMATIO_TOKEN) {
17
+ process.env.TESTOMATIO = process.env.TESTOMATIO_TOKEN;
18
+ }
19
+
20
+ if (process.env.TESTOMATIO === 'undefined')
21
+ console.error('TESTOMATIO is "undefined". Something went wrong. Contact dev team.');
14
22
 
15
23
  // select only TESTOMATIO related variables (only to print them in debug)
16
24
  const testomatioEnvVars =
@@ -26,4 +34,3 @@ debug('TESTOMATIO variables:', testomatioEnvVars);
26
34
  const config = process.env;
27
35
 
28
36
  module.exports = config;
29
- module.exports.TESTOMATIO = TESTOMATIO;
@@ -8,8 +8,8 @@ const JsonCycle = require('json-cycle');
8
8
 
9
9
  const { APP_PREFIX, STATUS, AXIOS_TIMEOUT, AXIOS_RETRY_TIMEOUT } = require('../constants');
10
10
  const { isValidUrl, foundedTestLog } = require('../utils/utils');
11
- const { parseFilterParams, generateFilterRequestParams, setS3Credentials, } = require('../utils/pipe_utils');
12
- const { TESTOMATIO } = require('../config');
11
+ const { parseFilterParams, generateFilterRequestParams, setS3Credentials } = require('../utils/pipe_utils');
12
+ const config = require('../config');
13
13
 
14
14
  if (process.env.TESTOMATIO_RUN) {
15
15
  process.env.runId = process.env.TESTOMATIO_RUN;
@@ -25,7 +25,7 @@ class TestomatioPipe {
25
25
  constructor(params, store) {
26
26
  this.isEnabled = false;
27
27
  this.url = params.testomatioUrl || process.env.TESTOMATIO_URL || 'https://app.testomat.io';
28
- this.apiKey = params.apiKey || TESTOMATIO;
28
+ this.apiKey = params.apiKey || config.TESTOMATIO;
29
29
  debug('Testomatio Pipe: ', this.apiKey ? 'API KEY' : '*no api key*');
30
30
  if (!this.apiKey) {
31
31
  return;
@@ -47,7 +47,7 @@ class TestomatioPipe {
47
47
  axiosRetry(this.axios, {
48
48
  retries: 3, // Number of retries (Defaults to 3)
49
49
  shouldResetTimeout: true,
50
- retryCondition: (error) => {
50
+ retryCondition: error => {
51
51
  // Conditional check the error status code
52
52
  switch (error.response.status) {
53
53
  case 409:
@@ -59,8 +59,8 @@ class TestomatioPipe {
59
59
  return false; // Do not retry the others
60
60
  }
61
61
  },
62
- retryDelay: (retryCount) => retryCount * AXIOS_RETRY_TIMEOUT, // sum = 15sec
63
- onRetry: (retryCount) => {
62
+ retryDelay: retryCount => retryCount * AXIOS_RETRY_TIMEOUT, // sum = 15sec
63
+ onRetry: retryCount => {
64
64
  debug(`Retry attempt #${retryCount} failed. Retrying again...`);
65
65
  },
66
66
  });
@@ -82,7 +82,7 @@ class TestomatioPipe {
82
82
  /**
83
83
  * Asynchronously prepares and retrieves the Testomat.io test grepList based on the provided options.
84
84
  * @param {Object} opts - The options for preparing the test grepList.
85
- * @returns {Promise<string[]>} - An array containing the retrieved
85
+ * @returns {Promise<string[]>} - An array containing the retrieved
86
86
  * test grepList, or an empty array if no tests are found or the request is disabled.
87
87
  * @throws {Error} - Throws an error if there was a problem while making the request.
88
88
  */
@@ -95,7 +95,7 @@ class TestomatioPipe {
95
95
  const q = generateFilterRequestParams({
96
96
  type,
97
97
  id,
98
- apiKey: this.apiKey.trim()
98
+ apiKey: this.apiKey.trim(),
99
99
  });
100
100
 
101
101
  if (!q) {
@@ -109,14 +109,10 @@ class TestomatioPipe {
109
109
  foundedTestLog(APP_PREFIX, data.tests);
110
110
  return data.tests;
111
111
  }
112
-
112
+
113
113
  console.log(APP_PREFIX, `⛔ No tests found for your --filter --> ${type}=${id}`);
114
- }
115
- catch (err) {
116
- console.error(
117
- APP_PREFIX,
118
- `🚩 Error getting Testomat.io test grepList: ${err}`,
119
- );
114
+ } catch (err) {
115
+ console.error(APP_PREFIX, `🚩 Error getting Testomat.io test grepList: ${err}`);
120
116
  }
121
117
  }
122
118
 
@@ -212,37 +208,38 @@ class TestomatioPipe {
212
208
 
213
209
  debug('Adding test', json);
214
210
 
215
- return this.axios.post(`/api/reporter/${this.runId}/testrun`, json, {
216
- maxContentLength: Infinity,
217
- maxBodyLength: Infinity,
218
- headers: {
219
- // Overwrite Axios's automatically set Content-Type
220
- 'Content-Type': 'application/json',
221
- },
222
- })
223
- .catch(err => {
224
- if (err.response) {
225
- if (err.response.status >= 400) {
226
- const responseData = err.response.data || { message: '' };
211
+ return this.axios
212
+ .post(`/api/reporter/${this.runId}/testrun`, json, {
213
+ maxContentLength: Infinity,
214
+ maxBodyLength: Infinity,
215
+ headers: {
216
+ // Overwrite Axios's automatically set Content-Type
217
+ 'Content-Type': 'application/json',
218
+ },
219
+ })
220
+ .catch(err => {
221
+ if (err.response) {
222
+ if (err.response.status >= 400) {
223
+ const responseData = err.response.data || { message: '' };
224
+ console.log(
225
+ APP_PREFIX,
226
+ chalk.yellow(`Warning: ${responseData.message} (${err.response.status})`),
227
+ chalk.grey(data?.title || ''),
228
+ );
229
+ if (err.response.data.message.includes('could not be matched')) {
230
+ this.hasUnmatchedTests = true;
231
+ }
232
+ return;
233
+ }
227
234
  console.log(
228
235
  APP_PREFIX,
229
- chalk.yellow(`Warning: ${responseData.message} (${err.response.status})`),
230
- chalk.grey(data?.title || ''),
236
+ chalk.yellow(`Warning: ${data?.title || ''} (${err.response?.status})`),
237
+ `Report couldn't be processed: ${err?.response?.data?.message}`,
231
238
  );
232
- if (err.response.data.message.includes('could not be matched')) {
233
- this.hasUnmatchedTests = true;
234
- }
235
- return;
239
+ } else {
240
+ console.log(APP_PREFIX, chalk.blue(data?.title || ''), "Report couldn't be processed", err);
236
241
  }
237
- console.log(
238
- APP_PREFIX,
239
- chalk.yellow(`Warning: ${data?.title || ''} (${err.response?.status})`),
240
- `Report couldn't be processed: ${err?.response?.data?.message}`,
241
- );
242
- } else {
243
- console.log(APP_PREFIX, chalk.blue(data?.title || ''), "Report couldn't be processed", err);
244
- }
245
- });
242
+ });
246
243
  }
247
244
 
248
245
  /**
package/lib/xmlReader.js CHANGED
@@ -15,7 +15,7 @@ const {
15
15
  const upload = require('./fileUploader');
16
16
  const pipesFactory = require('./pipe');
17
17
  const adapterFactory = require('./junit-adapter');
18
- const { TESTOMATIO } = require('./config');
18
+ const config = require('./config');
19
19
 
20
20
  const TESTOMATIO_URL = process.env.TESTOMATIO_URL || 'https://app.testomat.io';
21
21
  const { TESTOMATIO_RUNGROUP_TITLE, TESTOMATIO_TITLE, TESTOMATIO_ENV, TESTOMATIO_RUN } = process.env;
@@ -33,7 +33,7 @@ const reduceOptions = {};
33
33
  class XmlReader {
34
34
  constructor(opts = {}) {
35
35
  this.requestParams = {
36
- apiKey: opts.apiKey || TESTOMATIO,
36
+ apiKey: opts.apiKey || config.TESTOMATIO,
37
37
  url: opts.url || TESTOMATIO_URL,
38
38
  title: TESTOMATIO_TITLE,
39
39
  env: TESTOMATIO_ENV,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "1.1.2-beta-fix-config",
3
+ "version": "1.1.2-beta-fix-config-3",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "typings": "typings/index.d.ts",