@testomatio/reporter 2.0.1-beta.3 → 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.
- package/lib/adapter/codecept.js +335 -293
- package/lib/adapter/cucumber/current.js +203 -195
- package/lib/adapter/cucumber/legacy.js +155 -130
- package/lib/adapter/cucumber.js +16 -5
- package/lib/adapter/cypress-plugin/index.js +105 -91
- package/lib/adapter/jasmine.js +53 -54
- package/lib/adapter/jest.js +99 -97
- package/lib/adapter/mocha.js +141 -112
- package/lib/adapter/playwright.js +231 -199
- package/lib/adapter/vitest.js +149 -150
- package/lib/adapter/webdriver.js +121 -144
- package/lib/bin/cli.js +211 -229
- package/lib/bin/reportXml.js +52 -51
- package/lib/bin/startTest.js +95 -83
- package/lib/bin/uploadArtifacts.js +61 -56
- package/lib/client.js +465 -424
- package/lib/config.js +23 -18
- package/lib/constants.js +44 -50
- package/lib/data-storage.js +188 -216
- package/lib/junit-adapter/adapter.js +20 -17
- package/lib/junit-adapter/csharp.js +14 -28
- package/lib/junit-adapter/index.js +25 -27
- package/lib/junit-adapter/java.js +53 -41
- package/lib/junit-adapter/javascript.js +27 -30
- package/lib/junit-adapter/python.js +37 -38
- package/lib/junit-adapter/ruby.js +8 -11
- package/lib/output.js +52 -44
- package/lib/pipe/bitbucket.js +230 -223
- package/lib/pipe/csv.js +126 -113
- package/lib/pipe/debug.js +99 -118
- package/lib/pipe/github.js +213 -218
- package/lib/pipe/gitlab.js +206 -183
- package/lib/pipe/html.js +321 -258
- package/lib/pipe/index.js +66 -94
- package/lib/pipe/testomatio.js +474 -429
- package/lib/reporter-functions.js +26 -28
- package/lib/reporter.js +29 -34
- package/lib/services/artifacts.js +51 -55
- package/lib/services/index.js +12 -14
- package/lib/services/key-values.js +53 -56
- package/lib/services/logger.js +245 -226
- package/lib/template/testomatio.hbs +1366 -1026
- package/lib/uploader.js +364 -295
- package/lib/utils/pipe_utils.js +85 -89
- package/lib/utils/utils.js +307 -398
- package/lib/xmlReader.js +532 -525
- package/package.json +21 -64
- package/lib/adapter/codecept.d.ts +0 -2
- package/lib/adapter/cucumber/current.d.ts +0 -14
- package/lib/adapter/cucumber/legacy.d.ts +0 -0
- package/lib/adapter/cucumber.d.ts +0 -2
- package/lib/adapter/cypress-plugin/index.d.ts +0 -2
- package/lib/adapter/jasmine.d.ts +0 -11
- package/lib/adapter/jest.d.ts +0 -13
- package/lib/adapter/mocha.d.ts +0 -2
- package/lib/adapter/nightwatch.d.ts +0 -4
- package/lib/adapter/nightwatch.js +0 -80
- package/lib/adapter/playwright.d.ts +0 -14
- package/lib/adapter/vitest.d.ts +0 -35
- package/lib/adapter/webdriver.d.ts +0 -24
- package/lib/bin/cli.d.ts +0 -2
- package/lib/bin/reportXml.d.ts +0 -2
- package/lib/bin/startTest.d.ts +0 -2
- package/lib/bin/uploadArtifacts.d.ts +0 -2
- package/lib/client.d.ts +0 -76
- package/lib/config.d.ts +0 -1
- package/lib/constants.d.ts +0 -25
- package/lib/data-storage.d.ts +0 -34
- package/lib/junit-adapter/adapter.d.ts +0 -9
- package/lib/junit-adapter/csharp.d.ts +0 -5
- package/lib/junit-adapter/index.d.ts +0 -3
- package/lib/junit-adapter/java.d.ts +0 -5
- package/lib/junit-adapter/javascript.d.ts +0 -4
- package/lib/junit-adapter/python.d.ts +0 -5
- package/lib/junit-adapter/ruby.d.ts +0 -4
- package/lib/output.d.ts +0 -11
- package/lib/package.json +0 -3
- package/lib/pipe/bitbucket.d.ts +0 -25
- package/lib/pipe/csv.d.ts +0 -47
- package/lib/pipe/debug.d.ts +0 -29
- package/lib/pipe/github.d.ts +0 -30
- package/lib/pipe/gitlab.d.ts +0 -25
- package/lib/pipe/html.d.ts +0 -35
- package/lib/pipe/index.d.ts +0 -1
- package/lib/pipe/testomatio.d.ts +0 -71
- package/lib/replay.d.ts +0 -31
- package/lib/replay.js +0 -237
- package/lib/reporter-functions.d.ts +0 -34
- package/lib/reporter.d.ts +0 -232
- package/lib/services/artifacts.d.ts +0 -33
- package/lib/services/index.d.ts +0 -9
- package/lib/services/key-values.d.ts +0 -27
- package/lib/services/logger.d.ts +0 -64
- package/lib/uploader.d.ts +0 -60
- package/lib/utils/pipe_utils.d.ts +0 -41
- package/lib/utils/utils.d.ts +0 -54
- package/lib/xmlReader.d.ts +0 -92
- package/src/adapter/codecept.js +0 -373
- package/src/adapter/cucumber/current.js +0 -228
- package/src/adapter/cucumber/legacy.js +0 -158
- package/src/adapter/cucumber.js +0 -4
- package/src/adapter/cypress-plugin/index.js +0 -110
- package/src/adapter/jasmine.js +0 -60
- package/src/adapter/jest.js +0 -107
- package/src/adapter/mocha.cjs +0 -2
- package/src/adapter/mocha.js +0 -156
- package/src/adapter/nightwatch.js +0 -88
- package/src/adapter/playwright.js +0 -254
- package/src/adapter/vitest.js +0 -183
- package/src/adapter/webdriver.js +0 -142
- package/src/bin/cli.js +0 -348
- package/src/bin/reportXml.js +0 -77
- package/src/bin/startTest.js +0 -124
- package/src/bin/uploadArtifacts.js +0 -91
- package/src/client.js +0 -508
- package/src/config.js +0 -30
- package/src/constants.js +0 -53
- package/src/data-storage.js +0 -204
- package/src/junit-adapter/adapter.js +0 -23
- package/src/junit-adapter/csharp.js +0 -28
- package/src/junit-adapter/index.js +0 -28
- package/src/junit-adapter/java.js +0 -58
- package/src/junit-adapter/javascript.js +0 -31
- package/src/junit-adapter/python.js +0 -42
- package/src/junit-adapter/ruby.js +0 -10
- package/src/output.js +0 -57
- package/src/pipe/bitbucket.js +0 -252
- package/src/pipe/csv.js +0 -140
- package/src/pipe/debug.js +0 -119
- package/src/pipe/github.js +0 -232
- package/src/pipe/gitlab.js +0 -247
- package/src/pipe/html.js +0 -373
- package/src/pipe/index.js +0 -71
- package/src/pipe/testomatio.js +0 -504
- package/src/replay.js +0 -245
- package/src/reporter-functions.js +0 -55
- package/src/reporter.cjs_decprecated +0 -21
- package/src/reporter.js +0 -33
- package/src/services/artifacts.js +0 -59
- package/src/services/index.js +0 -13
- package/src/services/key-values.js +0 -59
- package/src/services/logger.js +0 -315
- package/src/template/emptyData.svg +0 -23
- package/src/template/testomatio.hbs +0 -1081
- package/src/uploader.js +0 -376
- package/src/utils/pipe_utils.js +0 -119
- package/src/utils/utils.js +0 -416
- package/src/xmlReader.js +0 -614
package/src/xmlReader.js
DELETED
|
@@ -1,614 +0,0 @@
|
|
|
1
|
-
import createDebugMessages from 'debug';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import pc from 'picocolors';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import { XMLParser } from 'fast-xml-parser';
|
|
6
|
-
import { APP_PREFIX, STATUS } from './constants.js';
|
|
7
|
-
import { randomUUID } from 'crypto';
|
|
8
|
-
import { fileURLToPath } from 'url';
|
|
9
|
-
import {
|
|
10
|
-
fetchFilesFromStackTrace,
|
|
11
|
-
fetchIdFromOutput,
|
|
12
|
-
fetchSourceCode,
|
|
13
|
-
fetchSourceCodeFromStackTrace,
|
|
14
|
-
fetchIdFromCode,
|
|
15
|
-
humanize,
|
|
16
|
-
TEST_ID_REGEX,
|
|
17
|
-
} from './utils/utils.js';
|
|
18
|
-
import { pipesFactory } from './pipe/index.js';
|
|
19
|
-
import adapterFactory from './junit-adapter/index.js';
|
|
20
|
-
import { config } from './config.js';
|
|
21
|
-
import { S3Uploader } from './uploader.js';
|
|
22
|
-
|
|
23
|
-
// @ts-ignore this line will be removed in compiled code, because __dirname is defined in commonjs
|
|
24
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
25
|
-
const debug = createDebugMessages('@testomatio/reporter:xml');
|
|
26
|
-
|
|
27
|
-
const ridRunId = randomUUID();
|
|
28
|
-
|
|
29
|
-
const TESTOMATIO_URL = process.env.TESTOMATIO_URL || 'https://app.testomat.io';
|
|
30
|
-
const {
|
|
31
|
-
TESTOMATIO_RUNGROUP_TITLE,
|
|
32
|
-
TESTOMATIO_SUITE,
|
|
33
|
-
TESTOMATIO_MAX_STACK_TRACE,
|
|
34
|
-
TESTOMATIO_TITLE,
|
|
35
|
-
TESTOMATIO_ENV,
|
|
36
|
-
TESTOMATIO_RUN,
|
|
37
|
-
TESTOMATIO_MARK_DETACHED,
|
|
38
|
-
} = process.env;
|
|
39
|
-
|
|
40
|
-
const options = {
|
|
41
|
-
ignoreDeclaration: true,
|
|
42
|
-
ignoreAttributes: false,
|
|
43
|
-
alwaysCreateTextNode: false,
|
|
44
|
-
attributeNamePrefix: '',
|
|
45
|
-
parseTagValue: true,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const MAX_OUTPUT_LENGTH = parseInt(TESTOMATIO_MAX_STACK_TRACE, 10) || 10000;
|
|
49
|
-
|
|
50
|
-
const reduceOptions = {};
|
|
51
|
-
|
|
52
|
-
class XmlReader {
|
|
53
|
-
constructor(opts = {}) {
|
|
54
|
-
this.requestParams = {
|
|
55
|
-
apiKey: opts.apiKey || config.TESTOMATIO,
|
|
56
|
-
url: opts.url || TESTOMATIO_URL,
|
|
57
|
-
title: TESTOMATIO_TITLE,
|
|
58
|
-
env: TESTOMATIO_ENV,
|
|
59
|
-
group_title: TESTOMATIO_RUNGROUP_TITLE,
|
|
60
|
-
detach: TESTOMATIO_MARK_DETACHED,
|
|
61
|
-
// batch uploading is implemented for xml already
|
|
62
|
-
isBatchEnabled: false,
|
|
63
|
-
};
|
|
64
|
-
this.runId = opts.runId || TESTOMATIO_RUN;
|
|
65
|
-
this.adapter = adapterFactory(opts.lang?.toLowerCase(), opts);
|
|
66
|
-
if (!this.adapter) throw new Error('XML adapter for this format not found');
|
|
67
|
-
|
|
68
|
-
this.opts = opts || {};
|
|
69
|
-
this.store = {};
|
|
70
|
-
this.pipesPromise = pipesFactory(opts, this.store);
|
|
71
|
-
|
|
72
|
-
this.parser = new XMLParser(options);
|
|
73
|
-
this.tests = [];
|
|
74
|
-
this.stats = {};
|
|
75
|
-
this.stats.language = opts.lang?.toLowerCase();
|
|
76
|
-
this.uploader = new S3Uploader();
|
|
77
|
-
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
const packageJsonPath = path.resolve(__dirname, '..', 'package.json');
|
|
80
|
-
this.version = JSON.parse(fs.readFileSync(packageJsonPath).toString()).version;
|
|
81
|
-
console.log(APP_PREFIX, `Testomatio Reporter v${this.version}`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
connectAdapter() {
|
|
85
|
-
if (this.opts.javaTests) {
|
|
86
|
-
this.adapter = adapterFactory('java', this.opts);
|
|
87
|
-
return this.adapter;
|
|
88
|
-
}
|
|
89
|
-
this.adapter = adapterFactory(this.stats.language, this.opts);
|
|
90
|
-
return this.adapter;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
parse(fileName) {
|
|
94
|
-
let xmlData = fs.readFileSync(path.resolve(fileName)).toString();
|
|
95
|
-
|
|
96
|
-
// we remove too long stack traces
|
|
97
|
-
const cutRegexes = [
|
|
98
|
-
/(<output><!\[CDATA\[)([\s\S]*?)(\]\]><\/output>)/g,
|
|
99
|
-
/(<system-err><!\[CDATA\[)([\s\S]*?)(\]\]><\/system-err>)/g,
|
|
100
|
-
/(<system-out><!\[CDATA\[)([\s\S]*?)(\]\]><\/system-out>)/g,
|
|
101
|
-
];
|
|
102
|
-
|
|
103
|
-
for (const regex of cutRegexes) {
|
|
104
|
-
xmlData = xmlData.replace(regex, (_, p1, p2, p3) => `${p1}${p2.substring(0, MAX_OUTPUT_LENGTH)}${p3}`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const jsonResult = this.parser.parse(xmlData);
|
|
108
|
-
let jsonSuite;
|
|
109
|
-
|
|
110
|
-
if (jsonResult.testsuites) {
|
|
111
|
-
jsonSuite = jsonResult.testsuites;
|
|
112
|
-
} else if (jsonResult.testsuite) {
|
|
113
|
-
jsonSuite = jsonResult;
|
|
114
|
-
} else if (jsonResult.TestRun) {
|
|
115
|
-
return this.processTRX(jsonResult);
|
|
116
|
-
} else if (jsonResult['test-run']) {
|
|
117
|
-
return this.processNUnit(jsonResult['test-run']);
|
|
118
|
-
} else if (jsonResult.assemblies) {
|
|
119
|
-
return this.processXUnit(jsonResult.assemblies);
|
|
120
|
-
} else {
|
|
121
|
-
console.log(jsonResult);
|
|
122
|
-
throw new Error("Format can't be parsed");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return this.processJUnit(jsonSuite);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
processJUnit(jsonSuite) {
|
|
129
|
-
const { testsuite, name, tests, failures, errors } = jsonSuite;
|
|
130
|
-
|
|
131
|
-
reduceOptions.preferClassname = this.stats.language === 'python';
|
|
132
|
-
const resultTests = processTestSuite(testsuite);
|
|
133
|
-
|
|
134
|
-
const hasFailures = resultTests.filter(t => t.status === 'failed').length > 0;
|
|
135
|
-
const status = failures > 0 || errors > 0 || hasFailures ? 'failed' : 'passed';
|
|
136
|
-
|
|
137
|
-
const time = testsuite.time || 0;
|
|
138
|
-
// debug('time', jsonSuite, time)
|
|
139
|
-
if (time) {
|
|
140
|
-
if (!this.stats.duration) this.stats.duration = 0;
|
|
141
|
-
this.stats.duration += parseFloat(time);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
this.tests = this.tests.concat(resultTests);
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
create_tests: true,
|
|
148
|
-
duration: parseFloat(time),
|
|
149
|
-
failed_count: parseInt(failures, 10),
|
|
150
|
-
name,
|
|
151
|
-
passed_count: parseInt(tests, 10) - parseInt(failures, 10),
|
|
152
|
-
skipped_count: 0,
|
|
153
|
-
status,
|
|
154
|
-
tests: resultTests,
|
|
155
|
-
tests_count: parseInt(tests, 10),
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
processNUnit(jsonSuite) {
|
|
160
|
-
const { result, total, passed, failed, inconclusive, skipped } = jsonSuite;
|
|
161
|
-
|
|
162
|
-
reduceOptions.preferClassname = this.stats.language === 'python';
|
|
163
|
-
const resultTests = processTestSuite(jsonSuite['test-suite']);
|
|
164
|
-
|
|
165
|
-
this.tests = this.tests.concat(resultTests);
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
status: result?.toLowerCase(),
|
|
169
|
-
create_tests: true,
|
|
170
|
-
tests_count: parseInt(total, 10),
|
|
171
|
-
passed_count: parseInt(passed, 10),
|
|
172
|
-
failed_count: parseInt(failed, 10),
|
|
173
|
-
skipped_count: parseInt(inconclusive + skipped, 10),
|
|
174
|
-
tests: resultTests,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
processTRX(jsonSuite) {
|
|
179
|
-
let defs = jsonSuite?.TestRun?.TestDefinitions?.UnitTest;
|
|
180
|
-
if (!Array.isArray(defs)) defs = [defs].filter(d => !!d);
|
|
181
|
-
|
|
182
|
-
const tests =
|
|
183
|
-
defs.map(td => {
|
|
184
|
-
const title = td.name.replace(/\(.*?\)/, '').trim();
|
|
185
|
-
let example = td.name.match(/\((.*?)\)/);
|
|
186
|
-
if (example) example = { ...example[1].split(',') };
|
|
187
|
-
const suite = td.TestMethod.className.split(', ')[0].split('.');
|
|
188
|
-
const suite_title = suite.pop();
|
|
189
|
-
return {
|
|
190
|
-
title,
|
|
191
|
-
example,
|
|
192
|
-
file: suite.join('/'),
|
|
193
|
-
description: td.Description,
|
|
194
|
-
suite_title,
|
|
195
|
-
id: td.Execution.id,
|
|
196
|
-
};
|
|
197
|
-
}) || [];
|
|
198
|
-
|
|
199
|
-
let result = jsonSuite?.TestRun?.Results?.UnitTestResult;
|
|
200
|
-
if (!Array.isArray(result)) result = [result].filter(d => !!d);
|
|
201
|
-
|
|
202
|
-
const results = result.map(td => ({
|
|
203
|
-
id: td.executionId,
|
|
204
|
-
// seconds are used in junit reports, but ms are used by testomatio
|
|
205
|
-
run_time: parseFloat(td.duration) * 1000,
|
|
206
|
-
status: td.outcome,
|
|
207
|
-
stack: td.Output.StdOut,
|
|
208
|
-
files: td?.ResultFiles?.ResultFile?.map(rf => rf.path),
|
|
209
|
-
}));
|
|
210
|
-
|
|
211
|
-
results.forEach(r => {
|
|
212
|
-
const test = tests.find(t => t.id === r.id) || {};
|
|
213
|
-
r.suite_title = test.suite_title;
|
|
214
|
-
r.title = test.title?.trim();
|
|
215
|
-
if (test.code) r.code = test.code;
|
|
216
|
-
if (test.description) r.description = test.description;
|
|
217
|
-
if (test.example) r.example = test.example;
|
|
218
|
-
if (test.file) r.file = test.file;
|
|
219
|
-
r.create = true;
|
|
220
|
-
if (r.status === 'Passed') r.status = STATUS.PASSED;
|
|
221
|
-
if (r.status === 'Failed') r.status = STATUS.FAILED;
|
|
222
|
-
if (r.status === 'Skipped') r.status = STATUS.SKIPPED;
|
|
223
|
-
delete r.id;
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
debug(results);
|
|
227
|
-
|
|
228
|
-
const counters = jsonSuite?.TestRun?.ResultSummary?.Counters || {};
|
|
229
|
-
|
|
230
|
-
const failed_count = parseInt(counters.failed, 10) + parseInt(counters.error, 10);
|
|
231
|
-
|
|
232
|
-
let status = STATUS.PASSED.toString();
|
|
233
|
-
if (failed_count > 0) status = STATUS.FAILED;
|
|
234
|
-
|
|
235
|
-
this.tests = results.filter(t => !!t.title);
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
status,
|
|
239
|
-
create_tests: !process.env.IGNORE_NEW_TESTS,
|
|
240
|
-
tests_count: parseInt(counters.total, 10),
|
|
241
|
-
passed_count: parseInt(counters.passed, 10),
|
|
242
|
-
skipped_count: parseInt(counters.notExecuted, 10),
|
|
243
|
-
failed_count,
|
|
244
|
-
tests: results,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
processXUnit(assemblies) {
|
|
249
|
-
const tests = [];
|
|
250
|
-
|
|
251
|
-
assemblies = Array.isArray(assemblies.assembly) ? assemblies.assembly : [assemblies.assembly];
|
|
252
|
-
|
|
253
|
-
assemblies.forEach(assembly => {
|
|
254
|
-
const { collection } = assembly;
|
|
255
|
-
|
|
256
|
-
const suites = Array.isArray(collection) ? collection : [collection];
|
|
257
|
-
|
|
258
|
-
suites.forEach(suite => {
|
|
259
|
-
const { test } = suite;
|
|
260
|
-
if (!test) return;
|
|
261
|
-
const cases = Array.isArray(test) ? test : [test];
|
|
262
|
-
cases.forEach(testCase => {
|
|
263
|
-
const { type, time, result } = testCase;
|
|
264
|
-
|
|
265
|
-
let message = '';
|
|
266
|
-
let stack = '';
|
|
267
|
-
|
|
268
|
-
if (testCase.failure) {
|
|
269
|
-
message = testCase.failure.message;
|
|
270
|
-
stack = testCase.failure['stack-trace'];
|
|
271
|
-
}
|
|
272
|
-
if (testCase.reason) {
|
|
273
|
-
message = testCase.reason.message;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
let status = STATUS.PASSED;
|
|
277
|
-
if (result === 'Pass') status = STATUS.PASSED;
|
|
278
|
-
if (result === 'Fail') status = STATUS.FAILED;
|
|
279
|
-
if (result === 'Skip') status = STATUS.SKIPPED;
|
|
280
|
-
|
|
281
|
-
const pathParts = type.split('.');
|
|
282
|
-
const suite_title = pathParts[pathParts.length - 1];
|
|
283
|
-
const file = pathParts.slice(0, -1).join('/');
|
|
284
|
-
const title = testCase.method || testCase.name.split('.').pop();
|
|
285
|
-
const run_time = parseFloat(time) * 1000;
|
|
286
|
-
|
|
287
|
-
tests.push({
|
|
288
|
-
create: true,
|
|
289
|
-
stack,
|
|
290
|
-
message,
|
|
291
|
-
file,
|
|
292
|
-
status,
|
|
293
|
-
title,
|
|
294
|
-
suite_title,
|
|
295
|
-
run_time,
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
const hasFailures = tests.filter(t => t.status === STATUS.FAILED).length > 0;
|
|
302
|
-
const status = hasFailures ? STATUS.FAILED : STATUS.PASSED;
|
|
303
|
-
|
|
304
|
-
this.tests = tests;
|
|
305
|
-
|
|
306
|
-
debug(tests);
|
|
307
|
-
|
|
308
|
-
return {
|
|
309
|
-
status,
|
|
310
|
-
create_tests: true,
|
|
311
|
-
name: 'xUnit',
|
|
312
|
-
tests_count: tests.length,
|
|
313
|
-
passed_count: tests.filter(t => t.status === STATUS.PASSED).length,
|
|
314
|
-
failed_count: tests.filter(t => t.status === STATUS.FAILED).length,
|
|
315
|
-
skipped_count: tests.filter(t => t.status === STATUS.SKIPPED).length,
|
|
316
|
-
tests,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
calculateStats() {
|
|
321
|
-
this.stats = {
|
|
322
|
-
...this.stats,
|
|
323
|
-
detach: this.requestParams.detach,
|
|
324
|
-
status: 'passed',
|
|
325
|
-
create_tests: true,
|
|
326
|
-
tests_count: 0,
|
|
327
|
-
passed_count: 0,
|
|
328
|
-
failed_count: 0,
|
|
329
|
-
skipped_count: 0,
|
|
330
|
-
};
|
|
331
|
-
this.tests.forEach(t => {
|
|
332
|
-
this.stats.tests_count++;
|
|
333
|
-
if (t.status === 'passed') this.stats.passed_count++;
|
|
334
|
-
if (t.status === 'failed') this.stats.failed_count++;
|
|
335
|
-
});
|
|
336
|
-
if (this.stats.failed_count) this.stats.status = 'failed';
|
|
337
|
-
|
|
338
|
-
return this.stats;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
fetchSourceCode() {
|
|
342
|
-
this.tests.forEach(t => {
|
|
343
|
-
try {
|
|
344
|
-
const file = this.adapter.getFilePath(t);
|
|
345
|
-
if (!file) return;
|
|
346
|
-
|
|
347
|
-
if (!this.stats.language) {
|
|
348
|
-
if (file.endsWith('.php')) this.stats.language = 'php';
|
|
349
|
-
if (file.endsWith('.py')) this.stats.language = 'python';
|
|
350
|
-
if (file.endsWith('.java')) this.stats.language = 'java';
|
|
351
|
-
if (file.endsWith('.rb')) this.stats.language = 'ruby';
|
|
352
|
-
if (file.endsWith('.js')) this.stats.language = 'js';
|
|
353
|
-
if (file.endsWith('.ts')) this.stats.language = 'ts';
|
|
354
|
-
if (file.endsWith('.cs')) this.stats.language = 'csharp';
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if (!fs.existsSync(file)) {
|
|
358
|
-
debug('Failed to open file with the source code', file);
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
const contents = fs.readFileSync(file).toString();
|
|
362
|
-
t.code = fetchSourceCode(contents, { ...t, lang: this.stats.language });
|
|
363
|
-
if (t.code) debug('Fetched code for test %s', t.title);
|
|
364
|
-
t.test_id = fetchIdFromCode(t.code, { lang: this.stats.language });
|
|
365
|
-
if (t.test_id) debug('Fetched test id %s for test %s', t.test_id, t.title);
|
|
366
|
-
} catch (err) {
|
|
367
|
-
debug(err);
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
formatTests() {
|
|
373
|
-
this.tests.forEach(t => {
|
|
374
|
-
if (t.file) {
|
|
375
|
-
t.file = t.file.replace(process.cwd() + path.sep, '');
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
this.adapter.formatTest(t);
|
|
379
|
-
|
|
380
|
-
t.title = humanize(t.title);
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
formatErrors() {
|
|
385
|
-
this.tests
|
|
386
|
-
.filter(t => !!t.stack)
|
|
387
|
-
.forEach(t => {
|
|
388
|
-
t.stack = this.formatStack(t);
|
|
389
|
-
t.message = this.adapter.formatMessage(t);
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
formatStack(t) {
|
|
394
|
-
const stack = this.adapter.formatStack(t);
|
|
395
|
-
|
|
396
|
-
const sourcePart = fetchSourceCodeFromStackTrace(stack);
|
|
397
|
-
|
|
398
|
-
if (!sourcePart) return stack;
|
|
399
|
-
|
|
400
|
-
const separator = pc.bold(pc.red('################[ Failure ]################'));
|
|
401
|
-
|
|
402
|
-
return `${stack}\n\n${separator}\n${fetchSourceCodeFromStackTrace(stack)}`;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
async uploadArtifacts() {
|
|
406
|
-
for (const test of this.tests.filter(t => !!t.stack)) {
|
|
407
|
-
let files = [];
|
|
408
|
-
if (!test.files?.length) continue;
|
|
409
|
-
|
|
410
|
-
files = test.files.map(f => (path.isAbsolute(f) ? f : path.join(process.cwd(), f)));
|
|
411
|
-
|
|
412
|
-
if (!files.length) continue;
|
|
413
|
-
|
|
414
|
-
const runId = this.runId || this.store.runId || Date.now().toString();
|
|
415
|
-
test.artifacts = await Promise.all(files.map(f => this.uploader.uploadFileByPath(f, [runId, path.basename(f)])));
|
|
416
|
-
console.log(APP_PREFIX, `🗄️ Uploaded ${pc.bold(`${files.length} artifacts`)} for test ${test.title}`);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
async createRun() {
|
|
421
|
-
const runParams = {
|
|
422
|
-
api_key: this.requestParams.apiKey,
|
|
423
|
-
title: this.requestParams.title,
|
|
424
|
-
env: this.requestParams.env,
|
|
425
|
-
group_title: this.requestParams.group_title,
|
|
426
|
-
isBatchEnabled: this.requestParams.isBatchEnabled,
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
debug('Run', runParams);
|
|
430
|
-
this.pipes = this.pipes || (await this.pipesPromise);
|
|
431
|
-
|
|
432
|
-
const run = await Promise.all(this.pipes.map(p => p.createRun(runParams)));
|
|
433
|
-
this.uploader.checkEnabled();
|
|
434
|
-
return run;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
async uploadData() {
|
|
438
|
-
await this.uploadArtifacts();
|
|
439
|
-
this.calculateStats();
|
|
440
|
-
this.connectAdapter();
|
|
441
|
-
this.fetchSourceCode();
|
|
442
|
-
this.formatErrors();
|
|
443
|
-
this.formatTests();
|
|
444
|
-
|
|
445
|
-
const dataString = {
|
|
446
|
-
...this.stats,
|
|
447
|
-
api_key: this.requestParams.apiKey,
|
|
448
|
-
status: 'finished',
|
|
449
|
-
duration: this.stats.duration,
|
|
450
|
-
tests: this.tests,
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
debug('Uploading data', dataString);
|
|
454
|
-
|
|
455
|
-
this.pipes = this.pipes || (await this.pipesPromise);
|
|
456
|
-
return Promise.all(this.pipes.map(p => p.finishRun(dataString)));
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
async _finishRun() {
|
|
460
|
-
this.pipes = this.pipes || (await this.pipesPromise);
|
|
461
|
-
return Promise.all(this.pipes.map(p => p.finishRun({ status: 'finished' })));
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
export default XmlReader;
|
|
466
|
-
|
|
467
|
-
function reduceTestCases(prev, item) {
|
|
468
|
-
let testCases = item.testcase;
|
|
469
|
-
if (!testCases) testCases = item['test-case'];
|
|
470
|
-
if (!Array.isArray(testCases)) {
|
|
471
|
-
testCases = [testCases];
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// suite inside test case
|
|
475
|
-
const testCase = item['test-suite']?.['test-case'];
|
|
476
|
-
if (testCase) {
|
|
477
|
-
const nestedCases = Array.isArray(testCase) ? testCase : [testCase];
|
|
478
|
-
testCases.push(...nestedCases);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
const suiteOutput = item['system-out'] || item.output || item.log || '';
|
|
482
|
-
const suiteErr = item['system-err'] || item.output || item.log || '';
|
|
483
|
-
testCases
|
|
484
|
-
.filter(t => !!t)
|
|
485
|
-
.forEach(testCaseItem => {
|
|
486
|
-
const file = testCaseItem.file || item.filepath || item.fullname || '';
|
|
487
|
-
|
|
488
|
-
let stack = '';
|
|
489
|
-
let message = '';
|
|
490
|
-
if (testCaseItem.error) stack = testCaseItem.error;
|
|
491
|
-
if (testCaseItem.failure) stack = testCaseItem.failure;
|
|
492
|
-
if (testCaseItem?.failure?.['stack-trace']) stack = testCaseItem.failure['stack-trace'];
|
|
493
|
-
if (testCaseItem?.failure?.message) message = testCaseItem.failure.message;
|
|
494
|
-
if (testCaseItem?.error?.message) message = testCaseItem.error.message;
|
|
495
|
-
|
|
496
|
-
if (testCaseItem.failure && testCaseItem.failure['#text']) stack = testCaseItem.failure['#text'];
|
|
497
|
-
if (testCaseItem.error && testCaseItem.error['#text']) stack = testCaseItem.error['#text'];
|
|
498
|
-
if (!message) message = stack.trim().split('\n')[0];
|
|
499
|
-
|
|
500
|
-
const isParametrized = item.type === 'ParameterizedMethod';
|
|
501
|
-
const preferClassname = reduceOptions.preferClassname || isParametrized;
|
|
502
|
-
|
|
503
|
-
// SpecFlow config
|
|
504
|
-
let { title, tags, testId } = fetchProperties(isParametrized ? item : testCaseItem);
|
|
505
|
-
let example = null;
|
|
506
|
-
const suiteTitle = preferClassname ? testCaseItem.classname : item.name || testCaseItem.classname;
|
|
507
|
-
|
|
508
|
-
title ||= testCaseItem.name || testCaseItem.methodname || testCaseItem.classname;
|
|
509
|
-
tags ||= [];
|
|
510
|
-
|
|
511
|
-
const exampleMatches = testCaseItem.name?.match(/\S\((.*?)\)/);
|
|
512
|
-
if (exampleMatches) {
|
|
513
|
-
example = { ...exampleMatches[1].split(',').map(v => v.trim().replace(/[^\w\s-]/g, '')) };
|
|
514
|
-
title = title.replace(/\(.*?\)/, '').trim();
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
stack = `${
|
|
518
|
-
testCaseItem['system-out'] || testCaseItem.output || testCaseItem.log || ''
|
|
519
|
-
}\n\n${stack}\n\n${suiteOutput}\n\n${suiteErr}`.trim();
|
|
520
|
-
|
|
521
|
-
if (!testId) testId = fetchIdFromOutput(stack);
|
|
522
|
-
|
|
523
|
-
if (tags?.length && !testId) {
|
|
524
|
-
testId = tags
|
|
525
|
-
.filter(t => t.startsWith('T'))
|
|
526
|
-
.map(t => `@${t}`)
|
|
527
|
-
.find(t => t.match(TEST_ID_REGEX))
|
|
528
|
-
?.slice(2);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
let status = STATUS.PASSED.toString();
|
|
532
|
-
if ('failure' in testCaseItem || 'error' in testCaseItem) status = STATUS.FAILED;
|
|
533
|
-
if ('skipped' in testCaseItem) status = STATUS.SKIPPED;
|
|
534
|
-
if (testCaseItem.result && Object.values(STATUS).includes(testCaseItem.result.toLowerCase())) {
|
|
535
|
-
status = testCaseItem.result.toLowerCase();
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
let rid = null;
|
|
539
|
-
if (testCaseItem.id) rid = `${ridRunId}-${testCaseItem.id}`;
|
|
540
|
-
|
|
541
|
-
// Extract attachments
|
|
542
|
-
let files = [];
|
|
543
|
-
if (testCaseItem.attachments) {
|
|
544
|
-
const attachments = Array.isArray(testCaseItem.attachments.attachment)
|
|
545
|
-
? testCaseItem.attachments.attachment
|
|
546
|
-
: [testCaseItem.attachments.attachment];
|
|
547
|
-
|
|
548
|
-
files = attachments.filter(a => a && a.filePath).map(a => a.filePath);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// Extract files from stack trace using existing utility
|
|
552
|
-
const stackFiles = fetchFilesFromStackTrace(stack);
|
|
553
|
-
files = [...new Set([...files, ...stackFiles])]; // Remove duplicates
|
|
554
|
-
|
|
555
|
-
prev.push({
|
|
556
|
-
rid,
|
|
557
|
-
file,
|
|
558
|
-
stack,
|
|
559
|
-
example,
|
|
560
|
-
tags,
|
|
561
|
-
create: true,
|
|
562
|
-
test_id: testId,
|
|
563
|
-
message,
|
|
564
|
-
line: testCaseItem.lineno,
|
|
565
|
-
// seconds are used in junit reports, but ms are used by testomatio
|
|
566
|
-
run_time: parseFloat(testCaseItem.time || testCaseItem.duration) * 1000,
|
|
567
|
-
status,
|
|
568
|
-
title,
|
|
569
|
-
root_suite_id: TESTOMATIO_SUITE,
|
|
570
|
-
suite_title: suiteTitle,
|
|
571
|
-
files,
|
|
572
|
-
});
|
|
573
|
-
});
|
|
574
|
-
return prev;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
function processTestSuite(testsuite) {
|
|
578
|
-
if (!testsuite) return [];
|
|
579
|
-
if (testsuite.testsuite) return processTestSuite(testsuite.testsuite);
|
|
580
|
-
if (testsuite['test-suite'] && !testsuite['test-case']) return processTestSuite(testsuite['test-suite']);
|
|
581
|
-
|
|
582
|
-
let suites = testsuite;
|
|
583
|
-
if (!Array.isArray(testsuite)) {
|
|
584
|
-
suites = [testsuite];
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
const subSuites = suites.filter(s => s['test-suite'] && !testsuite['test-case']);
|
|
588
|
-
|
|
589
|
-
return [...subSuites.map(s => processTestSuite(s['test-suite'])), ...suites.reduce(reduceTestCases, [])].flat();
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
function fetchProperties(item) {
|
|
593
|
-
const tags = [];
|
|
594
|
-
let title = '';
|
|
595
|
-
|
|
596
|
-
if (!item.properties) return {};
|
|
597
|
-
|
|
598
|
-
// Handle both single property and array of properties
|
|
599
|
-
const properties = Array.isArray(item.properties.property)
|
|
600
|
-
? item.properties.property
|
|
601
|
-
: [item.properties.property].filter(Boolean);
|
|
602
|
-
|
|
603
|
-
const prop = properties.find(p => p.name === 'Description');
|
|
604
|
-
if (prop) title = prop.value;
|
|
605
|
-
|
|
606
|
-
let testId = properties.find(p => p.name === 'ID')?.value;
|
|
607
|
-
|
|
608
|
-
if (testId?.startsWith('@')) testId = testId.slice(1);
|
|
609
|
-
if (testId?.startsWith('T')) testId = testId.slice(1);
|
|
610
|
-
|
|
611
|
-
properties.filter(p => p.name === 'Category').forEach(p => tags.push(p.value));
|
|
612
|
-
|
|
613
|
-
return { title, tags, testId };
|
|
614
|
-
}
|