1
0
Fork 0
mirror of https://github.com/dorny/test-reporter.git synced 2026-03-21 23:52:12 +01:00

Correct test time output

This commit is contained in:
Shamus Taylor 2025-03-05 15:06:35 -06:00
parent e89b2f3e47
commit 3eeb9fc888
No known key found for this signature in database
GPG key ID: C44FC1AA547ACE39
5 changed files with 19 additions and 20 deletions

View file

@ -1,12 +1,12 @@
![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%205%20failed%2C%202%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|fixtures/dotnet-nunit-legacy.xml|3 ✅|5 ❌|2 ⚪|9ms|
|fixtures/dotnet-nunit-legacy.xml|3 ✅|5 ❌|2 ⚪|73ms|
## ❌ <a id="user-content-r0" href="#r0">fixtures/dotnet-nunit-legacy.xml</a>
**10** tests were completed in **9ms** with **3** passed, **5** failed and **2** skipped.
**10** tests were completed in **73ms** with **3** passed, **5** failed and **2** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[NUnitLegacyTests.CalculatorTests](#r0s0)|3 ✅|5 ❌|2 ⚪|NaNms|
|[NUnitLegacyTests.CalculatorTests](#r0s0)|3 ✅|5 ❌|2 ⚪|73ms|
### ❌ <a id="user-content-r0s0" href="#r0s0">NUnitLegacyTests.CalculatorTests</a>
```
CalculatorTests

View file

@ -13,7 +13,7 @@ TestRunResult {
"error": undefined,
"name": "Is_Even_Number(2)",
"result": "success",
"time": 0.001,
"time": 1,
},
TestCaseResult {
"error": {
@ -27,7 +27,7 @@ TestRunResult {
},
"name": "Is_Even_Number(3)",
"result": "failed",
"time": 0.001,
"time": 1,
},
TestCaseResult {
"error": {
@ -40,7 +40,7 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame
},
"name": "Exception_In_TargetTest",
"result": "failed",
"time": 0.026,
"time": 26,
},
TestCaseResult {
"error": {
@ -52,7 +52,7 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame
},
"name": "Exception_In_Test",
"result": "failed",
"time": 0.002,
"time": 2,
},
TestCaseResult {
"error": {
@ -66,7 +66,7 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame
},
"name": "Failing_Test",
"result": "failed",
"time": 0.014,
"time": 14,
},
TestCaseResult {
"error": {
@ -77,7 +77,7 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame
},
"name": "Inconclusive_Test",
"result": "skipped",
"time": 0.001,
"time": 1,
},
TestCaseResult {
"error": undefined,
@ -100,7 +100,7 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame
},
"name": "Skipped_Test",
"result": "skipped",
"time": NaN,
"time": 0,
},
TestCaseResult {
"error": {
@ -111,7 +111,7 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame
},
"name": "Timeout_Test",
"result": "failed",
"time": 0.028,
"time": 28,
},
],
},
@ -120,6 +120,6 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame
"totalTime": undefined,
},
],
"totalTime": 9,
"totalTime": undefined,
}
`;

5
dist/index.js generated vendored
View file

@ -759,9 +759,8 @@ class DotnetNunitLegacyParser {
}
getTestRunResult(path, nunit) {
const suites = [];
const time = parseFloat(nunit['test-results'].$.time);
this.populateTestCasesRecursive(suites, [], nunit['test-results']['test-suite']);
return new test_results_1.TestRunResult(path, suites, time);
return new test_results_1.TestRunResult(path, suites);
}
populateTestCasesRecursive(result, suitePath, testSuites) {
if (testSuites === undefined) {
@ -803,7 +802,7 @@ class DotnetNunitLegacyParser {
existingGroup = new test_results_1.TestGroupResult(groupName, []);
existingSuite.groups.push(existingGroup);
}
existingGroup.tests.push(new test_results_1.TestCaseResult(testCase.$.name.startsWith(suiteName + '.') ? testCase.$.name.substring(suiteName.length + 1) : testCase.$.name, this.getTestExecutionResult(testCase), parseFloat(testCase.$.time), this.getTestCaseError(testCase)));
existingGroup.tests.push(new test_results_1.TestCaseResult(testCase.$.name.startsWith(suiteName + '.') ? testCase.$.name.substring(suiteName.length + 1) : testCase.$.name, this.getTestExecutionResult(testCase), testCase.$.time ? parseFloat(testCase.$.time) * 1000 : 0, this.getTestCaseError(testCase)));
}
getTestExecutionResult(test) {
if (test.$.result === 'Failed' || test.failure)

View file

@ -34,11 +34,10 @@ export class DotnetNunitLegacyParser implements TestParser {
private getTestRunResult(path: string, nunit: NunitReport): TestRunResult {
const suites: TestSuiteResult[] = []
const time = parseFloat(nunit['test-results'].$.time)
this.populateTestCasesRecursive(suites, [], nunit['test-results']['test-suite'])
return new TestRunResult(path, suites, time)
return new TestRunResult(path, suites)
}
private populateTestCasesRecursive(
@ -99,7 +98,7 @@ export class DotnetNunitLegacyParser implements TestParser {
new TestCaseResult(
testCase.$.name.startsWith(suiteName + '.') ? testCase.$.name.substring(suiteName.length + 1) : testCase.$.name,
this.getTestExecutionResult(testCase),
parseFloat(testCase.$.time),
testCase.$.time ? parseFloat(testCase.$.time) * 1000 : 0,
this.getTestCaseError(testCase)
)
)

View file

@ -4,7 +4,8 @@ export interface NunitReport {
export interface TestResults {
$: {
time: string
// there is a time attribute here, but it is the time of day the test ran, not the duration
// time: string
}
'test-suite'?: TestSuite[]
}
@ -26,7 +27,7 @@ export interface TestCase {
$: {
name: string
result: string
time: string
time?: string
}
failure?: TestFailure[]
reason?: TestFailure[]