@testomatio/reporter 1.6.13 → 2.0.1-beta-esm

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 (142) hide show
  1. package/lib/adapter/codecept.d.ts +2 -0
  2. package/lib/adapter/codecept.js +295 -335
  3. package/lib/adapter/cucumber/current.d.ts +14 -0
  4. package/lib/adapter/cucumber/current.js +195 -203
  5. package/lib/adapter/cucumber/legacy.d.ts +0 -0
  6. package/lib/adapter/cucumber/legacy.js +130 -155
  7. package/lib/adapter/cucumber.d.ts +2 -0
  8. package/lib/adapter/cucumber.js +5 -16
  9. package/lib/adapter/cypress-plugin/index.d.ts +2 -0
  10. package/lib/adapter/cypress-plugin/index.js +93 -105
  11. package/lib/adapter/jasmine.d.ts +11 -0
  12. package/lib/adapter/jasmine.js +54 -53
  13. package/lib/adapter/jest.d.ts +13 -0
  14. package/lib/adapter/jest.js +97 -99
  15. package/lib/adapter/mocha.d.ts +2 -0
  16. package/lib/adapter/mocha.js +112 -140
  17. package/lib/adapter/playwright.d.ts +14 -0
  18. package/lib/adapter/playwright.js +195 -231
  19. package/lib/adapter/vitest.d.ts +35 -0
  20. package/lib/adapter/vitest.js +150 -149
  21. package/lib/adapter/webdriver.d.ts +24 -0
  22. package/lib/adapter/webdriver.js +134 -119
  23. package/lib/bin/cli.d.ts +2 -0
  24. package/lib/bin/cli.js +164 -211
  25. package/lib/bin/reportXml.d.ts +2 -0
  26. package/lib/bin/reportXml.js +49 -52
  27. package/lib/bin/startTest.d.ts +2 -0
  28. package/lib/bin/startTest.js +82 -95
  29. package/lib/bin/uploadArtifacts.d.ts +2 -0
  30. package/lib/bin/uploadArtifacts.js +55 -61
  31. package/lib/client.d.ts +76 -0
  32. package/lib/client.js +411 -465
  33. package/lib/config.d.ts +1 -0
  34. package/lib/config.js +16 -21
  35. package/lib/constants.d.ts +25 -0
  36. package/lib/constants.js +50 -44
  37. package/lib/data-storage.d.ts +34 -0
  38. package/lib/data-storage.js +206 -188
  39. package/lib/junit-adapter/adapter.d.ts +9 -0
  40. package/lib/junit-adapter/adapter.js +17 -20
  41. package/lib/junit-adapter/csharp.d.ts +4 -0
  42. package/lib/junit-adapter/csharp.js +18 -14
  43. package/lib/junit-adapter/index.d.ts +3 -0
  44. package/lib/junit-adapter/index.js +27 -25
  45. package/lib/junit-adapter/java.d.ts +5 -0
  46. package/lib/junit-adapter/java.js +41 -53
  47. package/lib/junit-adapter/javascript.d.ts +4 -0
  48. package/lib/junit-adapter/javascript.js +30 -27
  49. package/lib/junit-adapter/python.d.ts +5 -0
  50. package/lib/junit-adapter/python.js +38 -37
  51. package/lib/junit-adapter/ruby.d.ts +4 -0
  52. package/lib/junit-adapter/ruby.js +11 -8
  53. package/lib/output.d.ts +11 -0
  54. package/lib/output.js +44 -52
  55. package/lib/package.json +3 -0
  56. package/lib/pipe/bitbucket.d.ts +23 -0
  57. package/lib/pipe/bitbucket.js +210 -229
  58. package/lib/pipe/csv.d.ts +47 -0
  59. package/lib/pipe/csv.js +113 -126
  60. package/lib/pipe/debug.d.ts +29 -0
  61. package/lib/pipe/debug.js +104 -99
  62. package/lib/pipe/github.d.ts +30 -0
  63. package/lib/pipe/github.js +186 -213
  64. package/lib/pipe/gitlab.d.ts +23 -0
  65. package/lib/pipe/gitlab.js +166 -207
  66. package/lib/pipe/html.d.ts +34 -0
  67. package/lib/pipe/html.js +260 -319
  68. package/lib/pipe/index.d.ts +1 -0
  69. package/lib/pipe/index.js +84 -66
  70. package/lib/pipe/testomatio.d.ts +70 -0
  71. package/lib/pipe/testomatio.js +413 -462
  72. package/lib/reporter-functions.d.ts +34 -0
  73. package/lib/reporter-functions.js +28 -26
  74. package/lib/reporter.d.ts +232 -0
  75. package/lib/reporter.js +34 -29
  76. package/lib/services/artifacts.d.ts +33 -0
  77. package/lib/services/artifacts.js +55 -51
  78. package/lib/services/index.d.ts +9 -0
  79. package/lib/services/index.js +14 -12
  80. package/lib/services/key-values.d.ts +27 -0
  81. package/lib/services/key-values.js +56 -53
  82. package/lib/services/logger.d.ts +64 -0
  83. package/lib/services/logger.js +227 -245
  84. package/lib/template/testomatio.hbs +651 -1366
  85. package/lib/uploader.d.ts +60 -0
  86. package/lib/uploader.js +291 -360
  87. package/lib/utils/pipe_utils.d.ts +41 -0
  88. package/lib/utils/pipe_utils.js +89 -85
  89. package/lib/utils/utils.d.ts +45 -0
  90. package/lib/utils/utils.js +347 -307
  91. package/lib/xmlReader.d.ts +92 -0
  92. package/lib/xmlReader.js +490 -529
  93. package/package.json +57 -15
  94. package/src/adapter/codecept.js +375 -0
  95. package/src/adapter/cucumber/current.js +228 -0
  96. package/src/adapter/cucumber/legacy.js +158 -0
  97. package/src/adapter/cucumber.js +4 -0
  98. package/src/adapter/cypress-plugin/index.js +112 -0
  99. package/src/adapter/jasmine.js +60 -0
  100. package/src/adapter/jest.js +107 -0
  101. package/src/adapter/mocha.cjs +2 -0
  102. package/src/adapter/mocha.js +157 -0
  103. package/src/adapter/playwright.js +250 -0
  104. package/src/adapter/vitest.js +183 -0
  105. package/src/adapter/webdriver.js +142 -0
  106. package/src/bin/cli.js +280 -0
  107. package/src/bin/reportXml.js +74 -0
  108. package/src/bin/startTest.js +123 -0
  109. package/src/bin/uploadArtifacts.js +90 -0
  110. package/src/client.js +504 -0
  111. package/src/config.js +30 -0
  112. package/src/constants.js +53 -0
  113. package/src/data-storage.js +204 -0
  114. package/src/junit-adapter/adapter.js +23 -0
  115. package/src/junit-adapter/csharp.js +16 -0
  116. package/src/junit-adapter/index.js +28 -0
  117. package/src/junit-adapter/java.js +58 -0
  118. package/src/junit-adapter/javascript.js +31 -0
  119. package/src/junit-adapter/python.js +42 -0
  120. package/src/junit-adapter/ruby.js +10 -0
  121. package/src/output.js +57 -0
  122. package/src/pipe/bitbucket.js +254 -0
  123. package/src/pipe/csv.js +140 -0
  124. package/src/pipe/debug.js +104 -0
  125. package/src/pipe/github.js +233 -0
  126. package/src/pipe/gitlab.js +229 -0
  127. package/src/pipe/html.js +374 -0
  128. package/src/pipe/index.js +71 -0
  129. package/src/pipe/testomatio.js +503 -0
  130. package/src/reporter-functions.js +55 -0
  131. package/src/reporter.cjs_decprecated +21 -0
  132. package/src/reporter.js +33 -0
  133. package/src/services/artifacts.js +59 -0
  134. package/src/services/index.js +13 -0
  135. package/src/services/key-values.js +59 -0
  136. package/src/services/logger.js +316 -0
  137. package/src/template/emptyData.svg +23 -0
  138. package/src/template/testomatio.hbs +706 -0
  139. package/src/uploader.js +371 -0
  140. package/src/utils/pipe_utils.js +119 -0
  141. package/src/utils/utils.js +383 -0
  142. package/src/xmlReader.js +562 -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,97 @@
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
+ // eslint-disable-next-line
44
+ error.inspect = function () {
45
+ return this.message;
46
+ };
47
+ }
48
+ const formattedError = error
49
+ ? {
50
+ message: error.message,
51
+ name: error.name,
52
+ inspect: error.inspect ||
53
+ // eslint-disable-next-line
54
+ function () {
55
+ return this.message;
56
+ },
57
+ }
58
+ : undefined;
59
+ const screenshots = Array.isArray(results.screenshots)
60
+ ? results.screenshots
61
+ .filter(screenshot => screenshot?.path && screenshot?.path.includes(title) && screenshot?.takenAt)
62
+ .map(screenshot => screenshot.path)
63
+ : [];
64
+ const files = [...videos, ...screenshots];
65
+ let state;
66
+ switch (test.state) {
67
+ case 'passed':
68
+ state = constants_js_1.STATUS.PASSED;
69
+ break;
70
+ case 'failed':
71
+ state = constants_js_1.STATUS.FAILED;
72
+ break;
73
+ case 'skipped':
74
+ case 'pending':
75
+ default:
76
+ state = constants_js_1.STATUS.SKIPPED;
77
+ }
78
+ addSpecTestsPromises.push(client.addTestRun(state, {
79
+ title,
80
+ time,
81
+ example,
82
+ error: formattedError,
83
+ files,
84
+ suite_title: suiteTitle,
85
+ test_id: testId,
86
+ suite_id: suiteId,
87
+ }));
88
+ }
89
+ await Promise.all(addSpecTestsPromises);
90
+ });
91
+ on('after:run', async (results) => {
92
+ const status = results.totalFailed ? constants_js_1.STATUS.FAILED : constants_js_1.STATUS.PASSED;
93
+ // @ts-ignore
94
+ await client.updateRunStatus(status);
95
+ });
107
96
  };
108
-
109
97
  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;