@testomatio/reporter 0.4.4 → 0.4.5

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/Changelog.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.4.5
2
+
3
+ * Fixed "Total XX artifacts publicly uploaded to S3 bucket" when no S3 bucket is configured
4
+ * Improved S3 connection error messages
5
+
1
6
  # 0.4.4
2
7
 
3
8
  * Fixed returning 0 exit code when a process fails when running tests in parallel via `start-test-run`. Previously was using the last exit code returned by a process. Currently prefers the highest exit code that was returned by a process.
@@ -7,6 +7,7 @@ const chalk = require("chalk");
7
7
  const TestomatClient = require("../client");
8
8
  const { FAILED } = require("../constants");
9
9
  const TRConstants = require("../constants");
10
+ const upload = require("../fileUploader");
10
11
  const Output = require("../output");
11
12
 
12
13
  let currentMetaStep = [];
@@ -87,7 +88,7 @@ module.exports = (config) => {
87
88
  });
88
89
 
89
90
  event.dispatcher.on(event.all.result, async () => {
90
- if (videos.length) {
91
+ if (videos.length && upload.isEnabled()) {
91
92
  console.log(TRConstants.APP_PREFIX, `🎞️ Uploading ${videos.length} videos...`);
92
93
 
93
94
  let promises = [];
@@ -5,6 +5,7 @@ const path = require('path');
5
5
  const fs = require('fs');
6
6
  const Status = require('../constants');
7
7
  const TestomatioClient = require("../client");
8
+ const upload = require("../fileUploader");
8
9
  const { parseTest } = require('../util');
9
10
 
10
11
  class TestomatioReporter {
@@ -75,7 +76,7 @@ class TestomatioReporter {
75
76
  async onEnd(result) {
76
77
  if (!this.client) return;
77
78
 
78
- if (this.videos.length) {
79
+ if (this.videos.length && upload.isEnabled()) {
79
80
  console.log(Status.APP_PREFIX, `🎞️ Uploading ${this.videos.length} videos...`);
80
81
 
81
82
  let promises = [];
package/lib/client.js CHANGED
@@ -5,7 +5,7 @@ const createCallsiteRecord = require("callsite-record");
5
5
  const { sep, join } = require("path");
6
6
  const fs = require("fs");
7
7
  const chalk = require("chalk");
8
- const { isPrivate, uploadFile } = require("./fileUploader");
8
+ const upload = require("./fileUploader");
9
9
  const { PASSED, FAILED, FINISHED, APP_PREFIX } = require("./constants");
10
10
 
11
11
  const TESTOMAT_URL = process.env.TESTOMATIO_URL || "https://app.testomat.io";
@@ -137,7 +137,7 @@ class TestomatClient {
137
137
  }
138
138
 
139
139
  for (const file of files) {
140
- uploadedFiles.push(uploadFile(file, this.runId));
140
+ uploadedFiles.push(upload.uploadFile(file, this.runId));
141
141
  }
142
142
  }
143
143
 
@@ -233,11 +233,11 @@ class TestomatClient {
233
233
  );
234
234
  }
235
235
 
236
- if (this.totalUploaded > 0) {
236
+ if (upload.isEnabled() && this.totalUploaded > 0) {
237
237
  console.log(
238
238
  APP_PREFIX,
239
239
  `🗄️ Total ${this.totalUploaded} artifacts ${
240
- isPrivate ? "privately" : chalk.bold("publicly")
240
+ upload.isPrivate ? "privately" : chalk.bold("publicly")
241
241
  } uploaded to S3 bucket `
242
242
  );
243
243
  }
@@ -2,9 +2,14 @@ const AWS = require("aws-sdk");
2
2
  const fs = require("fs");
3
3
  const path = require("path");
4
4
  const chalk = require("chalk");
5
+ const { APP_PREFIX } = require("./constants");
5
6
 
6
7
  const isPrivate = process.env.TESTOMATIO_PRIVATE_ARTIFACTS;
7
8
 
9
+ function isEnabled() {
10
+ return process.env.S3_BUCKET && !process.env.TESTOMATIO_DISABLE_ARTIFACTS;
11
+ }
12
+
8
13
  const uploadUsingS3 = async (filePath, runId) => {
9
14
  const region = process.env.S3_REGION;
10
15
  const bucket = process.env.S3_BUCKET;
@@ -32,22 +37,43 @@ const uploadUsingS3 = async (filePath, runId) => {
32
37
  const file = fs.readFileSync(filePath);
33
38
 
34
39
  fileName = `${runId}/${fileName || path.basename(filePath)}`;
40
+ const acl = isPrivate ? "private" : "public-read"
35
41
 
36
- const out = await s3
37
- .upload({
38
- Bucket: bucket,
39
- Key: fileName,
40
- Body: file,
41
- ContentType: contentType,
42
- ACL: isPrivate ? "private" : "public-read",
42
+ try {
43
+ const out = await s3
44
+ .upload({
45
+ Bucket: bucket,
46
+ Key: fileName,
47
+ Body: file,
48
+ ContentType: contentType,
49
+ ACL: acl,
50
+ })
51
+ .promise();
52
+ return out.Location;
53
+ } catch (e) {
54
+ console.log(APP_PREFIX, chalk.bold.red(`Failed uploading '${fileName}'. Please check S3 credentials`), {
55
+ accessKeyId,
56
+ secretAccessKey: secretAccessKey ? '**** (hidden) ***' : '(empty)',
57
+ region,
58
+ bucket,
59
+ acl,
60
+ endpoint: process.env.S3_ENDPOINT
43
61
  })
44
- .promise();
45
- return out.Location;
62
+
63
+ console.log(APP_PREFIX, `To ${chalk.bold('disable')} artifact uploads set: TESTOMATIO_DISABLE_ARTIFACTS=1`)
64
+ if (!isPrivate) {
65
+ console.log(APP_PREFIX, `To enable ${chalk.bold('PRIVATE')} uploads set: TESTOMATIO_PRIVATE_ARTIFACTS=1`)
66
+ } else {
67
+ console.log(APP_PREFIX, `To enable ${chalk.bold('PUBLIC')} uploads remove TESTOMATIO_PRIVATE_ARTIFACTS env variable`)
68
+ }
69
+ console.log(APP_PREFIX, '---------------')
70
+ return null;
71
+ }
46
72
  };
47
73
 
48
74
  const uploadFile = async (filePath, runId) => {
49
75
  try {
50
- if (process.env.S3_BUCKET) {
76
+ if (isEnabled()) {
51
77
  return uploadUsingS3(filePath, runId);
52
78
  }
53
79
  } catch (e) {
@@ -59,4 +85,5 @@ const uploadFile = async (filePath, runId) => {
59
85
  module.exports = {
60
86
  uploadFile,
61
87
  isPrivate,
88
+ isEnabled,
62
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "repository": "git@github.com:testomatio/reporter.git",