@testomatio/reporter 0.8.0-beta.3 → 0.8.0-beta.31

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,15 @@
1
+ # 0.7.6
2
+
3
+ * Updated to use AWS S3 3.0 SDK for uploading
4
+
5
+ # 0.7.5
6
+
7
+ * Fixed reporting skipped tests in mocha
8
+
9
+ # 0.7.4
10
+
11
+ * Fixed parsing source code in JUnit files
12
+
1
13
  # 0.7.3
2
14
 
3
15
  * CodeceptJS: Upload all traces and videos from artifacts
package/README.md CHANGED
@@ -20,11 +20,24 @@ For testcafe use testcafe reporter:
20
20
  npm i testcafe-reporter-testomatio
21
21
  ```
22
22
 
23
+ For newman use:
24
+
25
+ ```bash
26
+ npm i newman-reporter-testomatio --save-dev
27
+ ```
28
+
29
+ >`newman` and `newman-reporter-testomatio` should be installed in the same directory.
30
+ \
31
+ If you run your tests using globally installed newman (`newman run ...`), intall `newman-reporter-testomatio` globally too (`npm i newman-reporter-testomatio -g`).
32
+ \
33
+ If you use locally installed newman (within the project) (`npx newman run ...`), install `newman-reporter-testomatio` locally (`npm i newman-reporter-testomatio`).
34
+ You can verify installed packages via `npm list` or `npm list -g`.
35
+
23
36
  ## Usage
24
37
 
25
38
  ### CodeceptJS
26
39
 
27
- Make sure you load all your tests using [check-test](https://github.com/testomatio/check-tests#cli).
40
+ Make sure you load all your tests using [check-tests](https://github.com/testomatio/check-tests#cli).
28
41
 
29
42
  Add plugin to [codecept conf](https://github.com/testomatio/reporter/blob/master/example/codecept/codecept.conf.js#L23):
30
43
 
@@ -81,7 +94,7 @@ TESTOMATIO={API_KEY} npx playwright test
81
94
 
82
95
  ### Mocha
83
96
 
84
- Load the test using using `check-test` if not done already. Get the test id from testomat account and add it to your mocha test like in this [example](https://github.com/testomatio/reporter/blob/master/example/mocha/test/index.test.js#L4).
97
+ Load the test using using `check-tests` if not done already. Get the test id from testomat account and add it to your mocha test like in this [example](https://github.com/testomatio/reporter/blob/master/example/mocha/test/index.test.js#L4).
85
98
 
86
99
  Run the following command from you project folder:
87
100
 
@@ -91,7 +104,7 @@ mocha --reporter ./node_modules/testomat-reporter/lib/adapter/mocha.js --reporte
91
104
 
92
105
  ### Jest
93
106
 
94
- Load the test using using `check-test`. Add the test id to your tests like in this [example](https://github.com/testomatio/reporter/blob/master/example/jest/index.test.js#L1).
107
+ Load the test using using `check-tests`. Add the test id to your tests like in this [example](https://github.com/testomatio/reporter/blob/master/example/jest/index.test.js#L1).
95
108
 
96
109
  Add the following line to [jest.config.js](https://github.com/testomatio/reporter/blob/master/example/jest/jest.config.js#L100):
97
110
 
@@ -113,7 +126,7 @@ TESTOMATIO={API_KEY} ./node_modules/.bin/cucumber-js --format ./node_modules/@te
113
126
 
114
127
  ### TestCafe
115
128
 
116
- Load the test using using `check-test`.
129
+ Load the test using using `check-tests`.
117
130
 
118
131
  Run the following command from you project folder:
119
132
 
@@ -121,9 +134,20 @@ Run the following command from you project folder:
121
134
  TESTOMATIO={API_KEY} npx testcafe chrome -r testomatio
122
135
  ```
123
136
 
137
+ ### Newman (Postman)
138
+
139
+ Run collection and specify `testomatio` as reporter:
140
+
141
+ ```bash
142
+ TESTOMATIO={API_KEY} npx newman run {collection_name.json} -r testomatio
143
+ ```
144
+
145
+ > _`check-tests` not supported for newman for now, tests will be created on testomatio by default_
146
+
147
+
124
148
  ### Cypress
125
149
 
126
- Load the test using using `check-test`.
150
+ Load the test using using `check-tests`.
127
151
 
128
152
  Register our `cypress-plugin` in `cypress/plugins/index.js`:
129
153
 
@@ -151,7 +175,7 @@ TESTOMATIO={API_KEY} npx cypress run
151
175
 
152
176
  ### Protractor
153
177
 
154
- Load the test using using `check-test`.
178
+ Load the test using using `check-tests`.
155
179
 
