@testomatio/reporter 0.3.12 → 0.3.16

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,28 @@
1
+ # 0.3.16
2
+
3
+ * CodeceptJS: fixed reporting tests with empty steps (on retry)
4
+
5
+ # 0.3.15
6
+
7
+ * Finish Run via API:
8
+
9
+ ```
10
+ TESTOMATIO={apiKey} TESTOMATIO_RUN={runId} npx @testomatio/reporter@latest --finish
11
+ ```
12
+
13
+ # 0.3.14
14
+
15
+ * Create an empty Run via API:
16
+
17
+ ```
18
+ TESTOMATIO={apiKey} npx @testomatio/reporter@latest --launch
19
+ ```
20
+
21
+ # 0.3.13
22
+
23
+ * Checking for a valid report URL
24
+ * Sending unlimited data on test report
25
+
1
26
  # 0.3.12
2
27
 
3
28
  * Fixed submitting arbitrary data on a test run
package/README.md CHANGED
@@ -169,3 +169,25 @@ To save screenshots provide a configuration for S3 bucket via environment variab
169
169
  For local testing, it is recommended to store this configuration in `.env` file and load it with [dotenv](https://www.npmjs.com/package/dotenv) library.
170
170
 
171
171
  On CI set environment variables in CI config.
172
+
173
+
174
+ ## Starting an Empty Run
175
+
176
+ If you want to create a run and obtain its RunID from Testomat.io you can use `--launch` option:
177
+
178
+ ```sh
179
+ TESTOMATIO={apiKey} npx @testomatio/reporter@latest --launch
180
+ ```
181
+
182
+ This command will return RunID which you can pass to other testrunner processes.
183
+
184
+ > When executed with `--launch` a command provided by `-c` flag is ignored
185
+
186
+ ## Manually Finishing Run
187
+
188
+ If you want to finish a run started by `--launch` use `--finish` option. `TESTOMATIO_RUN` environment variable is required:
189
+
190
+ ```sh
191
+ TESTOMATIO={apiKey} TESTOMATIO_RUN={runId} npx @testomatio/reporter@latest --finish
192
+ ```
193
+
@@ -112,7 +112,7 @@ module.exports = (config) => {
112
112
  failedTests.push(id || title);
113
113
  const testId = parseTest(tags);
114
114
  const testObj = getTestAndMessage(title);
115
- if (err && err.stack && test.steps.length) {
115
+ if (err && err.stack && test.steps && test.steps.length) {
116
116
  err.stack = test.steps[test.steps.length - 1].line();
117
117
  }
118
118
 
@@ -3,13 +3,46 @@ const { spawn } = require("child_process");
3
3
  const program = require("commander");
4
4
  const chalk = require("chalk");
5
5
  const TestomatClient = require("../client");
6
- const { APP_PREFIX } = require("../constants");
6
+ const { APP_PREFIX, FINISHED } = require("../constants");
7
7
 
8
8
  const apiKey = process.env["INPUT_TESTOMATIO-KEY"] || process.env.TESTOMATIO;
9
9
  const title = process.env.TESTOMATIO_TITLE;
10
10
 
11
- program.option("-c, --command <cmd>", "Test command").action((opts) => {
12
- const { command } = opts;
11
+ program
12
+ .option("-c, --command <cmd>", "Test runner command")
13
+ .option('--launch', 'Start a new run and return its ID')
14
+ .option('--finish', 'Finish Run by its ID')
15
+ .action((opts) => {
16
+ const { command, launch, finish } = opts;
17
+
18
+ if (launch) {
19
+ console.log('Starting a new Run on Testomat.io...');
20
+ const client = new TestomatClient({ apiKey });
21
+
22
+ client.createRun().then(() => {
23
+ console.log(process.env.runId);
24
+ process.exit(0);
25
+ })
26
+ return;
27
+ }
28
+
29
+ if (finish) {
30
+ if (!process.env.TESTOMATIO_RUN) {
31
+ console.log('TESTOMATIO_RUN environment variable must be set.');
32
+ return process.exit(1);
33
+ }
34
+
35
+ console.log('Finishing Run on Testomat.io...');
36
+
37
+ const client = new TestomatClient({ apiKey });
38
+
39
+ client.updateRunStatus(FINISHED, true).then(() => {
40
+ console.log(chalk.yellow(`Run ${process.env.TESTOMATIO_RUN} was finished`));
41
+ process.exit(0);
42
+ });
43
+ return;
44
+ }
45
+
13
46
  const testCmds = command.split(" ");
14
47
  console.log(APP_PREFIX, `🚀 Running`, chalk.green(command));
15
48
 
package/lib/client.js CHANGED
@@ -1,16 +1,16 @@
1
- const axios = require("axios").default;
1
+ const axios = require("axios");
2
2
  const JsonCycle = require("json-cycle");
3
+ const { URL } = require("url");
3
4
  const createCallsiteRecord = require("callsite-record");
4
- // const defaultRenderer = require("callsite-record").renderers.noColor;
5
+
5
6
  const { sep } = require("path");
6
7
  const chalk = require("chalk");
7
8
  const { uploadFile } = require("./fileUploader");
8
- const { PASSED, FAILED, APP_PREFIX } = require("./constants");
9
+ const { PASSED, FAILED, FINISHED, APP_PREFIX } = require("./constants");
9
10
 
10
11
  const TESTOMAT_URL = process.env.TESTOMATIO_URL || "https://app.testomat.io";
11
- const { TESTOMATIO_RUNGROUP_TITLE } = process.env;
12
- const { TESTOMATIO_ENV } = process.env;
13
- const { TESTOMATIO_RUN } = process.env;
12
+ const { TESTOMATIO_RUNGROUP_TITLE, TESTOMATIO_ENV, TESTOMATIO_RUN } = process.env;
13
+
14
14
 
15
15
  if (TESTOMATIO_RUN) {
16
16
  process.env.runId = TESTOMATIO_RUN;
@@ -28,6 +28,7 @@ class TestomatClient {
28
28
  this.parallel = params.parallel;
29
29
  this.runId = process.env.runId;
30
30
  this.queue = Promise.resolve();
31
+ this.axios = axios.create();
31
32
  }
32
33
 
33
34
  /**
@@ -37,6 +38,7 @@ class TestomatClient {
37
38
  */
38
39
  createRun() {
39
40
  const { runId } = process.env;
41
+ if (!this.apiKey) throw new Error('No API key is set, can\'t create run');
40
42
  const runParams = {
41
43
  api_key: this.apiKey.trim(),
42
44
  title: this.title,
@@ -44,6 +46,14 @@ class TestomatClient {
44
46
  group_title: TESTOMATIO_RUNGROUP_TITLE,
45
47
  env: TESTOMATIO_ENV,
46
48
  };
49
+ if (!isValidUrl(TESTOMAT_URL.trim())) {
50
+ console.log(
51
+ APP_PREFIX,
52
+ chalk.red(`Error creating report on Testomat.io, report url '${TESTOMAT_URL}' is invalid`)
53
+ );
54
+ return;
55
+ }
56
+
47
57
  if (runId) {
48
58
  this.runId = runId;
49
59
  this.queue = this.queue.then(() =>
@@ -53,7 +63,7 @@ class TestomatClient {
53
63
 
54
64
  this.queue = this.queue
55
65
  .then(() =>
56
- axios
66
+ this.axios
57
67
  .post(`${TESTOMAT_URL.trim()}/api/reporter`, runParams)
58
68
  .then((resp) => {
59
69
  this.runId = resp.data.uid;
@@ -71,7 +81,7 @@ class TestomatClient {
71
81
  .catch(() => {
72
82
  console.log(
73
83
  APP_PREFIX,
74
- "Error creating a test run on testomat.io, please check if your API key is valid. Skipping report"
84
+ "Error creating report Testomat.io, please check if your API key is valid. Skipping report"
75
85
  );
76
86
  });
77
87
 
@@ -171,10 +181,12 @@ class TestomatClient {
171
181
  run_time: time,
172
182
  artifacts: await Promise.all(uploadedFiles),
173
183
  });
174
- return axios.post(
184
+ return this.axios.post(
175
185
  `${TESTOMAT_URL}/api/reporter/${this.runId}/testrun`,
176
186
  json,
177
187
  {
188
+ maxContentLength: Infinity,
189
+ maxBodyLength: Infinity,
178
190
  headers: {
179
191
  // Overwrite Axios's automatically set Content-Type
180
192
  "Content-Type": "application/json",
@@ -216,10 +228,11 @@ class TestomatClient {
216
228
  .then(async () => {
217
229
  if (this.runId) {
218
230
  let statusEvent;
231
+ if (status === FINISHED) statusEvent = "finish";
219
232
  if (status === PASSED) statusEvent = "pass";
220
233
  if (status === FAILED) statusEvent = "fail";
221
234
  if (isParallel) statusEvent += "_parallel";
222
- await axios.put(`${TESTOMAT_URL}/api/reporter/${this.runId}`, {
235
+ await this.axios.put(`${TESTOMAT_URL}/api/reporter/${this.runId}`, {
223
236
  api_key: this.apiKey,
224
237
  status_event: statusEvent,
225
238
  status,
@@ -241,3 +254,12 @@ class TestomatClient {
241
254
  }
242
255
 
243
256
  module.exports = TestomatClient;
257
+
258
+ function isValidUrl(s) {
259
+ try {
260
+ new URL(s); // eslint-disable-line
261
+ return true;
262
+ } catch (err) {
263
+ return false;
264
+ }
265
+ }
package/lib/constants.js CHANGED
@@ -6,5 +6,6 @@ module.exports = Object.freeze({
6
6
  PASSED: "passed",
7
7
  FAILED: "failed",
8
8
  SKIPPED: "skipped",
9
+ FINISHED: "finished",
9
10
  APP_PREFIX,
10
11
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testomatio/reporter",
3
- "version": "0.3.12",
3
+ "version": "0.3.16",
4
4
  "description": "Testomatio Reporter Client",
5
5
  "main": "./lib/reporter.js",
6
6
  "repository": "git@github.com:testomatio/reporter.git",