@testomatio/reporter 1.2.0-beta → 1.2.1-beta

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.
@@ -12,6 +12,7 @@ class JestReporter {
12
12
  }
13
13
 
14
14
  static getIdOfCurrentlyRunningTest() {
15
+ if (!process.env.JEST_WORKER_ID) return null;
15
16
  // @ts-expect-error "expect" could only be defined inside Jest environement (forbidden to import it outside)
16
17
  return parseTest(expect?.getState()?.currentTestName) || null; // eslint-disable-line
17
18
  }
package/lib/client.js CHANGED
@@ -12,7 +12,7 @@ const logger = require('./logger');
12
12
  /**
13
13
  * @typedef {import('../types').TestData} TestData
14
14
  * @typedef {import('../types').RunStatus} RunStatus
15
- * @typedef {import('../types').PipeResult} PipeResult
15
+ * @typedef {import('../types').PipeResult} PipeResult
16
16
  */
17
17
 
18
18
  class Client {
@@ -105,6 +105,7 @@ class Client {
105
105
 
106
106
  const testLogs = logger.getLogs(test_id);
107
107
  debug(`Test logs for ${test_id}:\n`, testLogs);
108
+ if (stack) stack += '\n\n';
108
109
  stack += testLogs;
109
110
 
110
111
  if (Array.isArray(storeArtifacts) && storeArtifacts.length) {
@@ -29,8 +29,8 @@ class DataStorage {
29
29
  Thus, checking environment is only reasonable when you put data to starage
30
30
  and potentially useless when get data from storage
31
31
  */
32
- const runningEnvironment = this.getRunningEnviroment();
33
- if (runningEnvironment === 'jest') this.isFileStorage = true;
32
+ this.runningEnvironment = this.getRunningEnviroment();
33
+ if (this.runningEnvironment === 'jest') this.isFileStorage = true;
34
34
 
35
35
  if (this.isFileStorage) {
36
36
  this.dataDirPath = path.join(TESTOMAT_TMP_STORAGE.mainDir, this.dataDirName);
@@ -52,8 +52,12 @@ class DataStorage {
52
52
  */
53
53
  getRunningEnviroment() {
54
54
  if (process.env.JEST_WORKER_ID) return 'jest';
55
- // @ts-expect-error mocha could be undefined, its ok
56
- if (typeof mocha !== 'undefined') return 'mocha';
55
+ try {
56
+ // @ts-expect-error mocha is defined only in mocha environment
57
+ if (typeof mocha !== 'undefined') return 'mocha';
58
+ } catch (e) {
59
+ // ignore
60
+ }
57
61
  return undefined;
58
62
  }
59
63
 
@@ -64,6 +68,8 @@ class DataStorage {
64
68
  * @returns
65
69
  */
66
70
  putData(data, context = null) {
71
+ // this.isFileStorage = !global.testomatioDataStore;
72
+
67
73
  let testId = null;
68
74
  if (typeof context === 'string') {
69
75
  testId = context;
@@ -73,7 +79,7 @@ class DataStorage {
73
79
  }
74
80
 
75
81
  // try to get testId for Jest
76
- testId = testId ?? JestReporter.getIdOfCurrentlyRunningTest();
82
+ if (this.runningEnvironment === 'jest') testId = testId ?? JestReporter.getIdOfCurrentlyRunningTest();
77
83
 
78
84
  // if testId is not provided, data is be saved to `{dataType}_other` file;
79
85
  if (!testId) testId = 'other';
@@ -101,7 +107,9 @@ class DataStorage {
101
107
  // testId = context...
102
108
  }
103
109
 
104
- if (!testId) testId = 'other';
110
+ if (!testId) {
111
+ debug(`Cannot get test id from passed context:\n}`, context);
112
+ }
105
113
 
106
114
  if (this.isFileStorage) {
107
115
  return this._getDataFromFile(testId);
package/lib/logger.js CHANGED
@@ -42,26 +42,6 @@ class Logger {
42
42
  }
43
43
  }
44
44
 
45
- /**
46
- * Returns the string (logs) and the context
47
- * This is required because loggers take multiple arguments
48
- * @param {...any} args
49
- */
50
- /*
51
- TODO: its difficult to distinguish context from log artument if its not a string,
52
- e.g. user can use something like console.log('some log', { key: 'value' });
53
- consider not to use this method at all and don't expect context from user inside default log methods;
54
- instead, use custom method like $`some log` and parse it
55
- */
56
- // _getLogStringAndContextFromArgs(...args) {
57
- // let context = '';
58
- // if (args.length > 1 && typeof args[args.length - 1] !== 'string') {
59
- // context = args.pop();
60
- // }
61
- // const logs = args.join(' ');
62
- // return { logs, context };
63
- // }
64
-
65
45
  /**
66
46
  * Tagget template literal. Allows to use different syntaxes:
67
47
  * 1. Tagget template: $`text ${someVar}`
@@ -293,9 +273,6 @@ Logger.instance = null;
293
273
  // module.exports.Logger = Logger;
294
274
  module.exports = new Logger();
295
275
 
296
- // TODO: consider using fs promises instead of writeSync/appendFileSync to prevent blocking and improve performance
297
276
  // TODO: parse passed arguments as {level: 'str', message: 'str'} because some loggers use such syntax;
298
277
  // upd: did not face such loggers, but still could be useful
299
278
 
300
- // TODO: in case of unset _originalUserLogger, logger.{method} will not provide console output,
301
- // need to add some logger by default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "1.2.0-beta",
3
+ "version": "1.2.1-beta",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "typings": "typings/index.d.ts",