156
180
  Add the following lines to [conf.js](https://github.com/angular/protractor/blob/5.4.1/example/conf.js):
157
181
 
@@ -173,7 +197,7 @@ TESTOMATIO={API_KEY} npx start-test-run -c 'npx protractor conf.js'
173
197
 
174
198
  ### WebdriverIO
175
199
 
176
- Load the test using using `check-test`.
200
+ Load the test using using `check-tests`.
177
201
 
178
202
  Add the following lines to [wdio.conf.js](https://webdriver.io/docs/configurationfile/):
179
203
 
@@ -208,6 +232,30 @@ Run the following command from you project folder:
208
232
  TESTOMATIO={API_KEY} npx start-test-run -c 'npx wdio wdio.conf.js'
209
233
  ```
210
234
 
235
+ ## Pipes
236
+ Pipes allow you to get report inside different systems (e.g. Pull request comment, database etc)
237
+ For now next pipes available:
238
+
239
+ ### GitHub
240
+ This pipe adds comment with run report to GitHub Pull Request.
241
+
242
+ To use it:
243
+ 1. run your tests using github actions in Pull Request
244
+ 2. pass `GH_PAT` (GitHub Personal Access Token) as environment variable.
245
+
246
+ > Last report (comment) will be replaced with the new one.
247
+ To leave previous report pass `GITHUB_KEEP_OUTDATED_REPORTS=1` env variable.
248
+
249
+ ### GitLab
250
+ This pipe adds comment with run report to GitLab Merge Request.
251
+
252
+ To use it:
253
+ 1. run your tests in Merge Request (pipeline trigger should be `merge_request`)
254
+ 2. pass `GITLAB_PAT` (GitLab Personal Access Token) as environment variable.
255
+
256
+ > Last report (comment) will be replaced with the new one.
257
+ To leave previous report pass `GITLAB_KEEP_OUTDATED_REPORTS=1` env variable.
258
+
211
259
  ## JUnit Reports
212
260
 
213
261
  > **Notice** JUnit reports are supported since 0.6.0
@@ -408,6 +456,23 @@ Add environments to run by providing `TESTOMATIO_ENV` as comma seperated values:
408
456
  TESTOMATIO={API_KEY} TESTOMATIO_ENV="Windows, Chrome" <actual run command>
409
457
  ```
410
458
 
459
+ ### Save test results to .csv file
460
+ Add an env to run by specifying the `TESTOMATIO_CSV_FILENAME` variable.
461
+
462
+ 1) using default report name:
463
+
464
+ ```bash
465
+ TESTOMATIO={API_KEY} TESTOMATIO_CSV_FILENAME="report.csv" <actual run command>
466
+ ```
467
+
468
+ 2) using unique report name:
469
+
470
+ ```bash
471
+ TESTOMATIO={API_KEY} TESTOMATIO_CSV_FILENAME="test.csv" <actual run command>
472
+ ```
473
+ _It's create a new /export folder with csv files_
474
+
475
+
411
476
  ### Attaching Test Artifacts
412
477
 
413
478
  To save a test artifacts (screenshots and videos) of a failed test use S3 storage.
@@ -520,3 +585,8 @@ If you want to finish a run started by `--launch` use `--finish` option. `TESTOM
520
585
  ```bash
521
586
  TESTOMATIO={API_KEY} TESTOMATIO_RUN={RUN_ID} npx start-test-run --finish
