-
Notifications
You must be signed in to change notification settings - Fork 291
Copy per-test result files to results directory in TRX reports #7449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,7 +169,7 @@ public TrxReportEngine(IFileSystem fileSystem, ITestApplicationModuleInfo testAp | |
| isFileNameExplicitlyProvided = false; | ||
| } | ||
|
|
||
| AddResults(testAppModule, testRun, out XElement testDefinitions, out XElement testEntries, out string uncategorizedTestId, out bool hasFailedTests); | ||
| (XElement testDefinitions, XElement testEntries, string uncategorizedTestId, bool hasFailedTests) = await AddResultsAsync(testAppModule, testRun, runDeploymentRoot).ConfigureAwait(false); | ||
| testRun.Add(testDefinitions); | ||
| testRun.Add(testEntries); | ||
| AddTestLists(testRun, uncategorizedTestId); | ||
|
|
@@ -346,25 +346,40 @@ private async Task AddResultSummaryAsync(XElement testRun, string resultSummaryO | |
| await AddArtifactsToCollectionAsync(_artifactsByExtension, collectorDataEntries, runDeploymentRoot).ConfigureAwait(false); | ||
| } | ||
|
|
||
| private async Task<string> CopyTestResultFileAndReturnRelativePathAsync(FileInfo artifact, string runDeploymentRoot, string executionId) | ||
| { | ||
| string testResultDirectory = Path.Combine(_configuration.GetTestResultDirectory(), runDeploymentRoot, "In", executionId, _environment.MachineName); | ||
| if (!Directory.Exists(testResultDirectory)) | ||
| { | ||
| Directory.CreateDirectory(testResultDirectory); | ||
| } | ||
|
Comment on lines
+351
to
+355
|
||
|
|
||
| string fileName = artifact.Name; | ||
|
|
||
| string destination = Path.Combine(testResultDirectory, fileName); | ||
|
|
||
| // If the file already exists, append a number to the end of the file name | ||
| for (int nameCounter = 1; File.Exists(destination) && nameCounter <= 10; nameCounter++) | ||
| { | ||
| destination = Path.Combine(testResultDirectory, $"{Path.GetFileNameWithoutExtension(fileName)}_{nameCounter}{Path.GetExtension(fileName)}"); | ||
| } | ||
|
Comment on lines
+361
to
+365
|
||
|
|
||
| await CopyFileAsync(artifact, new FileInfo(destination)).ConfigureAwait(false); | ||
|
|
||
| return Path.Combine(_environment.MachineName, Path.GetFileName(destination)); | ||
| } | ||
|
|
||
| private async Task<string> CopyArtifactIntoTrxDirectoryAndReturnHrefValueAsync(FileInfo artifact, string runDeploymentRoot) | ||
| { | ||
| string artifactDirectory = CreateOrGetTrxArtifactDirectory(runDeploymentRoot); | ||
| string fileName = artifact.Name; | ||
|
|
||
| string destination = Path.Combine(artifactDirectory, fileName); | ||
| int nameCounter = 0; | ||
|
|
||
| // If the file already exists, append a number to the end of the file name | ||
| while (true) | ||
| for (int nameCounter = 1; File.Exists(destination) && nameCounter <= 10; nameCounter++) | ||
| { | ||
| if (File.Exists(destination)) | ||
| { | ||
| nameCounter++; | ||
| destination = Path.Combine(artifactDirectory, $"{Path.GetFileNameWithoutExtension(fileName)}_{nameCounter}{Path.GetExtension(fileName)}"); | ||
| continue; | ||
| } | ||
|
|
||
| break; | ||
| destination = Path.Combine(artifactDirectory, $"{Path.GetFileNameWithoutExtension(fileName)}_{nameCounter}{Path.GetExtension(fileName)}"); | ||
| } | ||
|
|
||
| await CopyFileAsync(artifact, new FileInfo(destination)).ConfigureAwait(false); | ||
|
|
@@ -412,17 +427,17 @@ private static void AddTestLists(XElement testRun, string uncategorizedTestId) | |
| testRun.Add(testLists); | ||
| } | ||
|
|
||
| private void AddResults(string testAppModule, XElement testRun, out XElement testDefinitions, out XElement testEntries, out string uncategorizedTestId, out bool hasFailedTests) | ||
| private async Task<(XElement TestDefinitions, XElement TestEntries, string UncategorizedTestId, bool HasFailedTests)> AddResultsAsync(string testAppModule, XElement testRun, string runDeploymentRoot) | ||
| { | ||
| var results = new XElement("Results"); | ||
|
|
||
| // Duplicate test ids are not allowed inside the TestDefinitions element. | ||
| testDefinitions = new XElement("TestDefinitions"); | ||
| var testDefinitions = new XElement("TestDefinitions"); | ||
| var uniqueTestDefinitionTestIds = new HashSet<string>(); | ||
|
|
||
| testEntries = new XElement("TestEntries"); | ||
| uncategorizedTestId = "8C84FA94-04C1-424b-9868-57A2D4851A1D"; | ||
| hasFailedTests = false; | ||
| var testEntries = new XElement("TestEntries"); | ||
| string uncategorizedTestId = "8C84FA94-04C1-424b-9868-57A2D4851A1D"; | ||
| bool hasFailedTests = false; | ||
| foreach (TestNodeUpdateMessage nodeMessage in _testNodeUpdatedMessages) | ||
| { | ||
| TestNode testNode = nodeMessage.TestNode; | ||
|
|
@@ -534,9 +549,11 @@ private void AddResults(string testAppModule, XElement testRun, out XElement tes | |
| foreach (FileArtifactProperty testFileArtifact in testNode.Properties.OfType<FileArtifactProperty>()) | ||
| { | ||
| resultFiles ??= new XElement("ResultFiles"); | ||
| string relativePath = await CopyTestResultFileAndReturnRelativePathAsync( | ||
| testFileArtifact.FileInfo, runDeploymentRoot, executionId).ConfigureAwait(false); | ||
| resultFiles.Add(new XElement( | ||
| "ResultFile", | ||
| new XAttribute("path", testFileArtifact.FileInfo.FullName))); | ||
| new XAttribute("path", relativePath))); | ||
|
Comment on lines
+552
to
+556
|
||
| } | ||
|
|
||
| if (resultFiles is not null) | ||
|
|
@@ -666,6 +683,8 @@ private void AddResults(string testAppModule, XElement testRun, out XElement tes | |
| } | ||
|
|
||
| testRun.Add(results); | ||
|
|
||
| return (testDefinitions, testEntries, uncategorizedTestId, hasFailedTests); | ||
| } | ||
|
|
||
| private static string AddTestSettings(XElement testRun, string testRunName) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also consider the copy function to be part of the core platform (or vstest bridge) so that the feature is also available outside of trx being enabled