@testomatio/reporter 1.0.12-beta.2 → 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 +17 -0
- package/lib/xmlReader.js +12 -5
- package/package.json +1 -1
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');
|
|
@@ -39,8 +39,8 @@ class XmlReader {
|
|
|
39
39
|
if (!this.adapter) throw new Error('XML adapter for this format not found');
|
|
40
40
|
|
|
41
41
|
this.opts = opts || {};
|
|
42
|
-
|
|
43
|
-
this.pipes = pipesFactory(opts, store);
|
|
42
|
+
this.store = {}
|
|
43
|
+
this.pipes = pipesFactory(opts, this.store);
|
|
44
44
|
|
|
45
45
|
this.parser = new XMLParser(options);
|
|
46
46
|
this.tests = []
|
|
@@ -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
|
}
|
|
@@ -353,8 +356,12 @@ class XmlReader {
|
|
|
353
356
|
let files = [];
|
|
354
357
|
if (test.files?.length) files = test.files.map(f => path.join(process.cwd(), f))
|
|
355
358
|
files = [...files, ...fetchFilesFromStackTrace(test.stack)];
|
|
356
|
-
|
|
357
|
-
|
|
359
|
+
|
|
360
|
+
if (!files.length) continue;
|
|
361
|
+
|
|
362
|
+
const runId = this.runId || this.store.runId || Date.now().toString();
|
|
363
|
+
test.artifacts = await Promise.all(files.map(f => upload.uploadFileByPath(f, runId)));
|
|
364
|
+
console.log(APP_PREFIX, `🗄️ Uploaded ${chalk.bold(`${files.length} artifacts`)} for test ${test.title}`);
|
|
358
365
|
}
|
|
359
366
|
}
|
|
360
367
|
|