@testomatio/reporter 2.0.1-beta.4 → 2.0.1-beta.5-timestamp

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.
Files changed (148) hide show
  1. package/lib/adapter/codecept.js +335 -293
  2. package/lib/adapter/cucumber/current.js +203 -195
  3. package/lib/adapter/cucumber/legacy.js +155 -130
  4. package/lib/adapter/cucumber.js +16 -5
  5. package/lib/adapter/cypress-plugin/index.js +105 -91
  6. package/lib/adapter/jasmine.js +53 -54
  7. package/lib/adapter/jest.js +99 -97
  8. package/lib/adapter/mocha.js +141 -112
  9. package/lib/adapter/playwright.js +231 -199
  10. package/lib/adapter/vitest.js +149 -150
  11. package/lib/adapter/webdriver.js +121 -144
  12. package/lib/bin/cli.js +211 -229
  13. package/lib/bin/reportXml.js +52 -51
  14. package/lib/bin/startTest.js +95 -83
  15. package/lib/bin/uploadArtifacts.js +61 -56
  16. package/lib/client.js +465 -424
  17. package/lib/config.js +23 -18
  18. package/lib/constants.js +44 -50
  19. package/lib/data-storage.js +188 -216
  20. package/lib/junit-adapter/adapter.js +20 -17
  21. package/lib/junit-adapter/csharp.js +14 -28
  22. package/lib/junit-adapter/index.js +25 -27
  23. package/lib/junit-adapter/java.js +53 -41
  24. package/lib/junit-adapter/javascript.js +27 -30
  25. package/lib/junit-adapter/python.js +37 -38
  26. package/lib/junit-adapter/ruby.js +8 -11
  27. package/lib/output.js +52 -44
  28. package/lib/pipe/bitbucket.js +230 -223
  29. package/lib/pipe/csv.js +126 -113
  30. package/lib/pipe/debug.js +99 -118
  31. package/lib/pipe/github.js +213 -218
  32. package/lib/pipe/gitlab.js +206 -183
  33. package/lib/pipe/html.js +321 -258
  34. package/lib/pipe/index.js +66 -94
  35. package/lib/pipe/testomatio.js +474 -429
  36. package/lib/reporter-functions.js +26 -28
  37. package/lib/reporter.js +29 -34
  38. package/lib/services/artifacts.js +51 -55
  39. package/lib/services/index.js +12 -14
  40. package/lib/services/key-values.js +53 -56
  41. package/lib/services/logger.js +245 -226
  42. package/lib/template/testomatio.hbs +1366 -1026
  43. package/lib/uploader.js +364 -295
  44. package/lib/utils/pipe_utils.js +85 -89
  45. package/lib/utils/utils.js +307 -398
  46. package/lib/xmlReader.js +532 -525
  47. package/package.json +21 -64
  48. package/lib/adapter/codecept.d.ts +0 -2
  49. package/lib/adapter/cucumber/current.d.ts +0 -14
  50. package/lib/adapter/cucumber/legacy.d.ts +0 -0
  51. package/lib/adapter/cucumber.d.ts +0 -2
  52. package/lib/adapter/cypress-plugin/index.d.ts +0 -2
  53. package/lib/adapter/jasmine.d.ts +0 -11
  54. package/lib/adapter/jest.d.ts +0 -13
  55. package/lib/adapter/mocha.d.ts +0 -2
  56. package/lib/adapter/nightwatch.d.ts +0 -4
  57. package/lib/adapter/nightwatch.js +0 -80
  58. package/lib/adapter/playwright.d.ts +0 -14
  59. package/lib/adapter/vitest.d.ts +0 -35
  60. package/lib/adapter/webdriver.d.ts +0 -24
  61. package/lib/bin/cli.d.ts +0 -2
  62. package/lib/bin/reportXml.d.ts +0 -2
  63. package/lib/bin/startTest.d.ts +0 -2
  64. package/lib/bin/uploadArtifacts.d.ts +0 -2
  65. package/lib/client.d.ts +0 -76
  66. package/lib/config.d.ts +0 -1
  67. package/lib/constants.d.ts +0 -25
  68. package/lib/data-storage.d.ts +0 -34
  69. package/lib/junit-adapter/adapter.d.ts +0 -9
  70. package/lib/junit-adapter/csharp.d.ts +0 -5
  71. package/lib/junit-adapter/index.d.ts +0 -3
  72. package/lib/junit-adapter/java.d.ts +0 -5
  73. package/lib/junit-adapter/javascript.d.ts +0 -4
  74. package/lib/junit-adapter/python.d.ts +0 -5
  75. package/lib/junit-adapter/ruby.d.ts +0 -4
  76. package/lib/output.d.ts +0 -11
  77. package/lib/package.json +0 -3
  78. package/lib/pipe/bitbucket.d.ts +0 -25
  79. package/lib/pipe/csv.d.ts +0 -47
  80. package/lib/pipe/debug.d.ts +0 -29
  81. package/lib/pipe/github.d.ts +0 -30
  82. package/lib/pipe/gitlab.d.ts +0 -25
  83. package/lib/pipe/html.d.ts +0 -35
  84. package/lib/pipe/index.d.ts +0 -1
  85. package/lib/pipe/testomatio.d.ts +0 -71
  86. package/lib/replay.d.ts +0 -31
  87. package/lib/replay.js +0 -237
  88. package/lib/reporter-functions.d.ts +0 -34
  89. package/lib/reporter.d.ts +0 -232
  90. package/lib/services/artifacts.d.ts +0 -33
  91. package/lib/services/index.d.ts +0 -9
  92. package/lib/services/key-values.d.ts +0 -27
  93. package/lib/services/logger.d.ts +0 -64
  94. package/lib/uploader.d.ts +0 -60
  95. package/lib/utils/pipe_utils.d.ts +0 -41
  96. package/lib/utils/utils.d.ts +0 -54
  97. package/lib/xmlReader.d.ts +0 -92
  98. package/src/adapter/codecept.js +0 -373
  99. package/src/adapter/cucumber/current.js +0 -228
  100. package/src/adapter/cucumber/legacy.js +0 -158
  101. package/src/adapter/cucumber.js +0 -4
  102. package/src/adapter/cypress-plugin/index.js +0 -110
  103. package/src/adapter/jasmine.js +0 -60
  104. package/src/adapter/jest.js +0 -107
  105. package/src/adapter/mocha.cjs +0 -2
  106. package/src/adapter/mocha.js +0 -156
  107. package/src/adapter/nightwatch.js +0 -88
  108. package/src/adapter/playwright.js +0 -254
  109. package/src/adapter/vitest.js +0 -183
  110. package/src/adapter/webdriver.js +0 -142
  111. package/src/bin/cli.js +0 -348
  112. package/src/bin/reportXml.js +0 -77
  113. package/src/bin/startTest.js +0 -124
  114. package/src/bin/uploadArtifacts.js +0 -91
  115. package/src/client.js +0 -508
  116. package/src/config.js +0 -30
  117. package/src/constants.js +0 -53
  118. package/src/data-storage.js +0 -204
  119. package/src/junit-adapter/adapter.js +0 -23
  120. package/src/junit-adapter/csharp.js +0 -28
  121. package/src/junit-adapter/index.js +0 -28
  122. package/src/junit-adapter/java.js +0 -58
  123. package/src/junit-adapter/javascript.js +0 -31
  124. package/src/junit-adapter/python.js +0 -42
  125. package/src/junit-adapter/ruby.js +0 -10
  126. package/src/output.js +0 -57
  127. package/src/pipe/bitbucket.js +0 -252
  128. package/src/pipe/csv.js +0 -140
  129. package/src/pipe/debug.js +0 -119
  130. package/src/pipe/github.js +0 -232
  131. package/src/pipe/gitlab.js +0 -247
  132. package/src/pipe/html.js +0 -373
  133. package/src/pipe/index.js +0 -71
  134. package/src/pipe/testomatio.js +0 -504
  135. package/src/replay.js +0 -245
  136. package/src/reporter-functions.js +0 -55
  137. package/src/reporter.cjs_decprecated +0 -21
  138. package/src/reporter.js +0 -33
  139. package/src/services/artifacts.js +0 -59
  140. package/src/services/index.js +0 -13
  141. package/src/services/key-values.js +0 -59
  142. package/src/services/logger.js +0 -315
  143. package/src/template/emptyData.svg +0 -23
  144. package/src/template/testomatio.hbs +0 -1081
  145. package/src/uploader.js +0 -376
  146. package/src/utils/pipe_utils.js +0 -119
  147. package/src/utils/utils.js +0 -416
  148. package/src/xmlReader.js +0 -614
