Skip to content

Commit

Permalink
Adding fix for removing old trx files in case of multiple test tasks (#…
Browse files Browse the repository at this point in the history
…6615)

* Adding fix for removing old trx files in case of multiple test tasks

* Fixing tests
  • Loading branch information
prawalagarwal authored Mar 8, 2018
1 parent a035732 commit 061c443
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Tasks/DotNetCoreCLI/Tests/TestCommandTests/publishtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const a: ma.TaskLibAnswers = <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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const a: ma.TaskLibAnswers = <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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const a: ma.TaskLibAnswers = <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);
Expand Down
16 changes: 16 additions & 0 deletions Tasks/DotNetCoreCLI/dotnetcore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLI/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"demands": [],
"version": {
"Major": 2,
"Minor": 131,
"Minor": 132,
"Patch": 0
},
"minimumAgentVersion": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLI/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"demands": [],
"version": {
"Major": 2,
"Minor": 131,
"Minor": 132,
"Patch": 0
},
"minimumAgentVersion": "2.0.0",
Expand Down

0 comments on commit 061c443

Please sign in to comment.