@testomatio/reporter 2.3.7 → 2.3.8
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/README.md +2 -1
- package/lib/bin/cli.js +14 -4
- package/lib/bin/reportXml.js +5 -2
- package/lib/client.d.ts +1 -1
- package/lib/client.js +2 -2
- package/lib/junit-adapter/csharp.d.ts +0 -1
- package/lib/junit-adapter/csharp.js +40 -7
- package/lib/junit-adapter/nunit-parser.d.ts +82 -0
- package/lib/junit-adapter/nunit-parser.js +431 -0
- package/lib/pipe/testomatio.d.ts +2 -1
- package/lib/pipe/testomatio.js +2 -1
- package/lib/uploader.js +4 -0
- package/lib/utils/utils.js +182 -21
- package/lib/xmlReader.d.ts +32 -26
- package/lib/xmlReader.js +111 -52
- package/package.json +8 -4
- package/src/bin/cli.js +16 -4
- package/src/bin/reportXml.js +5 -2
- package/src/client.js +2 -2
- package/src/junit-adapter/csharp.js +45 -6
- package/src/junit-adapter/nunit-parser.js +472 -0
- package/src/pipe/testomatio.js +2 -1
- package/src/uploader.js +5 -0
- package/src/utils/utils.js +195 -19
- package/src/xmlReader.js +134 -46
- package/types/types.d.ts +364 -0
- package/types/vitest.types.d.ts +93 -0
package/src/utils/utils.js
CHANGED
|
@@ -76,21 +76,29 @@ const isValidUrl = s => {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
-
const fileMatchRegex = /file:(
|
|
79
|
+
const fileMatchRegex = /file:(\/*)([A-Za-z]:[\\/].*?|\/.*?)\.(png|avi|webm|jpg|html|txt)/gi;
|
|
80
80
|
|
|
81
81
|
const fetchFilesFromStackTrace = (stack = '', checkExists = true) => {
|
|
82
|
-
|
|
83
|
-
.map(
|
|
82
|
+
let files = Array.from(stack.matchAll(fileMatchRegex))
|
|
83
|
+
.map(match => {
|
|
84
|
+
// match[0] is full match, match[1] is slashes, match[2] is path, match[3] is extension
|
|
85
|
+
const slashes = match[1] || '';
|
|
86
|
+
const path = match[2];
|
|
87
|
+
const extension = match[3];
|
|
88
|
+
return `${slashes}${path}.${extension}`;
|
|
89
|
+
})
|
|
90
|
+
.map(f => f.trim())
|
|
84
91
|
.map(f => f.replace(/^\/+/, '/').replace(/^\/([A-Za-z]:)/, '$1')) // Remove extra slashes, handle Windows paths
|
|
85
92
|
.map(f => {
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
// Convert Windows path to Linux equivalent for test scenarios
|
|
89
|
-
return f.replace(/^[A-Za-z]:[\\\/]/, '/').replace(/\\/g, '/');
|
|
90
|
-
}
|
|
91
|
-
return f;
|
|
93
|
+
// Normalize path separators for cross-platform compatibility
|
|
94
|
+
return f.replace(/\\/g, '/');
|
|
92
95
|
});
|
|
93
96
|
|
|
97
|
+
// If we're not checking file existence, remove Windows drive letters for consistency
|
|
98
|
+
if (!checkExists) {
|
|
99
|
+
files = files.map(f => f.replace(/^([A-Za-z]):/, ''));
|
|
100
|
+
}
|
|
101
|
+
|
|
94
102
|
debug('Found files in stack trace: ', files);
|
|
95
103
|
|
|
96
104
|
return files.filter(f => {
|
|
@@ -105,21 +113,92 @@ const fetchSourceCodeFromStackTrace = (stack = '') => {
|
|
|
105
113
|
const stackLines = stack
|
|
106
114
|
.split('\n')
|
|
107
115
|
.filter(l => l.includes(':'))
|
|
108
|
-
// .map(l => l.match(/\[(.*?)\]/)?.[1] || l) // minitest format
|
|
109
|
-
// .map(l => l.split(':')[0])
|
|
110
116
|
.map(l => l.trim())
|
|
111
|
-
.map(l =>
|
|
112
|
-
|
|
117
|
+
.map(l => {
|
|
118
|
+
// Remove 'at ' prefix if present
|
|
119
|
+
if (l.startsWith('at ')) {
|
|
120
|
+
return l.substring(3).trim();
|
|
121
|
+
}
|
|
122
|
+
// Find the part that looks like a file path with line number
|
|
123
|
+
const parts = l.split(' ');
|
|
124
|
+
for (const part of parts) {
|
|
125
|
+
// Check if this part has a colon
|
|
126
|
+
if (part.includes(':')) {
|
|
127
|
+
// For Windows paths, we need to handle drive letters (C:, D:, etc.)
|
|
128
|
+
// Split by colon but keep drive letter with the path
|
|
129
|
+
const colonParts = part.split(':');
|
|
130
|
+
let filePath;
|
|
131
|
+
|
|
132
|
+
// Check if first part is a Windows drive letter (single letter)
|
|
133
|
+
if (colonParts.length >= 2 && colonParts[0].length === 1 && /[A-Za-z]/.test(colonParts[0])) {
|
|
134
|
+
// Windows path like D:\path\file.php:24
|
|
135
|
+
// Reconstruct as D:\path\file.php
|
|
136
|
+
filePath = colonParts[0] + ':' + colonParts[1];
|
|
137
|
+
} else {
|
|
138
|
+
// Unix path like /path/file.php:24
|
|
139
|
+
filePath = colonParts[0];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Only consider it valid if the file exists
|
|
143
|
+
if (fs.existsSync(filePath)) {
|
|
144
|
+
return part;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// If no valid file path found in parts, return the whole line
|
|
149
|
+
// It will be filtered out later if it's not a valid file path
|
|
150
|
+
return parts.find(p => p.includes(':')) || l;
|
|
151
|
+
})
|
|
152
|
+
.filter(l => {
|
|
153
|
+
// Extract file path from line (accounting for Windows drive letters)
|
|
154
|
+
if (!l) return false;
|
|
155
|
+
const colonParts = l.split(':');
|
|
156
|
+
let filePath;
|
|
157
|
+
|
|
158
|
+
if (colonParts.length >= 2 && colonParts[0].length === 1 && /[A-Za-z]/.test(colonParts[0])) {
|
|
159
|
+
// Windows path
|
|
160
|
+
filePath = colonParts[0] + ':' + colonParts[1];
|
|
161
|
+
} else {
|
|
162
|
+
// Unix path
|
|
163
|
+
filePath = colonParts[0];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return filePath && fs.existsSync(filePath);
|
|
167
|
+
})
|
|
113
168
|
|
|
114
169
|
// // filter out 3rd party libs
|
|
115
170
|
.filter(l => !l?.includes(`vendor${sep}`))
|
|
116
171
|
.filter(l => !l?.includes(`node_modules${sep}`))
|
|
117
|
-
.filter(l =>
|
|
118
|
-
|
|
172
|
+
.filter(l => {
|
|
173
|
+
// Extract file path for final check (accounting for Windows drive letters)
|
|
174
|
+
const colonParts = l.split(':');
|
|
175
|
+
let filePath;
|
|
176
|
+
|
|
177
|
+
if (colonParts.length >= 2 && colonParts[0].length === 1 && /[A-Za-z]/.test(colonParts[0])) {
|
|
178
|
+
filePath = colonParts[0] + ':' + colonParts[1];
|
|
179
|
+
} else {
|
|
180
|
+
filePath = colonParts[0];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return fs.lstatSync(filePath).isFile();
|
|
184
|
+
});
|
|
119
185
|
|
|
120
186
|
if (!stackLines.length) return '';
|
|
121
187
|
|
|
122
|
-
|
|
188
|
+
// Extract file and line number (accounting for Windows drive letters)
|
|
189
|
+
const firstLine = stackLines[0];
|
|
190
|
+
const colonParts = firstLine.split(':');
|
|
191
|
+
let file, line;
|
|
192
|
+
|
|
193
|
+
if (colonParts.length >= 3 && colonParts[0].length === 1 && /[A-Za-z]/.test(colonParts[0])) {
|
|
194
|
+
// Windows path like D:\path\file.php:24
|
|
195
|
+
file = colonParts[0] + ':' + colonParts[1];
|
|
196
|
+
line = colonParts[2];
|
|
197
|
+
} else {
|
|
198
|
+
// Unix path like /path/file.php:24
|
|
199
|
+
file = colonParts[0];
|
|
200
|
+
line = colonParts[1];
|
|
201
|
+
}
|
|
123
202
|
|
|
124
203
|
const prepend = 3;
|
|
125
204
|
const source = fetchSourceCode(fs.readFileSync(file).toString(), { line, prepend, limit: 7 });
|
|
@@ -139,6 +218,8 @@ export const TEST_ID_REGEX = /@T([\w\d]{8})/;
|
|
|
139
218
|
export const SUITE_ID_REGEX = /@S([\w\d]{8})/;
|
|
140
219
|
|
|
141
220
|
const fetchIdFromCode = (code, opts = {}) => {
|
|
221
|
+
if (!code) return null;
|
|
222
|
+
|
|
142
223
|
const comments = code
|
|
143
224
|
.split('\n')
|
|
144
225
|
.map(l => l.trim())
|
|
@@ -180,8 +261,65 @@ const fetchSourceCode = (contents, opts = {}) => {
|
|
|
180
261
|
if (lineIndex === -1) lineIndex = lines.findIndex(l => l.includes(`public void ${title}`));
|
|
181
262
|
if (lineIndex === -1) lineIndex = lines.findIndex(l => l.includes(`${title}(`));
|
|
182
263
|
} else if (opts.lang === 'csharp') {
|
|
183
|
-
|
|
184
|
-
|
|
264
|
+
// Find the method declaration line
|
|
265
|
+
let methodLineIndex = lines.findIndex(l => l.includes(`public void ${title}(`));
|
|
266
|
+
|
|
267
|
+
if (methodLineIndex === -1) {
|
|
268
|
+
methodLineIndex = lines.findIndex(l => l.includes(`public async Task ${title}(`));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (methodLineIndex === -1) {
|
|
272
|
+
methodLineIndex = lines.findIndex(l => l.includes(`${title}(`));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// If found, scan upwards to find [TestCase], [Test] attributes and XML comments
|
|
276
|
+
if (methodLineIndex !== -1) {
|
|
277
|
+
lineIndex = methodLineIndex;
|
|
278
|
+
|
|
279
|
+
// Scan upwards to find the start of attributes and comments
|
|
280
|
+
for (let i = methodLineIndex - 1; i >= 0; i--) {
|
|
281
|
+
const trimmedLine = lines[i].trim();
|
|
282
|
+
|
|
283
|
+
// Include [TestCase], [Test], and other attributes
|
|
284
|
+
if (trimmedLine.startsWith('[')) {
|
|
285
|
+
lineIndex = i;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Include XML documentation comments
|
|
290
|
+
if (trimmedLine.startsWith('///')) {
|
|
291
|
+
lineIndex = i;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Stop at empty lines (with some tolerance)
|
|
296
|
+
if (trimmedLine === '') {
|
|
297
|
+
// Check if next non-empty line is an attribute or comment
|
|
298
|
+
let hasMoreAttributes = false;
|
|
299
|
+
for (let j = i - 1; j >= 0; j--) {
|
|
300
|
+
const nextTrimmed = lines[j].trim();
|
|
301
|
+
if (nextTrimmed === '') continue;
|
|
302
|
+
if (nextTrimmed.startsWith('[') || nextTrimmed.startsWith('///')) {
|
|
303
|
+
hasMoreAttributes = true;
|
|
304
|
+
lineIndex = j;
|
|
305
|
+
}
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
if (!hasMoreAttributes) break;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Stop at other method declarations or class-level elements
|
|
313
|
+
if (
|
|
314
|
+
trimmedLine.includes('public ') ||
|
|
315
|
+
trimmedLine.includes('private ') ||
|
|
316
|
+
trimmedLine.includes('protected ') ||
|
|
317
|
+
trimmedLine.includes('internal ')
|
|
318
|
+
) {
|
|
319
|
+
if (!trimmedLine.startsWith('[')) break;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
185
323
|
} else {
|
|
186
324
|
lineIndex = lines.findIndex(l => l.includes(title));
|
|
187
325
|
}
|
|
@@ -191,11 +329,31 @@ const fetchSourceCode = (contents, opts = {}) => {
|
|
|
191
329
|
lineIndex -= opts.prepend;
|
|
192
330
|
}
|
|
193
331
|
|
|
194
|
-
if (lineIndex) {
|
|
332
|
+
if (lineIndex !== -1 && lineIndex !== undefined) {
|
|
195
333
|
const result = [];
|
|
334
|
+
let braceDepth = 0; // Track brace depth for C# methods
|
|
335
|
+
let methodStartFound = false; // Flag to indicate we've found the method opening brace
|
|
336
|
+
|
|
196
337
|
for (let i = lineIndex; i < lineIndex + limit; i++) {
|
|
197
338
|
if (lines[i] === undefined) continue;
|
|
198
339
|
|
|
340
|
+
// Track brace depth for C# to stop after method closes
|
|
341
|
+
if (opts.lang === 'csharp') {
|
|
342
|
+
const line = lines[i];
|
|
343
|
+
// Count opening and closing braces
|
|
344
|
+
const openBraces = (line.match(/\{/g) || []).length;
|
|
345
|
+
const closeBraces = (line.match(/\}/g) || []).length;
|
|
346
|
+
|
|
347
|
+
if (openBraces > 0) methodStartFound = true;
|
|
348
|
+
braceDepth += openBraces - closeBraces;
|
|
349
|
+
|
|
350
|
+
// If we've started the method and depth returns to 0, method is complete
|
|
351
|
+
if (methodStartFound && braceDepth === 0 && closeBraces > 0) {
|
|
352
|
+
// Don't include the closing brace - just break
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
199
357
|
if (i > lineIndex + 2 && !opts.prepend) {
|
|
200
358
|
// annotation
|
|
201
359
|
if (opts.lang === 'php' && lines[i].trim().startsWith('#[')) break;
|
|
@@ -216,7 +374,25 @@ const fetchSourceCode = (contents, opts = {}) => {
|
|
|
216
374
|
if (opts.lang === 'java' && lines[i].trim().match(/^@\w+/)) break;
|
|
217
375
|
if (opts.lang === 'java' && lines[i].includes(' public void ')) break;
|
|
218
376
|
if (opts.lang === 'java' && lines[i].includes(' class ')) break;
|
|
377
|
+
// For C#, additional checks if brace tracking didn't stop us
|
|
378
|
+
if (opts.lang === 'csharp') {
|
|
379
|
+
const trimmed = lines[i].trim();
|
|
380
|
+
// Stop at attribute that marks beginning of next test (but not if we're still in the current method)
|
|
381
|
+
if (trimmed.match(/^\[(Test|TestCase|Theory|Fact)/) && methodStartFound && braceDepth === 0) break;
|
|
382
|
+
// Stop at XML documentation comments that belong to next method
|
|
383
|
+
if (trimmed.startsWith('///') && methodStartFound && braceDepth === 0) break;
|
|
384
|
+
// Stop at another method declaration (but not if we're still in the current method)
|
|
385
|
+
if (
|
|
386
|
+
trimmed.match(/^\s*(public|private|protected|internal)\s+(\w+|async\s+\w+)\s+\w+\s*\(/) &&
|
|
387
|
+
methodStartFound &&
|
|
388
|
+
braceDepth === 0
|
|
389
|
+
)
|
|
390
|
+
break;
|
|
391
|
+
// Stop at class declaration
|
|
392
|
+
if (trimmed.includes(' class ') && trimmed.includes('public')) break;
|
|
393
|
+
}
|
|
219
394
|
}
|
|
395
|
+
|
|
220
396
|
result.push(lines[i]);
|
|
221
397
|
}
|
|
222
398
|
return result.join('\n');
|
package/src/xmlReader.js
CHANGED
|
@@ -6,6 +6,7 @@ import { XMLParser } from 'fast-xml-parser';
|
|
|
6
6
|
import { APP_PREFIX, STATUS } from './constants.js';
|
|
7
7
|
import { randomUUID } from 'crypto';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
|
+
import { NUnitXmlParser } from './junit-adapter/nunit-parser.js';
|
|
9
10
|
import {
|
|
10
11
|
fetchFilesFromStackTrace,
|
|
11
12
|
fetchIdFromOutput,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
fetchIdFromCode,
|
|
15
16
|
humanize,
|
|
16
17
|
TEST_ID_REGEX,
|
|
18
|
+
transformEnvVarToBoolean,
|
|
17
19
|
} from './utils/utils.js';
|
|
18
20
|
import { pipesFactory } from './pipe/index.js';
|
|
19
21
|
import adapterFactory from './junit-adapter/index.js';
|
|
@@ -35,6 +37,7 @@ const {
|
|
|
35
37
|
TESTOMATIO_ENV,
|
|
36
38
|
TESTOMATIO_RUN,
|
|
37
39
|
TESTOMATIO_MARK_DETACHED,
|
|
40
|
+
TESTOMATIO_LEGACY_NUNIT,
|
|
38
41
|
} = process.env;
|
|
39
42
|
|
|
40
43
|
const options = {
|
|
@@ -75,6 +78,11 @@ class XmlReader {
|
|
|
75
78
|
this.stats.language = opts.lang?.toLowerCase();
|
|
76
79
|
this.uploader = new S3Uploader();
|
|
77
80
|
|
|
81
|
+
// Enhanced NUnit parsing - enabled by default for NUnit XML
|
|
82
|
+
// Can be disabled via opts.enhancedNunit = false or TESTOMATIO_LEGACY_NUNIT=1
|
|
83
|
+
this.enhancedNunit = !transformEnvVarToBoolean(TESTOMATIO_LEGACY_NUNIT);
|
|
84
|
+
this.groupParameterized = opts.groupParameterized !== false; // Default true, can be disabled
|
|
85
|
+
|
|
78
86
|
// @ts-ignore
|
|
79
87
|
const packageJsonPath = path.resolve(__dirname, '..', 'package.json');
|
|
80
88
|
this.version = JSON.parse(fs.readFileSync(packageJsonPath).toString()).version;
|
|
@@ -126,7 +134,8 @@ class XmlReader {
|
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
processJUnit(jsonSuite) {
|
|
129
|
-
const { testsuite, name,
|
|
137
|
+
const { testsuite, name, failures, errors } = jsonSuite;
|
|
138
|
+
const tests = testsuite?.tests || jsonSuite.tests;
|
|
130
139
|
|
|
131
140
|
reduceOptions.preferClassname = this.stats.language === 'python';
|
|
132
141
|
const resultTests = processTestSuite(testsuite);
|
|
@@ -157,6 +166,14 @@ class XmlReader {
|
|
|
157
166
|
}
|
|
158
167
|
|
|
159
168
|
processNUnit(jsonSuite) {
|
|
169
|
+
// Use enhanced NUnit parser if enabled and this is actually NUnit XML
|
|
170
|
+
if (this.enhancedNunit && this.isNUnitXml(jsonSuite)) {
|
|
171
|
+
debug('Using enhanced NUnit parser');
|
|
172
|
+
return this.processNUnitEnhanced(jsonSuite);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Fallback to legacy parser for backward compatibility
|
|
176
|
+
debug('Using legacy NUnit parser');
|
|
160
177
|
const { result, total, passed, failed, inconclusive, skipped } = jsonSuite;
|
|
161
178
|
|
|
162
179
|
reduceOptions.preferClassname = this.stats.language === 'python';
|
|
@@ -175,63 +192,71 @@ class XmlReader {
|
|
|
175
192
|
};
|
|
176
193
|
}
|
|
177
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Check if the XML is actually NUnit format (has test-suite hierarchy)
|
|
197
|
+
* @param {Object} jsonSuite - Parsed XML suite object
|
|
198
|
+
* @returns {boolean} - True if this is NUnit XML format
|
|
199
|
+
*/
|
|
200
|
+
isNUnitXml(jsonSuite) {
|
|
201
|
+
// NUnit XML has test-suite elements with type attributes
|
|
202
|
+
if (jsonSuite['test-suite']) {
|
|
203
|
+
const testSuite = Array.isArray(jsonSuite['test-suite']) ? jsonSuite['test-suite'][0] : jsonSuite['test-suite'];
|
|
204
|
+
|
|
205
|
+
// Check for NUnit-specific test-suite types
|
|
206
|
+
return (
|
|
207
|
+
testSuite &&
|
|
208
|
+
testSuite.type &&
|
|
209
|
+
['Assembly', 'TestSuite', 'TestFixture', 'ParameterizedMethod'].includes(testSuite.type)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
processNUnitEnhanced(jsonSuite) {
|
|
216
|
+
debug('Processing NUnit XML with enhanced parser');
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const nunitParser = new NUnitXmlParser({
|
|
220
|
+
groupParameterized: this.groupParameterized,
|
|
221
|
+
...this.opts,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const result = nunitParser.parseTestRun(jsonSuite);
|
|
225
|
+
|
|
226
|
+
// Add parsed tests to our collection
|
|
227
|
+
this.tests = this.tests.concat(result.tests);
|
|
228
|
+
|
|
229
|
+
debug(`Enhanced NUnit parser processed ${result.tests.length} tests`);
|
|
230
|
+
|
|
231
|
+
return result;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
debug('Enhanced NUnit parser failed, falling back to legacy parser:', error.message);
|
|
234
|
+
console.warn(`${APP_PREFIX} Enhanced NUnit parsing failed, using legacy parser: ${error.message}`);
|
|
235
|
+
|
|
236
|
+
// Fallback to legacy parser
|
|
237
|
+
this.enhancedNunit = false;
|
|
238
|
+
return this.processNUnit(jsonSuite);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
178
242
|
processTRX(jsonSuite) {
|
|
179
243
|
let defs = jsonSuite?.TestRun?.TestDefinitions?.UnitTest;
|
|
180
244
|
if (!Array.isArray(defs)) defs = [defs].filter(d => !!d);
|
|
181
245
|
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
}) || [];
|
|
246
|
+
// Parse test definitions
|
|
247
|
+
const tests = defs.map(td => this._parseTRXTestDefinition(td));
|
|
198
248
|
|
|
249
|
+
// Parse test results
|
|
199
250
|
let result = jsonSuite?.TestRun?.Results?.UnitTestResult;
|
|
200
251
|
if (!Array.isArray(result)) result = [result].filter(d => !!d);
|
|
201
252
|
|
|
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
|
-
r.overwrite = true;
|
|
221
|
-
if (r.status === 'Passed') r.status = STATUS.PASSED;
|
|
222
|
-
if (r.status === 'Failed') r.status = STATUS.FAILED;
|
|
223
|
-
if (r.status === 'Skipped') r.status = STATUS.SKIPPED;
|
|
224
|
-
delete r.id;
|
|
225
|
-
});
|
|
253
|
+
const results = result.map(td => this._parseTRXTestResult(td, tests));
|
|
226
254
|
|
|
227
255
|
debug(results);
|
|
228
256
|
|
|
229
257
|
const counters = jsonSuite?.TestRun?.ResultSummary?.Counters || {};
|
|
230
|
-
|
|
231
258
|
const failed_count = parseInt(counters.failed, 10) + parseInt(counters.error, 10);
|
|
232
|
-
|
|
233
|
-
let status = STATUS.PASSED.toString();
|
|
234
|
-
if (failed_count > 0) status = STATUS.FAILED;
|
|
259
|
+
const status = failed_count > 0 ? STATUS.FAILED : STATUS.PASSED.toString();
|
|
235
260
|
|
|
236
261
|
this.tests = results.filter(t => !!t.title);
|
|
237
262
|
|
|
@@ -246,6 +271,69 @@ class XmlReader {
|
|
|
246
271
|
};
|
|
247
272
|
}
|
|
248
273
|
|
|
274
|
+
_parseTRXTestDefinition(td) {
|
|
275
|
+
const title = td.name.replace(/\(.*?\)/, '').trim();
|
|
276
|
+
const exampleMatch = td.name.match(/\((.*?)\)/);
|
|
277
|
+
const example = exampleMatch ? {
|
|
278
|
+
...exampleMatch[1].split(',').map(p => p.trim()).filter(p => p !== '')
|
|
279
|
+
} : null;
|
|
280
|
+
|
|
281
|
+
const suite = td.TestMethod.className.split(', ')[0].split('.');
|
|
282
|
+
const suite_title = suite.pop();
|
|
283
|
+
|
|
284
|
+
// Convert namespace to file path for C#
|
|
285
|
+
const file = `${suite.join('/')}.cs`;
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
title, // Base name without parameters for test import
|
|
289
|
+
example, // Parameters object for parameterized tests
|
|
290
|
+
file, // File path with .cs extension
|
|
291
|
+
description: td.Description,
|
|
292
|
+
suite_title,
|
|
293
|
+
id: td.Execution.id,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
_parseTRXTestResult(td, tests) {
|
|
298
|
+
const test = tests.find(t => t.id === td.executionId) || {};
|
|
299
|
+
|
|
300
|
+
const result = {
|
|
301
|
+
suite_title: test.suite_title,
|
|
302
|
+
title: test.title?.trim(),
|
|
303
|
+
file: test.file,
|
|
304
|
+
description: test.description,
|
|
305
|
+
code: test.code,
|
|
306
|
+
run_time: parseFloat(td.duration) * 1000,
|
|
307
|
+
stack: td.Output?.StdOut || '',
|
|
308
|
+
files: td?.ResultFiles?.ResultFile?.map(rf => rf.path),
|
|
309
|
+
create: true,
|
|
310
|
+
overwrite: true,
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// Add example for parameterized tests
|
|
314
|
+
if (test.example) {
|
|
315
|
+
result.example = test.example;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Map TRX status to Testomat.io status
|
|
319
|
+
result.status = this._mapTRXStatus(td.outcome);
|
|
320
|
+
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
_mapTRXStatus(outcome) {
|
|
325
|
+
switch (outcome) {
|
|
326
|
+
case 'Passed':
|
|
327
|
+
return STATUS.PASSED;
|
|
328
|
+
case 'Failed':
|
|
329
|
+
return STATUS.FAILED;
|
|
330
|
+
case 'Skipped':
|
|
331
|
+
return STATUS.SKIPPED;
|
|
332
|
+
default:
|
|
333
|
+
return STATUS.PASSED;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
249
337
|
processXUnit(assemblies) {
|
|
250
338
|
const tests = [];
|
|
251
339
|
|
|
@@ -512,7 +600,7 @@ function reduceTestCases(prev, item) {
|
|
|
512
600
|
|
|
513
601
|
const exampleMatches = testCaseItem.name?.match(/\S\((.*?)\)/);
|
|
514
602
|
if (exampleMatches) {
|
|
515
|
-
example = { ...exampleMatches[1].split(',').map(v => v.trim().replace(/[^\w\s-]/g, '')) };
|
|
603
|
+
example = { ...exampleMatches[1].split(',').map(v => v.trim().replace(/[^\w\s-]/g, '')).filter(v => v !== '') };
|
|
516
604
|
title = title.replace(/\(.*?\)/, '').trim();
|
|
517
605
|
}
|
|
518
606
|
|