@@ -1,130 +1,155 @@
1
- // import { Formatter } from 'cucumber';
2
- // import pc from 'picocolors';
3
- // import { getTestomatIdFromTestTitle, fileSystem } from '../../utils/utils.js';
4
- // import { STATUS, TESTOMAT_TMP_STORAGE_DIR } from '../../constants.js';
5
- // import TestomatClient from '../../client.js';
6
- // import {config} from '../../config.js';
7
- // const createTestomatFormatter = apiKey => {
8
- // if (!apiKey || apiKey === '') {
9
- // console.log(pc.red('TESTOMATIO key is empty, ignoring reports'));
10
- // }
11
- // const documents = {};
12
- // const dataTableMap = {};
13
- // const addDocument = gherkinDocument => {
14
- // documents[gherkinDocument.uri] = gherkinDocument.document;
15
- // };
16
- // const getTitle = scenario => {
17
- // let { name } = scenario;
18
- // if (scenario.tags.length) {
19
- // let tags = '';
20
- // for (const tag of scenario.tags) {
21
- // tags = `${tags} ${tag.name}`;
22
- // }
23
- // name = `${name}${tags}`;
24
- // }
25
- // return name;
26
- // };
27
- // const getFeature = uri => documents[uri].feature;
28
- // const getScenario = location => {
29
- // const { children } = getFeature(location.uri);
30
- // for (const scenario of children) {
31
- // if (scenario.type === 'Scenario' && scenario.location.line === location.line) {
32
- // return scenario;
33
- // }
34
- // if (scenario.type === 'ScenarioOutline') {
35
- // for (const example of scenario.examples) {
36
- // for (const tableBody of example.tableBody) {
37
- // if (tableBody.location.line === location.line) {
38
- // return scenario;
39
- // }
40
- // }
41
- // }
42
- // }
43
- // }
44
- // return null;
45
- // };
46
- // const loadDataTable = (scenario, uri) => {
47
- // if (scenario.type === 'ScenarioOutline') {
48
- // for (const example of scenario.examples) {
49
- // for (const tableBody of example.tableBody) {
50
- // const dataMap = example.tableHeader.cells.reduce((acc, cell, index) => {
51
- // acc[cell.value] = tableBody.cells[index].value;
52
- // return acc;
53
- // }, {});
54
- // dataTableMap[`${uri}:${tableBody.location.line}`] = JSON.stringify(dataMap);
55
- // }
56
- // }
57
- // }
58
- // };
59
- // const getDataTableMap = (scenario, sourceLocation) => {
60
- // const key = `${sourceLocation.uri}:${sourceLocation.line}`;
61
- // if (!dataTableMap[key]) {
62
- // loadDataTable(scenario, sourceLocation.uri);
63
- // }
64
- // return dataTableMap[key] || '';
65
- // };
66
- // const getTestId = scenario => {
67
- // if (scenario) {
68
- // for (const tag of scenario.tags) {
69
- // const testId = getTestomatIdFromTestTitle(tag.name);
70
- // if (testId) return testId;
71
- // }
72
- // }
73
- // return null;
74
- // };
75
- // return class TestomatFormatter extends Formatter {
76
- // constructor(options) {
77
- // super(options);
78
- // if (!apiKey) return;
79
- // this.client = new TestomatClient({ apiKey });
80
- // this.status = STATUS.PASSED.toString();
81
- // options.eventBroadcaster.on('gherkin-document', addDocument);
82
- // options.eventBroadcaster.on('test-run-started', () => {
83
- // fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR);
84
- // this?.client?.createRun();
85
- // });
86
- // options.eventBroadcaster.on('test-case-finished', this.onTestCaseFinished.bind(this));
87
- // options.eventBroadcaster.on('test-case-started', this.onTestCaseStarted.bind(this));
88
- // // @ts-ignore
89
- // options.eventBroadcaster.on('test-run-finished', () => this?.client?.updateRunStatus(this.status));
90
- // global.testomatioRunningEnvironment = 'cucumber:legacy';
91
- // }
92
- // onTestCaseStarted(event) {
93
- // const scenario = getScenario(event.sourceLocation);
94
- // const testId = getTestId(scenario);
95
- // if (!global.testomatioDataStore) global.testomatioDataStore = {};
96
- // global.testomatioDataStore.currentlyRunningTestId = testId;
97
- // }
98
- // onTestCaseFinished(event) {
99
- // const scenario = getScenario(event.sourceLocation);
100
- // const testId = getTestId(scenario);
101
- // const status = event.result.status === 'undefined' ? STATUS.SKIPPED : event.result.status;
102
- // let example = getDataTableMap(scenario, event.sourceLocation);
103
- // if (example) example = JSON.parse(example);
104
- // if (!scenario.name) return;
105
- // const message = '';
106
- // const cliMessage = `- ${scenario.name}: ${pc.bold(status.toUpperCase())}`;
107
- // // if (event.result.status === 'undefined') {
108
- // // cliMessage += pc.yellow(
109
- // // ' (undefined steps. Run Cucumber without this formatter and implement missing steps)',
110
- // // );
111
- // // message = 'Undefined steps. Implement missing steps and rerun this scenario';
112
- // // }
113
- // console.log(cliMessage);
114
- // if (status !== STATUS.PASSED && status !== STATUS.SKIPPED) {
115
- // this.status = STATUS.FAILED;
116
- // }
117
- // this.client?.addTestRun(status, {
118
- // error: event.result.exception instanceof Error ? event.result.exception : undefined,
119
- // message,
120
- // example,
121
- // test_id: testId,
122
- // title: getTitle(scenario),
123
- // suite_title: getTitle(getFeature(event.sourceLocation.uri)),
124
- // });
125
- // }
126
- // };
127
- // };
128
- // const CucumberLegacyReporter = createTestomatFormatter(config.TESTOMATIO);
129
- // export { CucumberLegacyReporter };
130
- // export default CucumberLegacyReporter;
1
+ // eslint-disable-next-line global-require, import/no-extraneous-dependencies, import/no-unresolved
2
+ const { Formatter } = require('cucumber');
3
+ const chalk = require('chalk');
4
+ const { getTestomatIdFromTestTitle, fileSystem } = require('../../utils/utils');
5
+ const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../../constants');
6
+ const TestomatClient = require('../../client');
7
+ const config = require('../../config');
8
+
9
+ const createTestomatFormatter = apiKey => {
10
+ if (!apiKey || apiKey === '') {
11
+ console.log(chalk.red('TESTOMATIO key is empty, ignoring reports'));
12
+ }
13
+
14
+ const documents = {};
15
+ const dataTableMap = {};
16
+
17
+ const addDocument = gherkinDocument => {
18
+ documents[gherkinDocument.uri] = gherkinDocument.document;
19
+ };
20
+
21
+ const getTitle = scenario => {
22
+ let { name } = scenario;
23
+ if (scenario.tags.length) {
24
+ let tags = '';
25
+ for (const tag of scenario.tags) {
26
+ tags = `${tags} ${tag.name}`;
27
+ }
28
+ name = `${name}${tags}`;
29
+ }
30
+ return name;
31
+ };
32
+
33
+ const getFeature = uri => documents[uri].feature;
34
+
35
+ const getScenario = location => {
36
+ const { children } = getFeature(location.uri);
37
+ for (const scenario of children) {
38
+ if (scenario.type === 'Scenario' && scenario.location.line === location.line) {
39
+ return scenario;
40
+ }
41
+ if (scenario.type === 'ScenarioOutline') {
42
+ for (const example of scenario.examples) {
43
+ for (const tableBody of example.tableBody) {
44
+ if (tableBody.location.line === location.line) {
45
+ return scenario;
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ return null;
53
+ };
54
+
55
+ const loadDataTable = (scenario, uri) => {
56
+ if (scenario.type === 'ScenarioOutline') {
57
+ for (const example of scenario.examples) {
58
+ for (const tableBody of example.tableBody) {
59
+ const dataMap = example.tableHeader.cells.reduce((acc, cell, index) => {
60
+ acc[cell.value] = tableBody.cells[index].value;
61
+ return acc;
62
+ }, {});
63
+
64
+ dataTableMap[`${uri}:${tableBody.location.line}`] = JSON.stringify(dataMap);
65
+ }
66
+ }
67
+ }
68
+ };
69
+
70
+ const getDataTableMap = (scenario, sourceLocation) => {
71
+ const key = `${sourceLocation.uri}:${sourceLocation.line}`;
72
+ if (!dataTableMap[key]) {
73
+ loadDataTable(scenario, sourceLocation.uri);
74
+ }
75
+
76
+ return dataTableMap[key] || '';
77
+ };
78
+
79
+ const getTestId = scenario => {
80
+ if (scenario) {
81
+ for (const tag of scenario.tags) {
82
+ const testId = getTestomatIdFromTestTitle(tag.name);
83
+ if (testId) return testId;
84
+ }
85
+ }
86
+
87
+ return null;
88
+ };
89
+
90
+ return class TestomatFormatter extends Formatter {
91
+ constructor(options) {
92
+ super(options);
93
+
94
+ if (!apiKey) return;
95
+
96
+ this.client = new TestomatClient({ apiKey });
97
+ this.status = STATUS.PASSED.toString();
98
+
99
+ options.eventBroadcaster.on('gherkin-document', addDocument);
100
+ options.eventBroadcaster.on('test-run-started', () => {
101
+ fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR);
102
+ this?.client?.createRun();
103
+ });
104
+ options.eventBroadcaster.on('test-case-finished', this.onTestCaseFinished.bind(this));
105
+ options.eventBroadcaster.on('test-case-started', this.onTestCaseStarted.bind(this));
106
+ options.eventBroadcaster.on('test-run-finished', () => this?.client?.updateRunStatus(this.status));
107
+
108
+ global.testomatioRunningEnvironment = 'cucumber:legacy';
109
+ }
110
+
111
+ onTestCaseStarted(event) {
112
+ const scenario = getScenario(event.sourceLocation);
113
+ const testId = getTestId(scenario);
114
+
115
+ if (!global.testomatioDataStore) global.testomatioDataStore = {};
116
+ global.testomatioDataStore.currentlyRunningTestId = testId;
117
+ }
118
+
119
+ onTestCaseFinished(event) {
120
+ const scenario = getScenario(event.sourceLocation);
121
+ const testId = getTestId(scenario);
122
+ const status = event.result.status === 'undefined' ? STATUS.SKIPPED : event.result.status;
123
+
124
+ let example = getDataTableMap(scenario, event.sourceLocation);
125
+ if (example) example = JSON.parse(example);
126
+
127
+ if (!scenario.name) return;
128
+
129
+ const message = '';
130
+ const cliMessage = `- ${scenario.name}: ${chalk.bold(status.toUpperCase())}`;
131
+
132
+ // if (event.result.status === 'undefined') {
133
+ // cliMessage += chalk.yellow(
134
+ // ' (undefined steps. Run Cucumber without this formatter and implement missing steps)',
135
+ // );
136
+ // message = 'Undefined steps. Implement missing steps and rerun this scenario';
137
+ // }
138
+ console.log(cliMessage);
139
+ if (status !== STATUS.PASSED && status !== STATUS.SKIPPED) {
140
+ this.status = STATUS.FAILED;
141
+ }
142
+
143
+ this.client?.addTestRun(status, {
144
+ error: event.result.exception instanceof Error ? event.result.exception : undefined,
145
+ message,
146
+ example,
147
+ test_id: testId,
148
+ title: getTitle(scenario),
149
+ suite_title: getTitle(getFeature(event.sourceLocation.uri)),
150
+ });
151
+ }
152
+ };
153
+ };
154
+
155
+ module.exports = createTestomatFormatter(config.TESTOMATIO);
@@ -1,5 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const current_js_1 = require("./cucumber/current.js");
4
- // import { CucumberLegacyReporter } from './cucumber/legacy.js';
5
- module.exports = current_js_1.CucumberReporter;
1
+ try {
2
+ // eslint-disable-next-line import/no-unresolved
3
+ require.resolve('@cucumber/cucumber');
4
+ // eslint-disable-next-line global-require, import/no-extraneous-dependencies
5
+ module.exports = require('./cucumber/current');
6
+ } catch (_e) {
7
+ try {
8
+ // eslint-disable-next-line global-require, import/no-extraneous-dependencies
9
+ require.resolve('cucumber');
10
+ // eslint-disable-next-line global-require, import/no-extraneous-dependencies
11
+ module.exports = require('./cucumber/legacy');
12
+ } catch (_err) {
13
+ console.error('Cucumber packages: "@cucumber/cucumber" or "cucumber" were not detected. Report won\'t be sent');
14
+ module.exports = {};
15
+ }
16
+ }
@@ -1,95 +1,109 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const constants_js_1 = require("../../constants.js");
7
- const utils_js_1 = require("../../utils/utils.js");
8
- const client_js_1 = __importDefault(require("../../client.js"));
9
- const config_js_1 = require("../../config.js");
1
+ const { STATUS } = require('../../constants');
2
+ const { getTestomatIdFromTestTitle, parseSuite } = require('../../utils/utils');
3
+ const TestomatClient = require('../../client');
4
+ const config = require('../../config');
5
+
10
6
  const testomatioReporter = on => {
11
- if (!config_js_1.config.TESTOMATIO) {
12
- console.log('TESTOMATIO key is empty, ignoring reports');
13
- return;
7
+ if (!config.TESTOMATIO) {
8
+ console.log('TESTOMATIO key is empty, ignoring reports');
9
+ return;
10
+ }
11
+ const client = new TestomatClient({ apiKey: config.TESTOMATIO });
12
+
13
+ on('before:run', async run => {
14
+ // TODO: looks like client.env does not exist
15
+ if (!client.env) {
16
+ client.env = `${run.browser.displayName},${run.system.osName}`;
17
+ }
18
+ await client.createRun();
19
+ });
20
+
21
+ on('after:spec', async (_spec, results) => {
22
+ const addSpecTestsPromises = [];
23
+
24
+ const videos = [results.video];
25
+
26
+ for (const test of results.tests) {
27
+ const lastAttemptIndex = test.attempts.length - 1;
28
+ const latestAttempt = test.attempts[lastAttemptIndex];
29
+
30
+ // latestAttempt.duration && latestAttempt.error were available in adapters version up to 13 JFYI
31
+ const time = latestAttempt.duration || latestAttempt.wallClockDuration || test.duration;
32
+ let error = latestAttempt.error;
33
+
34
+ let title = test.title.pop();
35
+ const examples = title.match(/\(example (#\d+)\)/);
36
+ let example = null;
37
+ if (examples && examples[1]) example = { example: examples[1] };
38
+ title = title.replace(/\(example #\d+\)/, '').trim();
39
+
40
+ const suiteTitle = test.title.pop();
41
+
42
+ const testId = getTestomatIdFromTestTitle(title);
43
+ const suiteId = parseSuite(suiteTitle);
44
+
45
+ if (!error && test.displayError) {
46
+ error = { message: test.displayError };
47
+ error.inspect = function () {
48
+ // eslint-disable-line func-names
49
+ return this.message;
50
+ };
51
+ }
52
+
53
+ const formattedError = error
54
+ ? {
55
+ message: error.message,
56
+ inspect:
57
+ error.inspect ||
58
+ function () {
59
+ return this.message;
60
+ },
61
+ }
62
+ : '';
63
+
64
+ const screenshots = Array.isArray(results.screenshots)
65
+ ? results.screenshots
66
+ .filter(screenshot => screenshot?.path && screenshot?.path.includes(title) && screenshot?.takenAt)
67
+ .map(screenshot => screenshot.path)
68
+ : [];
69
+
70
+ const files = [...videos, ...screenshots];
71
+
72
+ let state;
73
+ switch (test.state) {
74
+ case 'passed':
75
+ state = STATUS.PASSED;
76
+ break;
77
+ case 'failed':
78
+ state = STATUS.FAILED;
79
+ break;
80
+ case 'skipped':
81
+ case 'pending':
82
+ default:
83
+ state = STATUS.SKIPPED;
84
+ }
85
+
86
+ addSpecTestsPromises.push(
87
+ client.addTestRun(state, {
88
+ title,
89
+ time,
90
+ example,
91
+ error: formattedError,
92
+ files,
93
+ suite_title: suiteTitle,
94
+ test_id: testId,
95
+ suite_id: suiteId,
96
+ }),
97
+ );
14
98
  }
15
- const client = new client_js_1.default({ apiKey: config_js_1.config.TESTOMATIO });
16
- on('before:run', async () => {
17
- // TODO: looks like client.env does not exist
18
- // if (!client.env) {
19
- // client.env = `${run.browser.displayName},${run.system.osName}`;
20
- // }
21
- await client.createRun();
22
- });
23
- on('after:spec', async (_spec, results) => {
24
- const addSpecTestsPromises = [];
25
- const videos = [results.video];
26
- for (const test of results.tests) {
27
- const lastAttemptIndex = test.attempts.length - 1;
28
- const latestAttempt = test.attempts[lastAttemptIndex];
29
- // latestAttempt.duration && latestAttempt.error were available in adapters version up to 13 JFYI
30
- const time = latestAttempt.duration || latestAttempt.wallClockDuration || test.duration;
31
- let error = latestAttempt.error;
32
- let title = test.title.pop();
33
- const examples = title.match(/\(example (#\d+)\)/);
34
- let example = null;
35
- if (examples && examples[1])
36
- example = { example: examples[1] };
37
- title = title.replace(/\(example #\d+\)/, '').trim();
38
- const suiteTitle = test.title.pop();
39
- const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(title);
40
- const suiteId = (0, utils_js_1.parseSuite)(suiteTitle);
41
- if (!error && test.displayError) {
42
- error = { message: test.displayError };
43
- error.inspect = function () {
44
- return this.message;
45
- };
46
- }
47
- const formattedError = error
48
- ? {
49
- message: error.message,
50
- name: error.name,
51
- inspect: error.inspect ||
52
- function () {
53
- return this.message;
54
- },
55
- }
56
- : undefined;
57
- const screenshots = Array.isArray(results.screenshots)
58
- ? results.screenshots
59
- .filter(screenshot => screenshot?.path && screenshot?.path.includes(title) && screenshot?.takenAt)
60
- .map(screenshot => screenshot.path)
61
- : [];
62
- const files = [...videos, ...screenshots];
63
- let state;
64
- switch (test.state) {
65
- case 'passed':
66
- state = constants_js_1.STATUS.PASSED;
67
- break;
68
- case 'failed':
69
- state = constants_js_1.STATUS.FAILED;
70
- break;
71
- case 'skipped':
72
- case 'pending':
73
- default:
74
- state = constants_js_1.STATUS.SKIPPED;
75
- }
76
- addSpecTestsPromises.push(client.addTestRun(state, {
77
- title,
78
- time,
79
- example,
80
- error: formattedError,
81
- files,
82
- suite_title: suiteTitle,
83
- test_id: testId,
84
- suite_id: suiteId,
85
- }));
86
- }
87
- await Promise.all(addSpecTestsPromises);
88
- });
89
- on('after:run', async (results) => {
90
- const status = results.totalFailed ? constants_js_1.STATUS.FAILED : constants_js_1.STATUS.PASSED;
91
- // @ts-ignore
92
- await client.updateRunStatus(status);
93
- });
99
+
100
+ await Promise.all(addSpecTestsPromises);
101
+ });
102
+
103
+ on('after:run', async results => {
104
+ const status = results.totalFailed ? STATUS.FAILED : STATUS.PASSED;
105
+ await client.updateRunStatus(status);
106
+ });
94
107
  };
108
+
95
109
  module.exports = testomatioReporter;
@@ -1,59 +1,58 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.JasmineReporter = void 0;
7
- const client_js_1 = __importDefault(require("../client.js"));
8
- const utils_js_1 = require("../utils/utils.js");
9
- const constants_js_1 = require("../constants.js");
1
+ const TestomatClient = require('../client');
2
+ const { getTestomatIdFromTestTitle, ansiRegExp } = require('../utils/utils');
3
+ const { STATUS } = require('../constants');
4
+
10
5
  class JasmineReporter {
11
- constructor(options) {
12
- this.testTimeMap = {};
13
- this.client = new client_js_1.default({ apiKey: options?.apiKey });
14
- this.client.createRun();
15
- }
16
- getDuration(test) {
17
- if (this.testTimeMap[test.id]) {
18
- return Date.now() - this.testTimeMap[test.id];
19
- }
20
- return 0;
21
- }
22
- specStarted(result) {
23
- this.testTimeMap[result.id] = Date.now();
24
- }
25
- specDone(result) {
26
- if (!this.client)
27
- return;
28
- const title = result.description;
29
- const { status } = result;
30
- let errorMessage = '';
31
- for (let i = 0; i < result.failedExpectations.length; i += 1) {
32
- errorMessage = `${errorMessage}Failure: ${result.failedExpectations[i].message}\n`;
33
- errorMessage = `${errorMessage}\n ${result.failedExpectations[i].stack}`;
34
- }
35
- console.log(`${title} : ${constants_js_1.STATUS.PASSED}`);
36
- console.log(errorMessage);
37
- const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(title);
38
- errorMessage = errorMessage.replace((0, utils_js_1.ansiRegExp)(), '');
39
- this.client.addTestRun(status, {
40
- error: result.failedExpectations[0],
41
- message: errorMessage,
42
- test_id: testId,
43
- title,
44
- time: this.getDuration(result),
45
- });
6
+ constructor(options) {
7
+ this.testTimeMap = {};
8
+ this.client = new TestomatClient({ apiKey: options?.apiKey });
9
+ this.client.createRun();
10
+ }
11
+
12
+ getDuration(test) {
13
+ if (this.testTimeMap[test.id]) {
14
+ return Date.now() - this.testTimeMap[test.id];
46
15
  }
47
- jasmineDone(suiteInfo, done) {
48
- if (!this.client)
49
- return;
50
- const { overallStatus } = suiteInfo;
51
- const status = overallStatus === 'failed' ? constants_js_1.STATUS.FAILED : constants_js_1.STATUS.PASSED;
52
- // @ts-ignore
53
- this.client.updateRunStatus(status).then(() => done);
16
+
17
+ return 0;
18
+ }
19
+
20
+ specStarted(result) {
21
+ this.testTimeMap[result.id] = Date.now();
22
+ }
23
+
24
+ specDone(result) {
25
+ if (!this.client) return;
26
+
27
+ const title = result.description;
28
+ const { status } = result;
29
+ let errorMessage = '';
30
+
31
+ for (let i = 0; i < result.failedExpectations.length; i += 1) {
32
+ errorMessage = `${errorMessage}Failure: ${result.failedExpectations[i].message}\n`;
33
+ errorMessage = `${errorMessage}\n ${result.failedExpectations[i].stack}`;
54
34
  }
35
+ console.log(`${title} : ${STATUS.PASSED}`);
36
+ console.log(errorMessage);
37
+ const testId = getTestomatIdFromTestTitle(title);
38
+ errorMessage = errorMessage.replace(ansiRegExp(), '');
39
+ this.client.addTestRun(status, {
40
+ error: result.failedExpectations[0],
41
+ message: errorMessage,
42
+ test_id: testId,
43
+ title,
44
+ time: this.getDuration(result),
45
+ });
46
+ }
47
+
48
+ jasmineDone(suiteInfo, done) {
49
+ if (!this.client) return;
50
+
51
+ const { overallStatus } = suiteInfo;
52
+ const status = overallStatus === 'failed' ? STATUS.FAILED : STATUS.PASSED;
53
+
54
+ this.client.updateRunStatus(status).then(() => done);
55
+ }
55
56
  }
56
- exports.JasmineReporter = JasmineReporter;
57
- module.exports = JasmineReporter;
58
57
 
59
- module.exports.JasmineReporter = JasmineReporter;
58
+ module.exports = JasmineReporter;