@testomatio/reporter 1.0.12-beta.3 → 1.0.12-beta.4

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/lib/util.js CHANGED
@@ -104,6 +104,22 @@ const fetchSourceCodeFromStackTrace = (stack = '') => {
104
104
  }).join('\n');
105
105
  };
106
106
 
107
+ const TEST_ID_REGEX = /@T([\w\d]{8})/;
108
+
109
+ const fetchIdFromCode = (code, opts = {}) => {
110
+ const comments = code.split('\n').map(l => l.trim()).filter(l => {
111
+ switch (opts.lang) {
112
+ case 'ruby':
113
+ case 'python':
114
+ return l.startsWith('# ');
115
+ default:
116
+ return l.startsWith('// ');
117
+ }
118
+ });
119
+
120
+ return comments.find(c => c.match(TEST_ID_REGEX))?.match(TEST_ID_REGEX)?.[1];
121
+ }
122
+
107
123
  const fetchSourceCode = (contents, opts = {}) => {
108
124
  if (!opts.title && !opts.line) return '';
109
125
 
@@ -251,6 +267,7 @@ module.exports = {
251
267
  isSameTest,
252
268
  fetchSourceCode,
253
269
  fetchSourceCodeFromStackTrace,
270
+ fetchIdFromCode,
254
271
  fetchFilesFromStackTrace,
255
272
  fileSystem,
256
273
  getCurrentDateTime,
package/lib/xmlReader.js CHANGED
@@ -4,7 +4,7 @@ const chalk = require('chalk');
4
4
  const fs = require("fs");
5
5
  const { XMLParser } = require("fast-xml-parser");
6
6
  const { APP_PREFIX, STATUS } = require('./constants');
7
- const { fetchFilesFromStackTrace, fetchSourceCode, fetchSourceCodeFromStackTrace } = require('./util');
7
+ const { fetchFilesFromStackTrace, fetchSourceCode, fetchSourceCodeFromStackTrace, fetchIdFromCode } = require('./util');
8
8
  const upload = require('./fileUploader');
9
9
  const pipesFactory = require('./pipe');
10
10
  const adapterFactory = require('./junit-adapter');
@@ -310,6 +310,9 @@ class XmlReader {
310
310
  }
311
311
  const contents = fs.readFileSync(file).toString();
312
312
  t.code = fetchSourceCode(contents, { ...t, lang: this.stats.language })
313
+ if (t.code) debug('Fetched code for test %s', t.title);
314
+ t.test_id = fetchIdFromCode(t.code, { lang: this.stats.language } )
315
+ if (t.test_id) debug('Fetched test id %s for test %s', t.test_id, t.title);
313
316
  } catch (err) {
314
317
  debug(err)
315
318
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "1.0.12-beta.3",
3
+ "version": "1.0.12-beta.4",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "typings": "typings/index.d.ts",