@testomatio/reporter 1.0.12-beta.1 → 1.0.12-beta.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.
@@ -23,6 +23,7 @@ program
23
23
  }
24
24
  let { javaTests, lang } = opts;
25
25
  if (opts.envFile) {
26
+ console.log(APP_PREFIX, 'Loading env file:', opts.envFile);
26
27
  debug('Loading env file: %s', opts.envFile)
27
28
  require('dotenv').config({ path: opts.envFile }); // eslint-disable-line
28
29
  }
package/lib/util.js CHANGED
@@ -55,11 +55,21 @@ const isValidUrl = s => {
55
55
  }
56
56
  };
57
57
 
58
+ const fileMatchRegex = /file:(\/\/?[^:\s]+?\.(png|avi|webm|jpg|html|txt))/ig;
59
+
58
60
  const fetchFilesFromStackTrace = (stack = '') => {
59
- const files = stack.matchAll(/file:?\/(\/?[^:\s]+?\.(png|avi|webm|jpg|html|txt))/ig);
60
- return Array.from(files)
61
- .map(f => f[1])
62
- .filter(f => fs.existsSync(f));
61
+
62
+ const files = Array.from(stack.matchAll(fileMatchRegex))
63
+ .map(f => f[1].trim())
64
+ .map(f => f.startsWith('//') ? f.substring(1) : f )
65
+
66
+ debug('Found files in stack trace: ', files);
67
+
68
+ return files.filter(f => {
69
+ const isFile = fs.existsSync(f);
70
+ if (!isFile) debug('File %s could not be found and uploaded as artifact', f);
71
+ return isFile;
72
+ });
63
73
  };
64
74
 
65
75
  const fetchSourceCodeFromStackTrace = (stack = '') => {
package/lib/xmlReader.js CHANGED
@@ -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
- const store = {}
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 = []
@@ -304,6 +304,10 @@ class XmlReader {
304
304
  if (file.endsWith('.ts')) this.stats.language = 'ts';
305
305
  }
306
306
 
307
+ if (!fs.existsSync(file)) {
308
+ debug('Failed to open file with the source code', file)
309
+ return;
310
+ }
307
311
  const contents = fs.readFileSync(file).toString();
308
312
  t.code = fetchSourceCode(contents, { ...t, lang: this.stats.language })
309
313
  } catch (err) {
@@ -349,8 +353,12 @@ class XmlReader {
349
353
  let files = [];
350
354
  if (test.files?.length) files = test.files.map(f => path.join(process.cwd(), f))
351
355
  files = [...files, ...fetchFilesFromStackTrace(test.stack)];
352
- debug('Uploading files', files)
353
- test.artifacts = await Promise.all(files.map(f => upload.uploadFileByPath(f, this.runId)));
356
+
357
+ if (!files.length) continue;
358
+
359
+ const runId = this.runId || this.store.runId || Date.now().toString();
360
+ test.artifacts = await Promise.all(files.map(f => upload.uploadFileByPath(f, runId)));
361
+ console.log(APP_PREFIX, `🗄️ Uploaded ${chalk.bold(`${files.length} artifacts`)} for test ${test.title}`);
354
362
  }
355
363
  }
356
364
 
@@ -360,8 +368,8 @@ class XmlReader {
360
368
  title: this.requestParams.title,
361
369
  env: this.requestParams.env,
362
370
  group_title: this.requestParams.group_title,
363
- };
364
-
371
+ };
372
+
365
373
  debug("Run", runParams);
366
374
 
367
375
  return Promise.all(this.pipes.map(p => p.createRun(runParams)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "1.0.12-beta.1",
3
+ "version": "1.0.12-beta.3",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "typings": "typings/index.d.ts",