522
587
  ```
588
+
589
+ ### Debug logs
590
+ Pass `DEBUG` variable with module name e.g. `DEBUG=@testomatio/reporter:pipe:github`.
591
+ (Module name could be taken directly from the required module code).
592
+ To log all debug info pass `DEBUG=*`.
@@ -0,0 +1,132 @@
1
+ const debug = require('debug')('@testomatio/reporter:storage');
2
+ const { join, resolve } = require('path');
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const uuid = require('uuid');
6
+
7
+ const { TESTOMAT_ARTIFACT_SUFFIX } = require('./constants');
8
+ const { specificTestInfo } = require('./util');
9
+
10
+ class ArtifactStorage {
11
+ _tmpPrefix = "tsmt_reporter";
12
+
13
+ constructor(params) {
14
+ this.isFile = false;
15
+ this.isMemory = true;
16
+ this.storage = params?.toFile;
17
+
18
+ if (this.storage) {
19
+ this.isFile = true;
20
+ this.isMemory = false;
21
+ this.tmpDirFullpath = this.createTestomatTmpDir(this._tmpPrefix);
22
+ debug('SAVE to tmp folder mode enabled!');
23
+ }
24
+ }
25
+
26
+ static async storeToFile(tmpDirName, artifact, testSuffix = "test") {
27
+ const suffix = TESTOMAT_ARTIFACT_SUFFIX + uuid.v4() + testSuffix;
28
+ const dirpath = join(os.tmpdir(), tmpDirName);
29
+ const filepath = resolve(dirpath, suffix + ".json");
30
+
31
+ return await fs.promises.appendFile(filepath, JSON.stringify(artifact));
32
+ }
33
+
34
+ static async artifact(artifact, context) {
35
+ //TODO: mode for different pre-hooks. As variant - "all-tests" || "only_fail"
36
+ // const mode = process.env.TESTOMAT_ARTIFACTS || "only_fail";
37
+
38
+ if (Array.isArray(global.testomatioArtifacts)) {
39
+ debug("Saving artifacts to global storage");
40
+
41
+ global.testomatioArtifacts.push(artifact);
42
+ }
43
+
44
+ if (global?.testomatioArtifacts === undefined) {
45
+ const tmpDirNames = ArtifactStorage.tmpTestomatDirNames();
46
+
47
+ const testSuffix = specificTestInfo(context.test);
48
+
49
+ if (Array.isArray(tmpDirNames) && tmpDirNames.length) {
50
+ debug("Saving artifacts to memory tmp folder");
51
+
52
+ return await ArtifactStorage.storeToFile(tmpDirNames[tmpDirNames.length - 1], artifact, testSuffix);
53
+ }
54
+ }
55
+ }
56
+
57
+ async artifactByTestName(test) {
58
+ const list = [];
59
+
60
+ if (this.isFile && this.tmpDirFullpath) {
61
+ const files = fs.readdirSync(this.tmpDirFullpath);
62
+
63
+ for (const file of files) {
64
+ if (file.includes(test)) {
65
+ const buff = await fs.promises.readFile(this.tmpDirFullpath + "/" + file);
66
+
67
+ list.push(JSON.parse(buff.toString()));
68
+ }
69
+ }
70
+ }
71
+
72
+ return list;
73
+ }
74
+
75
+ async tmpContents() {
76
+ const contents = [];
77
+
78
+ if (this.isFile && this.tmpDirFullpath) {
79
+ const files = fs.readdirSync(this.tmpDirFullpath);
80
+
81
+ for (const file of files) {
82
+ const buff = await fs.promises.readFile(this.tmpDirFullpath + "/" + file);
83
+ const content = buff.toString();
84
+
85
+ contents.push(content);
86
+ }
87
+ }
88
+
89
+ return contents;
90
+ }
91
+
92
+ createTestomatTmpDir(clientPrefix) {
93
+ return fs.mkdtempSync(join(os.tmpdir(), clientPrefix));
94
+ }
95
+
96
+ clearTmpDirByName(name) {
97
+ const tmpDirPath = join(os.tmpdir(), name);
98
+
99
+ if (fs.existsSync(tmpDirPath)) {
100
+ fs.rmSync(tmpDirPath, { recursive: true });
101
+ debug(` Testomat tmpDir = ${tmpDirPath} was deleted successfully!`);
102
+
103
+ return;
104
+ }
105
+ }
106
+
107
+ static tmpTestomatDirNames() {
108
+ const subname = this._tmpPrefix || "tsmt_reporter";
109
+
110
+ return fs.readdirSync(os.tmpdir(), { withFileTypes: true })
111
+ .filter((item) => item.isDirectory())
112
+ .map((item) => item.name)
113
+ .filter((name) => name.includes(subname));
114
+ }
115
+
116
+ cleanup() {
117
+ if (this.isFile && this.tmpDirFullpath) {
118
+ const tmpDirNames = ArtifactStorage.tmpTestomatDirNames();
119
+
120
+ if (Array.isArray(tmpDirNames) && tmpDirNames.length) {
121
+ for (const name of tmpDirNames) {
122
+ this.clearTmpDirByName(name);
123
+ }
124
+ }
125
+ }
126
+ else {
127
+ debug("The tmp folder has not been created! Nothing to delete");
128
+ }
129
+ }
130
+ }
131
+
132
+ module.exports = ArtifactStorage;
@@ -35,11 +35,6 @@ function CodeceptReporter(config) {
35
35
  const testTimeMap = {};
36
36
  const { apiKey } = config;
37
37
 
38
- if (!apiKey) {
39
- console.log('TESTOMATIO key is empty, ignoring reports');
40
- return;
41
- }
42
-
43
38
  const getDuration = test => {
44
39
  if (testTimeMap[test.id]) {
45
40
  return Date.now() - testTimeMap[test.id];
@@ -72,7 +67,7 @@ function CodeceptReporter(config) {
72
67
  });
73
68
 
74
69
  event.dispatcher.on(event.all.result, async () => {
75
- if (videos.length && upload.isArtifactsEnabled) {
70
+ if (videos.length && upload.isArtifactsEnabled()) {
76
71
  console.log(TRConstants.APP_PREFIX, `🎞️ Uploading ${videos.length} videos...`);
77
72
 
78
73
  const promises = [];
@@ -18,13 +18,7 @@ class CucumberReporter extends Formatter {
18
18
  this.failures = [];
19
19
  this.cases = [];
20
20
 
21
- const apiKey = process.env.TESTOMATIO;
22
- if (!apiKey || apiKey === '') {
23
- console.log(chalk.red('TESTOMATIO key is empty, ignoring reports'));
24
- return;
25
- }
26
-
27
- this.client = new TestomatClient({ apiKey });
21
+ this.client = new TestomatClient();
28
22
  this.status = TRConstants.PASSED;
29
23
 
30
24
  }
@@ -5,14 +5,7 @@ const { PASSED, FAILED } = require('../constants');
5
5
  class JasmineReporter {
6
6
  constructor(options) {
7
7
  this.testTimeMap = {};
8
- const { apiKey } = options;
9
-
10
- if (!apiKey) {
11
- console.log('TESTOMATIO key is empty, ignoring reports');
12
- return;
13
- }
14
-
15
- this.client = new TestomatClient({ apiKey });
8
+ this.client = new TestomatClient({ apiKey: options?.apiKey });
16
9
  this.client.createRun();
17
10
  }
18
11
 
@@ -6,14 +6,8 @@ class JestReporter {
6
6
  constructor(globalConfig, options) {
7
7
  this._globalConfig = globalConfig;
8
8
  this._options = options;
9
- const { apiKey } = options;
10
9
 
11
- if (!apiKey) {
12
- console.log('TESTOMATIO key is empty, ignoring reports');
13
- return;
14
- }
15
-
16
- this.client = new TestomatClient({ apiKey });
10
+ this.client = new TestomatClient({ apiKey: options?.apiKey });
17
11
  this.client.createRun();
18
12
  }
19
13
 
@@ -1,47 +1,97 @@
1
1
  // eslint-disable-next-line global-require, import/no-extraneous-dependencies
2
+ const debug = require('debug')('@testomatio/reporter:adapter:mocha');
2
3
  const Mocha = require('mocha');
4
+ const chalk = require('chalk');
3
5
  const TestomatClient = require('../client');
4
6
  const TRConstants = require('../constants');
5
- const { parseTest } = require('../util');
7
+ const { parseTest, specificTestInfo } = require('../util');
8
+ const ArtifactStorage = require('../ArtifactStorage');
6
9
 
7
- const { EVENT_RUN_BEGIN, EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS } = Mocha.Runner.constants;
10
+ const { EVENT_RUN_BEGIN, EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING } = Mocha.Runner.constants;
8
11
 
9
12
  function MochaReporter(runner, opts) {
10
13
  Mocha.reporters.Base.call(this, runner);
11
- let passes = 0;
12
- let failures = 0;
14
+ let passes = 0; let failures = 0; let skipped = 0;
15
+ let artifactStore;
13
16
 
14
- const client = new TestomatClient({ apiKey: opts?.reporterOptions?.apiKey });
17
+ const apiKey = opts?.reporterOptions?.apiKey || process.env.TESTOMATIO;
18
+
19
+ if (!apiKey) {
20
+ debug('TESTOMATIO key is empty, ignoring reports');
21
+ return;
22
+ }
23
+ const client = new TestomatClient({ apiKey });
15
24
 
16
25
  runner.on(EVENT_RUN_BEGIN, () => {
17
26
  client.createRun();
27
+
28
+ const params = {
29
+ "toFile": true
30
+ };
31
+
32
+ (runner._workerReporter !== undefined)
33
+ ? artifactStore = new ArtifactStorage(params)
34
+ : artifactStore = new ArtifactStorage();
18
35
  });
19
36
 
20
- runner.on(EVENT_TEST_PASS, test => {
37
+ runner.on(EVENT_TEST_PASS, async(test) => {
21
38
  passes += 1;
22
- console.log('pass: %s', test.fullTitle());
39
+ console.log(chalk.bold.green(''), test.fullTitle());
40
+ const testId = parseTest(test.title);
41
+
42
+ const specificTest = specificTestInfo(test);
43
+ const content = await artifactStore.artifactByTestName(specificTest);
44
+
45
+ debug(`test=${specificTest} content = `, content);
46
+
47
+ client.addTestRun(
48
+ testId,
49
+ TRConstants.PASSED,
50
+ {
51
+ title: test.title,
52
+ time: test.duration,
53
+ },
54
+ content
55
+ );
56
+ });
57
+
58
+ runner.on(EVENT_TEST_PENDING, test => {
59
+ skipped += 1;
60
+ console.log('skip: %s', test.fullTitle());
23
61
  const testId = parseTest(test.title);
24
- client.addTestRun(testId, TRConstants.PASSED, {
62
+ client.addTestRun(testId, TRConstants.SKIPPED, {
25
63
  title: test.title,
26
64
  time: test.duration,
27
65
  });
28
66
  });
29
67
 
30
- runner.on(EVENT_TEST_FAIL, (test, err) => {
68
+ runner.on(EVENT_TEST_FAIL, async(test, err) => {
31
69
  failures += 1;
32
- console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
70
+ console.log(chalk.bold.red(''), test.fullTitle(), chalk.gray(err.message));
33
71
  const testId = parseTest(test.title);
34
- client.addTestRun(testId, TRConstants.FAILED, {
35
- error: err,
36
- title: test.title,
37
- time: test.duration,
38
- });
72
+
73
+ const specificTest = specificTestInfo(test);
74
+ const content = await artifactStore.artifactByTestName(specificTest);
75
+
76
+ debug(`fail test=${specificTest} content = `, content);
77
+
78
+ client.addTestRun(
79
+ testId,
80
+ TRConstants.FAILED, {
81
+ error: err,
82
+ title: test.title,
83
+ time: test.duration,
84
+ },
85
+ content
86
+ );
39
87
  });
40
88
 
41
89
  runner.on(EVENT_RUN_END, () => {
42
- console.log('end: %d/%d', passes, passes + failures);
43
90
  const status = failures === 0 ? TRConstants.PASSED : TRConstants.FAILED;
91
+ console.log(chalk.bold(status), `${passes} passed, ${failures} failed, ${skipped} skipped`);
44
92
  client.updateRunStatus(status);
93
+
94
+ artifactStore.cleanup();
45
95
  });
46
96
  }
47
97
 
@@ -10,13 +10,7 @@ const { parseTest } = require('../util');
10
10
 
11
11
  class TestomatioReporter {
12
12
  constructor(config = {}) {
13
- const { apiKey } = config;
14
-
15
- if (!apiKey) {
16
- console.log('API Key is not provided. Testomat.io report is disabled');
17
- } else {
18
- this.client = new TestomatioClient({ apiKey });
19
- }
13
+ this.client = new TestomatioClient({ apiKey: config?.apiKey });
20
14
 
21
15
  this.videos = [];
22
16
  }
@@ -75,7 +69,7 @@ class TestomatioReporter {
75
69
  async onEnd(result) {
76
70
  if (!this.client) return;
77
71
 
78
- if (this.videos.length && upload.isArtifactsEnabled) {
72
+ if (this.videos.length && upload.isArtifactsEnabled()) {
79
73
  console.log(Status.APP_PREFIX, `🎞️ Uploading ${this.videos.length} videos...`);
80
74
 
81
75
  const promises = [];
@@ -7,10 +7,7 @@ class WebdriverReporter extends WDIOReporter {
7
7
  constructor(options) {
8
8
  super(options);
9
9
 
10
- const { apiKey } = options;
11
- if (!apiKey) return;
12
-
13
- this.client = new TestomatClient({ apiKey });
10
+ this.client = new TestomatClient({ apiKey: options?.apiKey });
14
11
  options = Object.assign(options, { stdout: true });
15
12
 
16
13
  this._addTestPromises = [];
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
+
2
3
  const program = require("commander");
3
4
  const chalk = require("chalk");
4
5
  const glob = require('glob');
5
-
6
+ const debug = require('debug')('@testomatio/reporter:xml-cli');
6
7
  const { APP_PREFIX } = require('../constants');
7
8
  const XmlReader = require("../xmlReader");
8
9
 
@@ -22,7 +23,10 @@ program
22
23
  pattern += '.xml';
23
24
  }
24
25
  let { javaTests, lang } = opts;
25
- if (opts.envFile) require('dotenv').config(opts.envFile); // eslint-disable-line
26
+ if (opts.envFile) {
27
+ debug('Loading env file: %s', opts.envFile)
28
+ require('dotenv').config({ path: opts.envFile }); // eslint-disable-line
29
+ }
26
30
  if (javaTests === true) javaTests = 'src/test/java';
27
31
  lang = lang?.toLowerCase();
28
32
  const runReader = new XmlReader({ javaTests, lang });