From 0513362b494151d6d7d5b6c4730344333a165925 Mon Sep 17 00:00:00 2001 From: Prawal Agarwal Date: Tue, 6 Mar 2018 17:45:16 +0530 Subject: [PATCH 1/2] Adding fix for removing old trx files in case of multiple test tasks --- Tasks/DotNetCoreCLI/dotnetcore.ts | 16 ++++++++++++++++ Tasks/DotNetCoreCLI/task.json | 2 +- Tasks/DotNetCoreCLI/task.loc.json | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Tasks/DotNetCoreCLI/dotnetcore.ts b/Tasks/DotNetCoreCLI/dotnetcore.ts index c5875bc260ec..27d202660f6d 100644 --- a/Tasks/DotNetCoreCLI/dotnetcore.ts +++ b/Tasks/DotNetCoreCLI/dotnetcore.ts @@ -103,6 +103,9 @@ export class dotNetExe { if (enablePublishTestResults && enablePublishTestResults === true) { this.arguments = this.arguments.concat(` --logger trx --results-directory ${resultsDirectory}`); } + + // Remove old trx files + this.removeOldTestResultFiles(resultsDirectory); // Use empty string when no project file is specified to operate on the current directory const projectFiles = this.getProjectFiles(); @@ -148,6 +151,19 @@ export class dotNetExe { } } + private removeOldTestResultFiles(resultsDir:string): void { + const matchingTestResultsFiles: string[] = tl.findMatch(resultsDir, '**/*.trx'); + if (!matchingTestResultsFiles || matchingTestResultsFiles.length === 0) { + tl.debug("No old result files found."); + return; + } + for (const fileIndex of Object.keys(matchingTestResultsFiles)) { + const resultFile = matchingTestResultsFiles[fileIndex]; + tl.rmRF(resultFile) + tl.debug("Successfuly removed: " + resultFile); + } + } + private replaceOutputArgument(modifiedOutput: string) { var str = this.arguments; var index = this.outputArgumentIndex; diff --git a/Tasks/DotNetCoreCLI/task.json b/Tasks/DotNetCoreCLI/task.json index 949b3a4448ed..e15df43dbd59 100644 --- a/Tasks/DotNetCoreCLI/task.json +++ b/Tasks/DotNetCoreCLI/task.json @@ -16,7 +16,7 @@ "demands": [], "version": { "Major": 2, - "Minor": 131, + "Minor": 132, "Patch": 0 }, "minimumAgentVersion": "2.0.0", diff --git a/Tasks/DotNetCoreCLI/task.loc.json b/Tasks/DotNetCoreCLI/task.loc.json index 541594a345da..8a3e24bf50fa 100644 --- a/Tasks/DotNetCoreCLI/task.loc.json +++ b/Tasks/DotNetCoreCLI/task.loc.json @@ -16,7 +16,7 @@ "demands": [], "version": { "Major": 2, - "Minor": 131, + "Minor": 132, "Patch": 0 }, "minimumAgentVersion": "2.0.0", From 81535945fd8737ee201cb440ed49dae6ade2ff4a Mon Sep 17 00:00:00 2001 From: Prawal Agarwal Date: Thu, 8 Mar 2018 15:47:37 +0530 Subject: [PATCH 2/2] Fixing tests --- Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtests.ts | 5 +++++ .../TestCommandTests/publishtestsWithFailedTestCommand.ts | 5 +++++ .../Tests/TestCommandTests/publishtestsWithoutBuildConfig.ts | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtests.ts b/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtests.ts index 2b7ac8dab37e..fa01e0b7a3e8 100644 --- a/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtests.ts +++ b/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtests.ts @@ -41,6 +41,11 @@ const a: ma.TaskLibAnswers = { 'findMatch': { 'temp.csproj': ['c:\\agent\\home\\directory\\temp.csproj'], '**/*.trx': ['c:\\agent\\home\\temp\\sample.trx'] + }, + "rmRF": { + "c:\\agent\\home\\temp\\sample.trx": { + "success": true + } } }; nmh.setAnswers(a); diff --git a/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtestsWithFailedTestCommand.ts b/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtestsWithFailedTestCommand.ts index 9923eb507793..892536111dc6 100644 --- a/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtestsWithFailedTestCommand.ts +++ b/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtestsWithFailedTestCommand.ts @@ -41,6 +41,11 @@ const a: ma.TaskLibAnswers = { 'findMatch': { 'temp.csproj': ['c:\\agent\\home\\directory\\temp.csproj'], '**/*.trx': ['c:\\agent\\home\\temp\\sample.trx'] + }, + "rmRF": { + "c:\\agent\\home\\temp\\sample.trx": { + "success": true + } } }; nmh.setAnswers(a); diff --git a/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtestsWithoutBuildConfig.ts b/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtestsWithoutBuildConfig.ts index 21ac37c46886..f3af235feb75 100644 --- a/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtestsWithoutBuildConfig.ts +++ b/Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtestsWithoutBuildConfig.ts @@ -39,6 +39,11 @@ const a: ma.TaskLibAnswers = { 'findMatch': { 'temp.csproj': ['c:\\agent\\home\\directory\\temp.csproj'], '**/*.trx': ['c:\\agent\\home\\temp\\sample.trx'] + }, + "rmRF": { + "c:\\agent\\home\\temp\\sample.trx": { + "success": true + } } }; nmh.setAnswers(a);