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

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 (149) hide show
  1. package/README.md +1 -0
  2. package/lib/adapter/codecept.d.ts +2 -0
  3. package/lib/adapter/codecept.js +293 -335
  4. package/lib/adapter/cucumber/current.d.ts +14 -0
  5. package/lib/adapter/cucumber/current.js +195 -203
  6. package/lib/adapter/cucumber/legacy.d.ts +0 -0
  7. package/lib/adapter/cucumber/legacy.js +130 -155
  8. package/lib/adapter/cucumber.d.ts +2 -0
  9. package/lib/adapter/cucumber.js +5 -16
  10. package/lib/adapter/cypress-plugin/index.d.ts +2 -0
  11. package/lib/adapter/cypress-plugin/index.js +91 -105
  12. package/lib/adapter/jasmine.d.ts +11 -0
  13. package/lib/adapter/jasmine.js +54 -53
  14. package/lib/adapter/jest.d.ts +13 -0
  15. package/lib/adapter/jest.js +97 -99
  16. package/lib/adapter/mocha.d.ts +2 -0
  17. package/lib/adapter/mocha.js +112 -141
  18. package/lib/adapter/nightwatch.d.ts +4 -0
  19. package/lib/adapter/nightwatch.js +80 -0
  20. package/lib/adapter/playwright.d.ts +14 -0
  21. package/lib/adapter/playwright.js +199 -231
  22. package/lib/adapter/vitest.d.ts +35 -0
  23. package/lib/adapter/vitest.js +150 -149
  24. package/lib/adapter/webdriver.d.ts +24 -0
  25. package/lib/adapter/webdriver.js +144 -121
  26. package/lib/bin/cli.d.ts +2 -0
  27. package/lib/bin/cli.js +229 -211
  28. package/lib/bin/reportXml.d.ts +2 -0
  29. package/lib/bin/reportXml.js +51 -52
  30. package/lib/bin/startTest.d.ts +2 -0
  31. package/lib/bin/startTest.js +83 -95
  32. package/lib/bin/uploadArtifacts.d.ts +2 -0
  33. package/lib/bin/uploadArtifacts.js +56 -61
  34. package/lib/client.d.ts +76 -0
  35. package/lib/client.js +429 -465
  36. package/lib/config.d.ts +1 -0
  37. package/lib/config.js +18 -23
  38. package/lib/constants.d.ts +25 -0
  39. package/lib/constants.js +50 -44
  40. package/lib/data-storage.d.ts +34 -0
  41. package/lib/data-storage.js +216 -188
  42. package/lib/junit-adapter/adapter.d.ts +9 -0
  43. package/lib/junit-adapter/adapter.js +17 -20
  44. package/lib/junit-adapter/csharp.d.ts +5 -0
  45. package/lib/junit-adapter/csharp.js +28 -14
  46. package/lib/junit-adapter/index.d.ts +3 -0
  47. package/lib/junit-adapter/index.js +27 -25
  48. package/lib/junit-adapter/java.d.ts +5 -0
  49. package/lib/junit-adapter/java.js +41 -53
  50. package/lib/junit-adapter/javascript.d.ts +4 -0
  51. package/lib/junit-adapter/javascript.js +30 -27
  52. package/lib/junit-adapter/python.d.ts +5 -0
  53. package/lib/junit-adapter/python.js +38 -37
  54. package/lib/junit-adapter/ruby.d.ts +4 -0
  55. package/lib/junit-adapter/ruby.js +11 -8
  56. package/lib/output.d.ts +11 -0
  57. package/lib/output.js +44 -52
  58. package/lib/package.json +3 -0
  59. package/lib/pipe/bitbucket.d.ts +25 -0
  60. package/lib/pipe/bitbucket.js +223 -230
  61. package/lib/pipe/csv.d.ts +47 -0
  62. package/lib/pipe/csv.js +113 -126
  63. package/lib/pipe/debug.d.ts +29 -0
  64. package/lib/pipe/debug.js +125 -99
  65. package/lib/pipe/github.d.ts +30 -0
  66. package/lib/pipe/github.js +218 -213
  67. package/lib/pipe/gitlab.d.ts +25 -0
  68. package/lib/pipe/gitlab.js +183 -206
  69. package/lib/pipe/html.d.ts +35 -0
  70. package/lib/pipe/html.js +258 -321
  71. package/lib/pipe/index.d.ts +1 -0
  72. package/lib/pipe/index.js +94 -66
  73. package/lib/pipe/testomatio.d.ts +71 -0
  74. package/lib/pipe/testomatio.js +429 -474
  75. package/lib/replay.d.ts +31 -0
  76. package/lib/replay.js +255 -0
  77. package/lib/reporter-functions.d.ts +34 -0
  78. package/lib/reporter-functions.js +28 -26
  79. package/lib/reporter.d.ts +232 -0
  80. package/lib/reporter.js +34 -29
  81. package/lib/services/artifacts.d.ts +33 -0
  82. package/lib/services/artifacts.js +55 -51
  83. package/lib/services/index.d.ts +9 -0
  84. package/lib/services/index.js +14 -12
  85. package/lib/services/key-values.d.ts +27 -0
  86. package/lib/services/key-values.js +56 -53
  87. package/lib/services/logger.d.ts +64 -0
  88. package/lib/services/logger.js +226 -245
  89. package/lib/template/testomatio.hbs +1026 -1366
  90. package/lib/uploader.d.ts +60 -0
  91. package/lib/uploader.js +295 -364
  92. package/lib/utils/pipe_utils.d.ts +41 -0
  93. package/lib/utils/pipe_utils.js +89 -85
  94. package/lib/utils/utils.d.ts +54 -0
  95. package/lib/utils/utils.js +398 -307
  96. package/lib/xmlReader.d.ts +92 -0
  97. package/lib/xmlReader.js +525 -532
  98. package/package.json +64 -21
  99. package/src/adapter/codecept.js +373 -0
  100. package/src/adapter/cucumber/current.js +228 -0
  101. package/src/adapter/cucumber/legacy.js +158 -0
  102. package/src/adapter/cucumber.js +4 -0
  103. package/src/adapter/cypress-plugin/index.js +110 -0
  104. package/src/adapter/jasmine.js +60 -0
  105. package/src/adapter/jest.js +107 -0
  106. package/src/adapter/mocha.cjs +2 -0
  107. package/src/adapter/mocha.js +156 -0
  108. package/src/adapter/nightwatch.js +88 -0
  109. package/src/adapter/playwright.js +254 -0
  110. package/src/adapter/vitest.js +183 -0
  111. package/src/adapter/webdriver.js +142 -0
  112. package/src/bin/cli.js +348 -0
  113. package/src/bin/reportXml.js +77 -0
  114. package/src/bin/startTest.js +124 -0
  115. package/src/bin/uploadArtifacts.js +91 -0
  116. package/src/client.js +515 -0
  117. package/src/config.js +30 -0
  118. package/src/constants.js +53 -0
  119. package/src/data-storage.js +204 -0
  120. package/src/junit-adapter/adapter.js +23 -0
  121. package/src/junit-adapter/csharp.js +28 -0
  122. package/src/junit-adapter/index.js +28 -0
  123. package/src/junit-adapter/java.js +58 -0
  124. package/src/junit-adapter/javascript.js +31 -0
  125. package/src/junit-adapter/python.js +42 -0
  126. package/src/junit-adapter/ruby.js +10 -0
  127. package/src/output.js +57 -0
  128. package/src/pipe/bitbucket.js +252 -0
  129. package/src/pipe/csv.js +140 -0
  130. package/src/pipe/debug.js +125 -0
  131. package/src/pipe/github.js +232 -0
  132. package/src/pipe/gitlab.js +247 -0
  133. package/src/pipe/html.js +373 -0
  134. package/src/pipe/index.js +71 -0
  135. package/src/pipe/testomatio.js +504 -0
  136. package/src/replay.js +262 -0
  137. package/src/reporter-functions.js +55 -0
  138. package/src/reporter.cjs_decprecated +21 -0
  139. package/src/reporter.js +33 -0
  140. package/src/services/artifacts.js +59 -0
  141. package/src/services/index.js +13 -0
  142. package/src/services/key-values.js +59 -0
  143. package/src/services/logger.js +315 -0
  144. package/src/template/emptyData.svg +23 -0
  145. package/src/template/testomatio.hbs +1081 -0
  146. package/src/uploader.js +376 -0
  147. package/src/utils/pipe_utils.js +119 -0
  148. package/src/utils/utils.js +416 -0
  149. package/src/xmlReader.js +614 -0
