From e89b2f3e4782bbfd46955e3e1c448a4474fa7298 Mon Sep 17 00:00:00 2001 From: Shamus Taylor Date: Wed, 5 Mar 2025 11:15:25 -0600 Subject: [PATCH] NUnit Legacy: clean up suite/group names --- __tests__/__outputs__/dotnet-nunit-legacy.md | 24 ++++++------- .../dotnet-nunit-legacy.test.ts.snap | 34 +++++++++---------- __tests__/dotnet-nunit-legacy.test.ts | 2 +- dist/index.js | 4 +-- .../dotnet-nunit-legacy-parser.ts | 4 +-- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/__tests__/__outputs__/dotnet-nunit-legacy.md b/__tests__/__outputs__/dotnet-nunit-legacy.md index c8203e8..d14a103 100644 --- a/__tests__/__outputs__/dotnet-nunit-legacy.md +++ b/__tests__/__outputs__/dotnet-nunit-legacy.md @@ -6,29 +6,29 @@ **10** tests were completed in **9ms** with **3** passed, **5** failed and **2** skipped. |Test suite|Passed|Failed|Skipped|Time| |:---|---:|---:|---:|---:| -|[C:\Users\james_t\Documents\git\test-reporter\reports\dotnet-nunit-legacy\NUnitLegacy.sln.C:\Users\james_t\Documents\git\test-reporter\reports\dotnet-nunit-legacy\NUnitLegacyTests\bin\Debug\NUnitLegacyTests.dll.NUnitLegacyTests](#r0s0)|3 ✅|5 ❌|2 ⚪|NaNms| -### ❌ C:\Users\james_t\Documents\git\test-reporter\reports\dotnet-nunit-legacy\NUnitLegacy.sln.C:\Users\james_t\Documents\git\test-reporter\reports\dotnet-nunit-legacy\NUnitLegacyTests\bin\Debug\NUnitLegacyTests.dll.NUnitLegacyTests +|[NUnitLegacyTests.CalculatorTests](#r0s0)|3 ✅|5 ❌|2 ⚪|NaNms| +### ❌ NUnitLegacyTests.CalculatorTests ``` CalculatorTests - ✅ NUnitLegacyTests.CalculatorTests.Is_Even_Number(2) - ❌ NUnitLegacyTests.CalculatorTests.Is_Even_Number(3) + ✅ Is_Even_Number(2) + ❌ Is_Even_Number(3) Expected: True But was: False - ❌ NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest + ❌ Exception_In_TargetTest System.DivideByZeroException : Attempted to divide by zero. - ❌ NUnitLegacyTests.CalculatorTests.Exception_In_Test + ❌ Exception_In_Test System.Exception : Test - ❌ NUnitLegacyTests.CalculatorTests.Failing_Test + ❌ Failing_Test Expected: 3 But was: 2 - ⚪ NUnitLegacyTests.CalculatorTests.Inconclusive_Test + ⚪ Inconclusive_Test couldn't run test for some reason - ✅ NUnitLegacyTests.CalculatorTests.Passing_Test - ✅ NUnitLegacyTests.CalculatorTests.Passing_Test_With_Description - ⚪ NUnitLegacyTests.CalculatorTests.Skipped_Test + ✅ Passing_Test + ✅ Passing_Test_With_Description + ⚪ Skipped_Test Skipped - ❌ NUnitLegacyTests.CalculatorTests.Timeout_Test + ❌ Timeout_Test Test exceeded Timeout value of 1ms ``` \ No newline at end of file diff --git a/__tests__/__snapshots__/dotnet-nunit-legacy.test.ts.snap b/__tests__/__snapshots__/dotnet-nunit-legacy.test.ts.snap index 27d5820..e66521d 100644 --- a/__tests__/__snapshots__/dotnet-nunit-legacy.test.ts.snap +++ b/__tests__/__snapshots__/dotnet-nunit-legacy.test.ts.snap @@ -11,7 +11,7 @@ TestRunResult { "tests": [ TestCaseResult { "error": undefined, - "name": "NUnitLegacyTests.CalculatorTests.Is_Even_Number(2)", + "name": "Is_Even_Number(2)", "result": "success", "time": 0.001, }, @@ -25,9 +25,9 @@ TestRunResult { ", "path": undefined, }, - "name": "NUnitLegacyTests.CalculatorTests.Is_Even_Number(3)", + "name": "Is_Even_Number(3)", "result": "failed", - "time": 0.002, + "time": 0.001, }, TestCaseResult { "error": { @@ -38,9 +38,9 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame "message": "System.DivideByZeroException : Attempted to divide by zero.", "path": undefined, }, - "name": "NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest", + "name": "Exception_In_TargetTest", "result": "failed", - "time": 0.028, + "time": 0.026, }, TestCaseResult { "error": { @@ -50,7 +50,7 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame "message": "System.Exception : Test", "path": undefined, }, - "name": "NUnitLegacyTests.CalculatorTests.Exception_In_Test", + "name": "Exception_In_Test", "result": "failed", "time": 0.002, }, @@ -64,9 +64,9 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame ", "path": undefined, }, - "name": "NUnitLegacyTests.CalculatorTests.Failing_Test", + "name": "Failing_Test", "result": "failed", - "time": 0.016, + "time": 0.014, }, TestCaseResult { "error": { @@ -75,19 +75,19 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame "message": "couldn't run test for some reason", "path": undefined, }, - "name": "NUnitLegacyTests.CalculatorTests.Inconclusive_Test", + "name": "Inconclusive_Test", "result": "skipped", - "time": 0.002, + "time": 0.001, }, TestCaseResult { "error": undefined, - "name": "NUnitLegacyTests.CalculatorTests.Passing_Test", + "name": "Passing_Test", "result": "success", "time": 0, }, TestCaseResult { "error": undefined, - "name": "NUnitLegacyTests.CalculatorTests.Passing_Test_With_Description", + "name": "Passing_Test_With_Description", "result": "success", "time": 0, }, @@ -98,7 +98,7 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame "message": "Skipped", "path": undefined, }, - "name": "NUnitLegacyTests.CalculatorTests.Skipped_Test", + "name": "Skipped_Test", "result": "skipped", "time": NaN, }, @@ -109,17 +109,17 @@ at NUnitLegacyTests.CalculatorTests.Exception_In_TargetTest() in C:\\Users\\jame "message": "Test exceeded Timeout value of 1ms", "path": undefined, }, - "name": "NUnitLegacyTests.CalculatorTests.Timeout_Test", + "name": "Timeout_Test", "result": "failed", - "time": 0.027, + "time": 0.028, }, ], }, ], - "name": "C:\\Users\\james_t\\source\\repos\\NUnitLegacy\\NUnitLegacy.sln.C:\\Users\\james_t\\source\\repos\\NUnitLegacy\\NUnitLegacyTests\\bin\\Debug\\NUnitLegacyTests.dll.NUnitLegacyTests", + "name": "NUnitLegacyTests.CalculatorTests", "totalTime": undefined, }, ], - "totalTime": 0, + "totalTime": 9, } `; diff --git a/__tests__/dotnet-nunit-legacy.test.ts b/__tests__/dotnet-nunit-legacy.test.ts index b03809b..c0fd4f3 100644 --- a/__tests__/dotnet-nunit-legacy.test.ts +++ b/__tests__/dotnet-nunit-legacy.test.ts @@ -15,7 +15,7 @@ describe('dotnet-nunit-legacy tests', () => { const opts: ParseOptions = { parseErrors: true, - trackedFiles: ['DotnetTests.Unit/Calculator.cs', 'DotnetTests.NUnitLegacyTests/CalculatorTests.cs'] + trackedFiles: ['MyLibrary/Calculator.cs', 'NUnitLegacyTests/CalculatorTests.cs'] } const parser = new DotnetNunitLegacyParser(opts) diff --git a/dist/index.js b/dist/index.js index 79ed489..c3e9e8b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -789,7 +789,7 @@ class DotnetNunitLegacyParser { // But ignore "Theory" suites. const suitesWithoutTheories = suitePath.filter(suite => suite.$.type !== 'Theory'); const suiteName = suitesWithoutTheories - .slice(0, suitesWithoutTheories.length - 1) + .filter(suite => suite.$.type !== 'Assembly' && suite.$.type !== 'Project') .map(suite => suite.$.name) .join('.'); const groupName = suitesWithoutTheories[suitesWithoutTheories.length - 1].$.name; @@ -803,7 +803,7 @@ class DotnetNunitLegacyParser { existingGroup = new test_results_1.TestGroupResult(groupName, []); existingSuite.groups.push(existingGroup); } - existingGroup.tests.push(new test_results_1.TestCaseResult(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), parseFloat(testCase.$.time), this.getTestCaseError(testCase))); } getTestExecutionResult(test) { if (test.$.result === 'Failed' || test.failure) diff --git a/src/parsers/dotnet-nunit-legacy/dotnet-nunit-legacy-parser.ts b/src/parsers/dotnet-nunit-legacy/dotnet-nunit-legacy-parser.ts index 0b65355..c62ee1a 100644 --- a/src/parsers/dotnet-nunit-legacy/dotnet-nunit-legacy-parser.ts +++ b/src/parsers/dotnet-nunit-legacy/dotnet-nunit-legacy-parser.ts @@ -78,7 +78,7 @@ export class DotnetNunitLegacyParser implements TestParser { // But ignore "Theory" suites. const suitesWithoutTheories = suitePath.filter(suite => suite.$.type !== 'Theory') const suiteName = suitesWithoutTheories - .slice(0, suitesWithoutTheories.length - 1) + .filter(suite => suite.$.type !== 'Assembly' && suite.$.type !== 'Project') .map(suite => suite.$.name) .join('.') const groupName = suitesWithoutTheories[suitesWithoutTheories.length - 1].$.name @@ -97,7 +97,7 @@ export class DotnetNunitLegacyParser implements TestParser { existingGroup.tests.push( new TestCaseResult( - testCase.$.name, + testCase.$.name.startsWith(suiteName + '.') ? testCase.$.name.substring(suiteName.length + 1) : testCase.$.name, this.getTestExecutionResult(testCase), parseFloat(testCase.$.time), this.getTestCaseError(testCase)