Skip to content
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

VSTest task changes #2

Closed
wants to merge 13 commits into from
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ gulp

Tasks will be created in the _build directory. It will also generate a tasks.loc.json and an english strings file under Strings in your source tree. You can check these back in. Another localization process will create the other strings files.

### Package
This must be done on a windows machine with nuget.exe in the path
From the root of the repo (replace version with appropriate version)
```bash
gulp package --version 1.0.29
```

Tasks will be create a nuget package in the _package directory.
2 changes: 1 addition & 1 deletion Tasks/NpmInstall/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "NpmInstall",
"friendlyName": "npm install",
"description": "install npm packages",
"category": "Build",
"category": "Package",
"author": "Microsoft Corporation",
"version": {
"Major": 0,
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NpmInstall/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "NpmInstall",
"friendlyName": "ms-resource:loc.friendlyName",
"description": "ms-resource:loc.description",
"category": "Build",
"category": "Package",
"author": "Microsoft Corporation",
"version": {
"Major": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"loc.group.displayName.advanced": "Advanced",
"loc.input.label.testAssembly": "Test Assembly",
"loc.input.label.testFiltercriteria": "Test Filter criteria",
"loc.input.label.platform": "Platform",
"loc.input.label.configuration": "Configuration",
"loc.input.label.overrideTestrunParameters": "Override TestRun Parameters",
"loc.input.label.runSettingsFile": "Run Settings File",
"loc.input.label.codeCoverageEnabled": "Code Coverage Enabled",
"loc.input.label.otherConsoleOptions": "Other console options",
Expand Down
19 changes: 16 additions & 3 deletions Tasks/VsTest/VSTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ param(
[string]$runSettingsFile,
[string]$codeCoverageEnabled,
[string]$pathtoCustomTestAdapters,
[string]$otherConsoleOptions
[string]$overrideTestrunParameters,
[string]$otherConsoleOptions,
[string]$platform,
[string]$configuration
)

Write-Verbose "Entering script VSTestConsole.ps1"

# Import the Task.Common dll that has all the cmdlets we need for Build
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common"
# Import the Task.TestResults dll that has the cmdlet we need for publishing results
import-module "Microsoft.TeamFoundation.DistributedTask.Task.TestResults"

if (!$testAssembly)
{
Expand All @@ -38,9 +43,17 @@ if($testAssemblyFiles)
{
Write-Verbose "Calling Invoke-VSTest for all test assemblies"
$timeline = Start-Timeline -Context $distributedTaskContext
$cwd = Get-Location
$projectName = Get-Variable -Context $distributedTaskContext -Name "System.TeamProject"
$buildDir = Get-Variable -Context $distributedTaskContext -Name "Agent.BuildDirectory" -Global $FALSE
$buildNumber = Get-Variable -Context $distributedTaskContext -Name "Build.BuildNumber"
$buildUri = Get-Variable -Context $distributedTaskContext -Name "Build.BuildUri"
$owner = Get-Variable -Context $distributedTaskContext -Name "Build.RequestedFor"
$cwd = $buildDir
$testResultsDir = $buildDir+"\"+"TestResults"
Write-Verbose "Calling Invoke-VSTest from working folder: $cwd"
Invoke-VSTest -TestAssemblies $testAssemblyFiles -Timeline $timeline -VSTestVersion $vsTestVersion -TestFiltercriteria $testFiltercriteria -RunSettingsFile $runSettingsFile -PathtoCustomTestAdapters $pathtoCustomTestAdapters -CodeCoverageEnabled $codeCoverage -OtherConsoleOptions $otherConsoleOptions -WorkingFolder $cwd
Invoke-VSTest -TestAssemblies $testAssemblyFiles -Timeline $timeline -VSTestVersion $vsTestVersion -TestFiltercriteria $testFiltercriteria -RunSettingsFile $runSettingsFile -PathtoCustomTestAdapters $pathtoCustomTestAdapters -CodeCoverageEnabled $codeCoverage -OverrideTestrunParameters $overrideTestrunParameters -OtherConsoleOptions $otherConsoleOptions -WorkingFolder $cwd -TestResultsFolder $testResultsDir
$connection = Get-VssConnection -TaskContext $distributedTaskContext
Invoke-ResultPublisher -Connection $connection -ProjectName $projectName -Owner $owner -TestResultsFolder $testResultsDir -Extension "trx" -ResultType "Trx" -BuildUri $buildUri -BuildNumber $buildNumber -Platform $platform -Configuration $configuration
}
else
{
Expand Down
50 changes: 37 additions & 13 deletions Tasks/VsTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 8
"Patch": 9
},
"demands": [
"vstest"
Expand Down Expand Up @@ -41,30 +41,45 @@
"required": false,
"helpMarkDown": "Filter criteria for the tests."
},
{
"name": "platform",
"type": "string",
"label": "Platform",
"defaultValue":"",
"required":false
},
{
"name": "configuration",
"type": "string",
"label": "Configuration",
"defaultValue":"",
"required":false
},
{
"name": "runSettingsFile",
"type": "filePath",
"label": "Run Settings File",
"defaultValue": "",
"required": false,
"helpMarkDown": "The run settings file to use."
"helpMarkDown": "Path to runsettings file to use with the Tests. Use $(agent.BuildDirectory)\\$(system.teamProject) to access the Project folder"
},
{
"name": "codeCoverageEnabled",
"type": "boolean",
"label": "Code Coverage Enabled",
"defaultValue": "True",
"required": false,
"helpMarkDown": "Whether code coverage needs to be enabled."
},
{
"name": "otherConsoleOptions",
"name": "overrideTestrunParameters",
"type": "string",
"label": "Other console options",
"label": "Override TestRun Parameters",
"defaultValue": "",
"required": false,
"helpMarkDown": "Any other console options to be used."
"helpMarkDown": "Override parameters defined in the TestRunParameters section of runsettings file. For example: Platform=$(platform);Port=8080"
},
{
"name": "codeCoverageEnabled",
"type": "boolean",
"label": "Code Coverage Enabled",
"defaultValue": "False",
"required": false,
"helpMarkDown": "Whether code coverage needs to be enabled.",
"groupName":"advanced"
},
{
"name": "vsTestVersion",
"type": "pickList",
Expand All @@ -86,6 +101,15 @@
"required": false,
"helpMarkDown": "Path to custom adapters.",
"groupName":"advanced"
},
{
"name": "otherConsoleOptions",
"type": "string",
"label": "Other console options",
"defaultValue": "",
"required": false,
"helpMarkDown": "Other console options.",
"groupName": "advanced"
}
],
"instanceNameFormat": "Test Assemblies $(testAssembly)",
Expand Down
46 changes: 35 additions & 11 deletions Tasks/VsTest/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 8
"Patch": 9
},
"demands": [
"vstest"
Expand Down Expand Up @@ -44,29 +44,44 @@
"required": false,
"helpMarkDown": "Filter criteria for the tests."
},
{
"name": "platform",
"type": "string",
"label": "ms-resource:loc.input.label.platform",
"defaultValue":"",
"required":false
},
{
"name": "configuration",
"type": "string",
"label": "ms-resource:loc.input.label.configuration",
"defaultValue":"",
"required":false
},
{
"name": "runSettingsFile",
"type": "filePath",
"label": "ms-resource:loc.input.label.runSettingsFile",
"defaultValue": "",
"required": false,
"helpMarkDown": "The run settings file to use."
"helpMarkDown": "Path to runsettings file to use with the Tests. Use $(agent.BuildDirectory)\\$(system.teamProject) to access the Project folder"
},
{
"name": "overrideTestrunParameters",
"type": "string",
"label": "ms-resource:loc.input.label.overrideTestrunParameters",
"defaultValue": "",
"required": false,
"helpMarkDown": "Override parameters defined in the TestRunParameters section of runsettings file. For example: Platform=$(platform);Port=8080"
},
{
"name": "codeCoverageEnabled",
"type": "boolean",
"label": "ms-resource:loc.input.label.codeCoverageEnabled",
"defaultValue": "True",
"required": false,
"helpMarkDown": "Whether code coverage needs to be enabled."
},
{
"name": "otherConsoleOptions",
"type": "string",
"label": "ms-resource:loc.input.label.otherConsoleOptions",
"defaultValue": "",
"required": false,
"helpMarkDown": "Any other console options to be used."
"helpMarkDown": "Whether code coverage needs to be enabled.",
"groupName":"advanced"
},
{
"name": "vsTestVersion",
Expand All @@ -89,6 +104,15 @@
"required": false,
"helpMarkDown": "Path to custom adapters.",
"groupName": "advanced"
},
{
"name": "otherConsoleOptions",
"type": "string",
"label": "ms-resource:loc.input.label.otherConsoleOptions",
"defaultValue": "",
"required": false,
"helpMarkDown": "Other console options.",
"groupName": "advanced"
}
],
"instanceNameFormat": "Test Assemblies $(testAssembly)",
Expand Down
19 changes: 11 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,9 @@ gulp.task('package', ['zip'], function(done) {
if (!semver.valid(version)) {
done(new gutil.PluginError('PackageTask', 'invalid semver version: ' + version));
return;
}
}

var server = options.server;
if (!server) {
done(new gutil.PluginError('PackageTask', 'supply nuget server with --server'));
return;
}

shell.mkdir('-p', _pkgRoot);

Expand Down Expand Up @@ -126,9 +122,16 @@ gulp.task('package', ['zip'], function(done) {
var cmdline = '"' + nugetPath + '" pack ' + nuspecPath + ' -OutputDirectory ' + _pkgRoot;
QExec(cmdline)
.then(function() {
var pkgLocation = path.join(_pkgRoot, pkgName + '.' + version + '.nupkg');
var cmdline = '"' + nugetPath + '" push ' + pkgLocation + ' -Source ' + server;
return QExec(cmdline);
// publish only if version and source supplied - used by CI server that does official publish
if (server) {
var pkgLocation = path.join(_pkgRoot, pkgName + '.' + version + '.nupkg');
var cmdline = '"' + nugetPath + '" push ' + pkgLocation + ' -Source ' + server;
return QExec(cmdline);
}
else {
return;
}

})
.then(function() {
done();
Expand Down