@@ -1,155 +1,130 @@
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
+ // 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;
@@ -0,0 +1,2 @@
1
+ export default CucumberReporter;
2
+ import { CucumberReporter } from './cucumber/current.js';
@@ -1,16 +1,5 @@
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
+ "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;
@@ -0,0 +1,2 @@
1
+ export default testomatioReporter;
2
+ declare function testomatioReporter(on: any): void;
@@ -1,109 +1,95 @@
1
- const { STATUS } = require('../../constants');
2
- const { getTestomatIdFromTestTitle, parseSuite } = require('../../utils/utils');
3
- const TestomatClient = require('../../client');
4
- const config = require('../../config');
5
-
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");
6
10
  const testomatioReporter = on => {
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
- );
11
+ if (!config_js_1.config.TESTOMATIO) {
12
+ console.log('TESTOMATIO key is empty, ignoring reports');
13
+ return;
98
14
  }
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
- });
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
+ });
107
94
  };
108
-
109
95
  module.exports = testomatioReporter;
@@ -0,0 +1,11 @@
1
+ export default JasmineReporter;
2
+ export class JasmineReporter {
3
+ constructor(options: any);
4
+ testTimeMap: {};
5
+ client: TestomatClient;
6
+ getDuration(test: any): number;
7
+ specStarted(result: any): void;
8
+ specDone(result: any): void;
9
+ jasmineDone(suiteInfo: any, done: any): void;
10
+ }
11
+ import TestomatClient from '../client.js';
@@ -1,58 +1,59 @@
1
- const TestomatClient = require('../client');
2
- const { getTestomatIdFromTestTitle, ansiRegExp } = require('../utils/utils');
3
- const { STATUS } = require('../constants');
4
-
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");
5
10
  class JasmineReporter {
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];
11
+ constructor(options) {
12
+ this.testTimeMap = {};
13
+ this.client = new client_js_1.default({ apiKey: options?.apiKey });
14
+ this.client.createRun();
15
15
  }
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}`;
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
+ });
46
+ }
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);
34
54
  }
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
- }
56
55
  }
57
-
56
+ exports.JasmineReporter = JasmineReporter;
58
57
  module.exports = JasmineReporter;
58
+
59
+ module.exports.JasmineReporter = JasmineReporter;