Giter VIP home page Giter VIP logo

azuredevopsextension's Introduction

Pester

💵 Please consider sponsoring nohwnd, fflaten or sponsoring Pester itself.

🌵 Documentation is available at https://pester.dev/docs/quick-start.

📦🔐 Pester is now signed. -SkipPublisherCheck should no longer be used to install from PowerShell Gallery on Windows 10.

📦🔐 Upgrading to 5.6.0 will show a "certificate changed" error, this is because a change in Root Certificate, and you have to specify -SkipPublisherCheck to update. More info below.

👩👨 We are looking for contributors! All issues labeled help wanted are up for grabs. They further split up into good first issue that are issues I hope are easy to solve. Bad first issue where I expect the implementation to be problematic or needs to be proposed and discussed beforehand. And the rest which is somewhere in the middle. If you decide to pick up an issue please comment in the issue thread so others don't waste their time working on the same issue as you. There is also contributor's guide that will hopefully help you.

Pester is the ubiquitous test and mock framework for PowerShell.

BeforeAll {
    # your function
    function Get-Planet ([string]$Name='*')
    {
        $planets = @(
            @{ Name = 'Mercury' }
            @{ Name = 'Venus'   }
            @{ Name = 'Earth'   }
            @{ Name = 'Mars'    }
            @{ Name = 'Jupiter' }
            @{ Name = 'Saturn'  }
            @{ Name = 'Uranus'  }
            @{ Name = 'Neptune' }
        ) | foreach { [PSCustomObject]$_ }

        $planets | where { $_.Name -like $Name }
    }
}

# Pester tests
Describe 'Get-Planet' {
  It "Given no parameters, it lists all 8 planets" {
    $allPlanets = Get-Planet
    $allPlanets.Count | Should -Be 8
  }

  Context "Filtering by Name" {
    It "Given valid -Name '<Filter>', it returns '<Expected>'" -TestCases @(
      @{ Filter = 'Earth'; Expected = 'Earth' }
      @{ Filter = 'ne*'  ; Expected = 'Neptune' }
      @{ Filter = 'ur*'  ; Expected = 'Uranus' }
      @{ Filter = 'm*'   ; Expected = 'Mercury', 'Mars' }
    ) {
      param ($Filter, $Expected)

      $planets = Get-Planet -Name $Filter
      $planets.Name | Should -Be $Expected
    }

    It "Given invalid parameter -Name 'Alpha Centauri', it returns `$null" {
      $planets = Get-Planet -Name 'Alpha Centauri'
      $planets | Should -Be $null
    }
  }
}

Save this code example in a file named Get-Planet.Tests.ps1, and run Invoke-Pester Get-Planet.Tests.ps1, or just press F5 in VSCode.

Learn how to start quick with Pester in our docs.

The example above also has an annotated and production ready version here.

Installation

Pester runs on Windows, Linux, MacOS and anywhere else thanks to PowerShell. It is compatible with Windows PowerShell 5.1 and PowerShell 7.2 and newer.

Pester 3 comes pre-installed with Windows 10, but we recommend updating, by running this PowerShell command as administrator:

Install-Module -Name Pester -Force

Not running Windows 10 or facing problems? See the full installation and update guide.

Signing certificates

The certificate used for signing the code has changed in 5.6.0. Error is shown when updating the module. Below is the list of the certificates you can expect to be used when importing the module (going back to 2016)

Version Authority Thumbprint
6.0.0-alpha4+ CN=DigiCert Trusted G4 Code Signing RSA4096 SHA384 2021 CA1, O="DigiCert, Inc.", C=US 147C2FD397677DC76DD198E83E7D9D234AA59D1A
5.6.0+ CN=DigiCert Trusted G4 Code Signing RSA4096 SHA384 2021 CA1, O="DigiCert, Inc.", C=US 2FCC9148EC2C9AB951C6F9654C0D2ED16AF27738
5.2.0 - 5.5.0 CN=DigiCert SHA2 Assured ID Code Signing CA, OU=www.digicert.com, O=DigiCert Inc, C=US C7B0582906E5205B8399D92991694A614D0C0B22
4.10.0 - 5.1.1 CN=DigiCert SHA2 Assured ID Code Signing CA, OU=www.digicert.com, O=DigiCert Inc, C=US 7B9157664392D633EDA2C0248605C1C868EBDE43
4.4.3 - 4.9.0 CN=DigiCert SHA2 Assured ID Code Signing CA, OU=www.digicert.com, O=DigiCert Inc, C=US CC1168BAFCDA3B1A5E532DA87E80A4DD69BCAEB1
3.0.3 - 4.4.2 No Certificate Found No Certificate Found
3.4.0 CN=Microsoft Windows Production PCA 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US 71F53A26BB1625E466727183409A30D03D7923DF

In all cases, except for version 3.4.0 that was signed directly by Microsoft, the Authenticode issuer for certificate is CN=Jakub Jareš, O=Jakub Jareš, L=Praha, C=CZ.

To successfully update the module when certificate changed, you need to provide -SkipPublisherCheck to the Install-Module command.

Features

Test runner

Pester runs your tests and prints a nicely formatted output to the screen.

test run output

Command line output is not the only output option, Pester also integrates with Visual Studio Code, Visual Studio, and any tool that can consume nUnit XML output.

Assertions

Pester comes with a suite of assertions that cover a lot of common use cases. Pester assertions range from very versatile, like Should -Be, to specialized like Should -Exists. Here is how you ensure that a file exists:

Describe 'Notepad' {
    It 'Exists in Windows folder' {
        'C:\Windows\notepad.exe' | Should -Exist
    }
}

Learn more about assertions in our documentation.

Mocking

Pester has mocking built-in. Using mocks you can easily replace functions with empty implementation to avoid changing the real environment.

function Remove-Cache {
    Remove-Item "$env:TEMP\cache.txt"
}

Describe 'Remove-Cache' {
    It 'Removes cached results from temp\cache.text' {
        Mock -CommandName Remove-Item -MockWith {}

        Remove-Cache

        Should -Invoke -CommandName Remove-Item -Times 1 -Exactly
    }
}

Learn more about Mocking here.

Code coverage

Pester can measure how much of your code is covered by tests and export it to JaCoCo format that is easily understood by build servers.

JaCoCo code coverage report

Learn more about code coverage here.

Build server integration

Pester integrates nicely with TFS, AppVeyor, TeamCity, Jenkins and other CI servers.

Testing your scripts, and all pull requests on AppVeyor is extremely simple. Just commit this appveyor.yml file to your repository, and select your repository on the AppVeyor website:

version: 1.0.{build}
image:
  - Visual Studio 2017
  - Ubuntu
install:
  - ps: Install-Module Pester -Force -Scope CurrentUser
build: off
test_script:
  - ps: Invoke-Pester -EnableExit

See it in action here! If you do not need to test your scripts against PowerShell Core, just simply remove the entire line mentioning Ubuntu.

Pester itself is built on AzureDevOps, and distributed mainly via PowerShell gallery.

Build Status latest version downloads

Further reading

Do you like what you see? Learn how to use Pester with our quick start guide.

Got questions?

Got questions or you just want to get in touch? Use our issues page or one of these channels:

Pester Twitter Pester on StackOverflow Testing channel on Powershell Slack Testing channel on Powershell Discord or try github discussions GitHub discussions.

Sponsored by

Pester is sponsored by Octopus Deploy.

Octopus deploy

As well as all the great folks on OpenCollective and GitHub.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. Contribute code.

Financial Contributors on Open Collective

Become a financial contributor and help us sustain our community. Contribute to Pester Open Collective.

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. Contribute

azuredevopsextension's People

Contributors

bm-fez avatar chrislgardner avatar esiebes avatar jpruskin avatar nohwnd avatar pwshaddict avatar rfennell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

azuredevopsextension's Issues

CodeCoverage.xml fails to include all files from -CodeCoverageFolder

Where are you running it?

You can run the extensions in the cloud or on-premise

  • Azure DevOps Service (VSTS)

Version of Extension/Task

10.1.17

Expected behaviour and actual behaviour

I expected all .ps1 files to be used for the codecoverage.xml file but only the ones in the ./tests folder show results.

Steps to reproduce the problem

Set -CodeCoverageFolder . or to the base folder
├───.vscode
├───docs
│ └───images
├───ModuleFolder
│ ├───private
│ └───public
├───TestResults
└───Tests

azure-pipelines.yml file:

 - task: Pester@10
      displayName: Pester Test Runner
      inputs:
        TestFolder: './tests'
        resultsFile: '$(Common.TestResultsDirectory)/Test-Pester.XML'
        CodeCoverageOutputFile: '$(Common.TestResultsDirectory)/CC-Pester.XML'
        usePSCore: ${{ parameters.pscore }}
        CodeCoverageFolder: '$(Build.Repository.LocalPath)/'
        PesterVersion: OtherVersion
        preferredPesterVersion: 5.0.2
        additionalModulePath: '$(System.DefaultWorkingDirectory)/**/*.psm1'

Findings during testing

$pesterConfig is correct and $pesterconfig.CodeCoverage.Path returns all the files.

$PesterConfig['CodeCoverage'] = $CodeCoverage

if (-not([String]::IsNullOrWhiteSpace($ScriptBlock))) {
    $ScriptBlockObject = [ScriptBlock]::Create($ScriptBlock)

    $ScriptBlockObject.Invoke()
}

$result = Invoke-Pester -Configuration  ([PesterConfiguration]$PesterConfig)

However, when the configuration object is created, ([PesterConfiguration]$PesterConfig).CodeCoverage.Path.Value is an empty array.

Pester Task Faling

Running on Linux Azure Agent

Using Latest Pester Test Runner: 10.2.4 (Latest)

When i run the task with a HASH TABLE including Parameters it fails

  • task: Pester@10
    inputs:
    scriptFolder: '@{Path=’$(System.DefaultWorkingDirectory)\server.template.tests.ps1′; Parameters=@{ResourceGroupName=''$(azure_resource_group_name)''}}'
    resultsFile: '$(System.DefaultWorkingDirectory)\server.template.tests.XML'
    usePSCore: true

Failure:

##[error]Get-ChildItem: /usr/local/share/powershell/Modules/Pester/5.0.4/Pester.psm1:3165
Line |
3165 | Get-ChildItem -Recurse -Path $p -Filter "*$Extension" -Fi …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find path
| '/home/vsts/work/1/s/@{Path=’/home/vsts/work/1/s/' because it
| does not exist.

##[debug]Processed: ##vso[task.issue type=error;]Get-ChildItem: /usr/local/share/powershell/Modules/Pester/5.0.4/Pester.psm1:3165%0ALine |%0A3165 | Get-ChildItem -Recurse -Path $p -Filter "$Extension" -Fi …%0A | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%0A | Cannot find path%0A | '/home/vsts/work/1/s/@{Path=’/home/vsts/work/1/s/' because it%0A | does not exist.%0A%0A
##[debug]task result: Failed
##[error]Get-ChildItem: /usr/local/share/powershell/Modules/Pester/5.0.4/Pester.psm1:3165
Line |
3165 | Get-ChildItem -Recurse -Path $p -Filter "
$Extension" -Fi …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot find path
| '/home/vsts/work/1/s/@{Path=’/home/vsts/work/1/s/' because it
| does not exist.

When I run the Task without parameters and modify the script to not require parameters it works:

  • task: Pester@10
    inputs:

scriptFolder: '$(System.DefaultWorkingDirectory)/server.template.tests.ps1'
resultsFile: "$(System.DefaultWorkingDirectory)/server.template.tests.XML"
usePSCore: true
run32Bit: False

Running in PowerShell

Starting discovery in 1 files.

Discovery finished in 665ms.

[+] /home/vsts/work/1/s/server.template.tests.ps1
2.36s (1.38s|344ms)

Tests completed in 2.39s

Tests Passed: 1,
Failed: 0,
Skipped: 0
NotRun: 0

Pester Script finished
Finishing: Pester

The term 'C:\Program' is not recognized as the name of a cmdlet

Where are you running it?

On-prem Azure DevOps Server

Version of Extension/Task

10.3.10

Expected behaviour and actual behaviour

Expected Pester to run when executed by an agent installed in the Program Files directory.

However, it looks like it's not quoting itself:

powershell.exe C:\Program Files\vsts-agent-win-x64-2.160.1\_work\(snip)\10.3.10\Pester.ps1

Here's the full script output:

Starting: Run unit tests
==============================================================================
Task         : Pester Test Runner
Description  : Run Pester tests by either installing the latest version of Pester at run time (if possible) or using the version shipped with the task (5.0.0)
Version      : 10.3.10
Author       : Pester
Help         : Version: #{Build.BuildNumber}#. [More Information](https://github.com/pester/AzureDevOpsExtension)
==============================================================================
Using executable 'powershell.exe'
powershell.exe C:\Program Files\vsts-agent-win-x64-2.160.1\_work\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.3.10\Pester.ps1 -TestFolder C:\Program Files\vsts-agent-win-x64-2.160.1\_work\3\s\* -resultsFile C:\Program Files\vsts-agent-win-x64-2.160.1\_work\3/Pester-Results.xml -run32Bit False -FailOnStdErr true -CodeCoverageOutputFile C:\Program Files\vsts-agent-win-x64-2.160.1\_work\3/Pester-Coverage.xml
##[error]C:\Program : The term 'C:\Program' is not recognized as the name of a cmdlet, 

##[error]C:\Program : The term 'C:\Program' is not recognized as the name of a cmdlet, 

##[error]function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ C:\Program Files\vsts-agent-win-x64-2.160.1\_work\_tasks\Pester_cca54 ...
+ ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program:String) [], CommandN 
   otFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Steps to reproduce the problem

Very simple task usage in my DevOps pipeline:

- task: Pester@10
  displayName: 'Run unit tests'
  inputs:
    resultsFile: '$(Pipeline.Workspace)/Pester-Results.xml'
    CodeCoverageOutputFile: '$(Pipeline.Workspace)/Pester-Coverage.xml'

Please document how to use this better. Pester fails, because it can't find the module under test

Where are you running it?

You can run the extensions in the cloud or on-premise

  • Azure DevOps Service (VSTS)
  • Azure DevOps Server (on-premise TFS, if so what version)

Running on Azure DevOps Service (VSTS)

Version of Extension/Task

I assume it is the currently public version, if you are using an older version on-premises let me know, but the answer will probably involve upgrading to the currently public version

Using latest version (task definition: Pester@10)

Expected behaviour and actual behaviour

Run the tests succesfully, using latest version of Pester (5.0.3)

Steps to reproduce the problem

Install the Pester Test Run from the marketplace in my Azure Organisation. I assume by doing so, any project within the organisation can define pipelines with a task: Pester@10.

To use the latest version of Pester set PesterVersion='LatestVersion|OtherVersion' and preferredPesterVersion to '5.0.3'.

I have 3 tasks under the same job:

  1. bootstrap: installs and imports dependencies
  2. build the module. The module is constructed by assembling all ps1 sources into the psm1 file.
  3. run Pester. This needs to use the module built in the previous step, but how do you correctly tell pester to use this just built module?

Here is my pipeline yaml:

name: $(Build.DefinitionName)_$(Date:yyyyMMdd))

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  major: 0
  minor: 0
  patch: $(Build.BuildID)
  buildVersion: $(major).$(minor).$(patch)
  system.debug: true

stages:
- stage: Build
  jobs:
    - job: Build
      steps:
      - powershell: ./bootstrap.ps1
        displayName: 'Install pre-requisites'
      - task: PowerShell@2
        displayName: 'Perform build'
        inputs:
          pwsh: true
          failOnStderr: true
          targetType: 'filePath'
          filePath: '$(System.DefaultWorkingDirectory)/do-build.ps1'
      - task: Pester@10
        inputs:
          PesterVersion: 'LatestVersion|OtherVersion'
          preferredPesterVersion: '5.0.3'
          scriptFolder: '$(System.DefaultWorkingDirectory)\Elizium.FakeBuddy\Tests\*'
          resultsFile: '$(System.DefaultWorkingDirectory)\Test-Pester.XML'
          usePSCore: true
          additionalModulePath: '$(System.DefaultWorkingDirectory)\Elizium.FakeBuddy\Output\Elizium.FakeBuddy\Elizium.FakeBuddy.psd1'

Please note that every thing works on local host, so this issue has nothing to do with me not writing correct powershell or writing faulty powershell tests. This is simply an issue of telling Pester on Azure to use the dynamically generated module.

I think the problem is something to do with "additionalModulePath", the documentation on this is not specific enough.

'$(System.DefaultWorkingDirectory) = the root of the git hub repo; FakeBuddy
The build task constructs the module at FakeBuddy/Elizium.FakeBuddy/Output/Elizium.FakeBuddy
and inside this location are Elizium.FakeBuddy.psd1 and Elizium.FakeBuddy.psm1

This is the module that Pester should be running the tests against.

Setting the additionalModulePath to "FakeBuddy\Elizium.FakeBuddy\Output\Elizium.FakeBuddy" (ie $(System.DefaultWorkingDirectory)\Elizium.FakeBuddy\Output\Elizium.FakeBuddy) does not work.

Setting additionalModulePath to the psd1 in that directory does not work.

The documentation says this:

Path to additional PowerShell modules - Any additional module paths that should be prepended to the PSModulePath before running Pester.

but this doesnt specify what input this refers to. If I assume it is the additionalModulePath input, then setting it to "$(System.DefaultWorkingDirectory)\Elizium.FakeBuddy\Output\Elizium.FakeBuddy" (ie the module just built), should work but it doesnt.

Actually, to come to think of it, it may have something to do with using invoke-build. I use invoke-build locally and that works. In fact invoke-build is used in the previous task PowerShell@2 to build the module. Should Pester just run an invoke-build task? What do I have to do here??

Here is the log showing the failure:

Starting discovery in 3 files.

Discovery finished in 202ms.

[-] Describe join-AllSchemas failed

 FileNotFoundException: The specified module '.\Output\Elizium.FakeBuddy\Elizium.FakeBuddy.psm1' was not loaded because no valid module file was found in any module directory.
 at <ScriptBlock>, /home/vsts/work/1/s/Elizium.FakeBuddy/Tests/Internal/join-AllSchemas.tests.ps1:4

[-] Describe merge-SettingsContent failed

 FileNotFoundException: The specified module '.\Output\Elizium.FakeBuddy\Elizium.FakeBuddy.psm1' was not loaded because no valid module file was found in any module directory.
 at <ScriptBlock>, /home/vsts/work/1/s/Elizium.FakeBuddy/Tests/Internal/merge-SettingsContent.tests.ps1:4

[-] Describe ConvertFrom-ItermColors failed


 FileNotFoundException: The specified module '.\Output\Elizium.FakeBuddy\Elizium.FakeBuddy.psm1' was not loaded because no valid module file was found in any module directory.
 at <ScriptBlock>, /home/vsts/work/1/s/Elizium.FakeBuddy/Tests/Public/ConvertFro
m-ItermColors.tests.ps1:4


Tests completed in 641ms

Tests Passed: 0, 
Failed: 12, 
Skipped: 0 
NotRun: 0

BeforeAll \ AfterAll failed: 3

  - join-AllSchemas
  - merge-SettingsContent
  - ConvertFrom-ItermColors

##[error]Write-Error: Pester Failed at least one test. Please see results for details.

##[debug]Processed: ##vso[task.issue type=error;]Write-Error: Pester Failed at least one test. Please see results for details.%0A
##[debug]task result: Failed
##[error]Write-Error: Pester Failed at least one test. Please see results for details.

##[debug]Processed: ##vso[task.issue type=error;]Write-Error: Pester Failed at least one test. Please see results for details.%0A
##[debug]Processed: ##vso[task.complete result=Failed;]Write-Error: Pester Failed at least one test. Please see results for details.%0A
Pester Script finished
Finishing: Pester

... so you can see that Pester can find the tests, but is not running them correctly for whatever reason.

I changed additionalModulePath to $(System.DefaultWorkingDirectory)\Elizium.FakeBuddy\Output

Seeing this in the log

Adding additional module path [/home/vsts/work/1/s\Elizium.FakeBuddy\Output] to $env:PSModulePath

makes me think this is correct. Perhaps Pester is not importing the generated module. How can I enforce this additional import?

But the question is, if I build a module in 1 task, is that module available in the following task. WHat happens in between tasks, are directories deleted? Do I have to combine them both into the same task, if so how? Pester can't build a module, and the PowerShell@2 task can't run the test, otherwise there would be no need for this (AzureDevOpsExtension) module right??

Pester module cannot be retrieved

Where are you running it?

  • Azure DevOps Service (VSTS)

Version of Extension/Task

10.0.3

Expected behaviour and actual behaviour

Pester Test Runner should not throw errors when using the new version

image

Steps to reproduce the problem

All I did was switching the task from v9 to v10 in a working build pipeline.
The issue is happening on Azure Pipelines agents and self-hosted agents as well.

Is it something on our end?

Extension stopped working this week without any modification

Where are you running it?

You can run the extensions in the cloud or on-premise

  • Azure DevOps Service (VSTS)

Version of Extension/Task

Version 9.2

Expected behaviour and actual behaviour

I started having this issue at the beginning of this week. Last week everything worked fine and I did not change anything in the pipeline. My agents are natively managed by Microsoft. I also checked that you guys have not updated anything so I do not get this issue, struggling with it since Monday.

I got the following error message:

2020-07-22T08:07:52.1896679Z ##[section]Starting: Test task
2020-07-22T08:07:52.2099288Z ==============================================================================
2020-07-22T08:07:52.2102874Z Task         : Pester Test Runner
2020-07-22T08:07:52.2103373Z Description  : Run Pester tests by either installing the latest version of Pester at run time (if possible) or using the version shipped with the task (4.10.1)
2020-07-22T08:07:52.2106185Z Version      : 9.2.0
2020-07-22T08:07:52.2110245Z Author       : Pester
2020-07-22T08:07:52.2114055Z Help         : Version: #{Build.BuildNumber}#. [More Information](https://github.com/pester/AzureDevOpsExtension)
2020-07-22T08:07:52.2114509Z ==============================================================================
2020-07-22T08:07:52.6386061Z Using executable 'powershell.exe'
2020-07-22T08:07:52.6389760Z powershell.exe D:\a\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\Pester.ps1 -scriptFolder @{Path='D:\a\r1\a\\_APIM_Migration\\test\\test.tests.ps1'; Parameters=@{someInput ='111'}} -resultsFile D:\a\r1\a\Test-Pester.XML -run32Bit False
2020-07-22T08:07:56.7580602Z scriptFolder System.Collections.Hashtable
2020-07-22T08:07:56.7589597Z 
2020-07-22T08:07:56.7592461Z 
2020-07-22T08:07:56.7630337Z resultsFile D:\a\r1\a\Test-Pester.XML
2020-07-22T08:07:56.7631352Z 
2020-07-22T08:07:56.7632654Z 
2020-07-22T08:07:56.7662240Z run32Bit False
2020-07-22T08:07:56.7666847Z 
2020-07-22T08:07:56.7667934Z 
2020-07-22T08:07:56.7686762Z additionalModulePath 
2020-07-22T08:07:56.7710677Z 
2020-07-22T08:07:56.7711662Z 
2020-07-22T08:07:56.7774558Z tag 
2020-07-22T08:07:56.7775036Z 
2020-07-22T08:07:56.7775398Z 
2020-07-22T08:07:56.7788461Z ExcludeTag 
2020-07-22T08:07:56.7788924Z 
2020-07-22T08:07:56.7809548Z CodeCoverageOutputFile 
2020-07-22T08:07:56.7810426Z 
2020-07-22T08:07:56.7811177Z 
2020-07-22T08:07:56.7834636Z CodeCoverageFolder 
2020-07-22T08:07:56.7835808Z 
2020-07-22T08:07:56.7836357Z 
2020-07-22T08:07:56.7850898Z ScriptBlock 
2020-07-22T08:07:56.7858521Z 
2020-07-22T08:07:56.7859004Z 
2020-07-22T08:08:12.2369277Z ##[error]Import-Module : The specified module 'Pester' with version '4.10.1' was not loaded because no valid module file was 

2020-07-22T08:08:12.2381500Z ##[error]Import-Module : The specified module 'Pester' with version '4.10.1' was not loaded because no valid module file was 

2020-07-22T08:08:12.2384964Z ##[error]found in any module directory.
At D:\a\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\HelperModule.psm1:61 char:13
+             Import-Module -Name Pester -RequiredVersion $NewestPester ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Pester:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleWithVersionNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
 

2020-07-22T08:08:12.2388532Z ##[error]found in any module directory.
At D:\a\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\HelperModule.psm1:61 char:13
+             Import-Module -Name Pester -RequiredVersion $NewestPester ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Pester:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleWithVersionNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
 

2020-07-22T08:08:12.2432705Z Running in AMD64 PowerShell
2020-07-22T08:08:12.2434190Z 
2020-07-22T08:08:12.2434410Z 
2020-07-22T08:08:12.3522147Z Running Pester using the script parameter [
2020-07-22T08:08:12.3522953Z Name                           Value                                                                                   
2020-07-22T08:08:12.3523744Z ----                           -----                                                                                   
2020-07-22T08:08:12.3525038Z Path                           D:\a\r1\a\\_APIM_Migration\\test\\test.tests.ps1                                        
2020-07-22T08:08:12.3528411Z Parameters                     {someInput}                                                                             
2020-07-22T08:08:12.3528947Z 
2020-07-22T08:08:12.3529111Z 
2020-07-22T08:08:12.3529433Z ] output sent to [D:\a\r1\a\Test-Pester.XML]
2020-07-22T08:08:12.3529716Z 
2020-07-22T08:08:12.3529877Z 
2020-07-22T08:08:14.6136450Z WARNING: You are using Legacy parameter set that adapts Pester 5 syntax to Pester 4 syntax. This parameter set is 
2020-07-22T08:08:14.6137844Z deprecated, and does not work 100%. The -Strict and -PesterOption parameters are ignored, and providing advanced 
2020-07-22T08:08:14.6138912Z configuration to -Path (-Script), and -CodeCoverage via a hash table does not work. Please refer to 
2020-07-22T08:08:14.6140037Z https://github.com/pester/Pester/releases/tag/5.0.1#legacy-parameter-set for more information.
2020-07-22T08:08:14.6140332Z 
2020-07-22T08:08:14.6140422Z 
2020-07-22T08:08:15.9033221Z System.Management.Automation.RuntimeException: No test files were found and no scriptblocks were provided.
2020-07-22T08:08:15.9034351Z at Invoke-Pester<End>, C:\Program Files\WindowsPowerShell\Modules\Pester\5.0.2\Pester.psm1: line 4197
2020-07-22T08:08:15.9035636Z at <ScriptBlock>, D:\a\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\Pester.ps1: line 142
2020-07-22T08:08:15.9038264Z at <ScriptBlock>, <No file>: line 1
2020-07-22T08:08:15.9038554Z 
2020-07-22T08:08:15.9038721Z 
2020-07-22T08:08:15.9408907Z ##[error]D:\a\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\Pester.ps1 : Pester returned errors

2020-07-22T08:08:15.9413400Z ##[error]D:\a\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\Pester.ps1 : Pester returned errors

2020-07-22T08:08:15.9426443Z ##[error]At line:1 char:1
+ D:\a\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\Pester. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Pester.ps1
 

2020-07-22T08:08:15.9430930Z ##[error]At line:1 char:1
+ D:\a\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\Pester. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Pester.ps1
 

2020-07-22T08:08:15.9996436Z Pester Script finished
2020-07-22T08:08:16.0148291Z ##[section]Finishing: Test task

Steps to reproduce the problem

Having a test file in the repository. I made a dummy one for submitting this issue:

Param(
    [Parameter(Mandatory=$true)]
    [string]$someInput
)

Describe "test" {
    It "check that true us  true" {
        $true | Should -Be $true
    }

    It "check that someInput equal to test" {
        $someInput | Should -Be "test"
    }
}

Having a release pipeline where there is a Pester test runner task. The parameters are the followings:

pester

What do you think what the cause could be? Many thanks in advance for your help! Let me know if you need any further details regarding...

Kind Regards,
Daniel Moka

Pester script is hanging after the recent Pull Requests

There is a Pester script processed with Azure Devops task "Pester Test Runner" and It has been detected as broken within version 9.4.0 and it worked for 9.3.0.
It is not related to the agent because it is hanging within Azure Pipelines agents too and there were no changes in the custom pool.
The current behavior: the task is going to be started for minutes.
Expected (previous) behavior: the task executes simple pester scripts for <2 minutes.

2 different Readme.md's in root of the Repo

When cloning the repo on Windows there are 2 readme files - README.ME & readme.md which cause this to appear in the git output

image

not sure which one is the right one and whether 1 needs removing for the other at all

Tests don't run in Yaml pipeline

Where are you running it?

You can run the extensions in the cloud or on-premise

  • Azure DevOps Service (VSTS)

Version of Extension/Task

Latest version from market place

Expected behaviour and actual behaviour

I have written a yaml pipeline as below:

  • task: Pester.PesterRunner.Pester-Task.Pester@9
    displayName: 'Pester Test Runner'
    inputs:
    scriptFolder: '$(Build.SourcesDirectory)*'
    resultsFile: '$(Build.SourcesDirectory)/Test-Pester.XML'
    CodeCoverageOutputFile: '$(Build.SourcesDirectory)/CC-Pester.XML'
    usePSCore: ${{ parameters.pscore }}
    CodeCoverageFolder: '$(Build.SourcesDirectory)'
    PesterVersion: OtherVersion
    preferredPesterVersion: 10.0.0

However, when executing the pipeline, the tests don't seem to run but the step is executed?

Steps to reproduce the problem

Dealing with azure policy exceptions

Where are you running it?

You can run the extensions in the cloud or on-premise

  • Azure DevOps Service (VSTS)

Version of Extension/Task

I assume it is the currently public version, if you are using an older version on-premises let me know, but the answer will probably involve upgrading to the currently public version

Expected behaviour and actual behaviour

Hi,
I have a Pester test in Powershell which basically attempts to create a resource in Azure. The intention is that this will fail because of the policy in place to block it, and this is what I am testing (The failure and Azure Policy error).

However, this is a Powershell exception and thus error, which fails the test (technically the test passes).

Can I change this behaviour?

Steps to reproduce the problem

Pester Scripts can't be started due Missing Signature

Where are you running it?

  • Azure DevOps Service (VSTS) + Self Hosted Agent with Windows 10 + Visual Studio

Version of Extension/Task

Version 10.0.3

Expected behaviour and actual behaviour

The task should at least start. Unfortunately it fails, because the embedded PowerShell script is not signed.
Of course I can and will change the security policy in this specific case, because its self hosted that is no issue. But I wondering if nobody else has such a problem and what the correct solution would be. I would think that every script a Task from the marketplace contains, should be signed so it be verified running only trusted and unchanged files.

Sorry, the error message in the build output is in German, but its the common known error:

##[error]"D:\azdevops-build\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.0.3\Pester.ps1" kann nicht geladen werden. 
Die Datei "D:\azdevops-build\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.0.3\Pester.ps1" ist nicht digital 
signiert. Sie können dieses Skript im aktuellen System nicht ausführen. Weitere Informationen zum Ausführen von 
Skripts und Festlegen der Ausführungsrichtlinie erhalten Sie unter "about_Execution_Policies" 
(https:/go.microsoft.com/fwlink/?LinkID=135170)..
In Zeile:1 Zeichen:1
+ d:\azdevops-build\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : Sicherheitsfehler: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Steps to reproduce the problem

I don't really know, because its not working for me out of the box. Maybe regular MS build agents have a other security policy then the Windows 10 I setup.

Ubuntu 20.04, permission denied at start of run

Where are you running it?

  • Azure DevOps Service (VSTS)

Version of Extension/Task

10.2.3

Expected behaviour and actual behaviour

Expected there to be no errors before actually running the tests. Errors show up right after starting pwsh:

##[error]mkdir: cannot create directory ‘/run/user/1001’
##[debug]Processed: ##vso[task.issue type=error;]mkdir: cannot create directory ‘/run/user/1001’
##[debug]task result: Failed
##[error]mkdir: cannot create directory ‘/run/user/1001’
##[debug]Processed: ##vso[task.issue type=error;]mkdir: cannot create directory ‘/run/user/1001’
##[debug]Processed: ##vso[task.complete result=Failed;]mkdir: cannot create directory ‘/run/user/1001’
##[error]: Permission denied

##[debug]Processed: ##vso[task.issue type=error;]: Permission denied%0A
##[debug]task result: Failed
##[error]: Permission denied

##[debug]Processed: ##vso[task.issue type=error;]: Permission denied%0A
##[debug]Processed: ##vso[task.complete result=Failed;]: Permission denied%0A

Steps to reproduce the problem

Create task that runs Pester Test Runner og Ubuntu 20.04.

Log

Temporary solution

Task work fine on Ubuntu 18.04. Haven't tried 16.04 but my guess is that the issue is present on Ubuntu 20.04 only.

Shipped version of Pester module is missing its assemblies

Where are you running it?

Azure DevOps Server 2022.0.1

Version of Extension/Task

Latest (10.3.10)

Expected behaviour and actual behaviour

We're using a self-hosted agent on Windows Server 2022

  • Without the Pester module installed
  • Without PSGet configured
  • Offline

Using this task in a pipeline will result in the following error (running with PSCore):

##[warning]Falling back to version of Pester shipped with extension. To use a newer version please update the version of PowerShellGet available on this machine.
##[error]Add-Type: Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path
##[error]Add-Type: Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path
##[error]'H:\b\1\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.3.10\5.0.1\bin\netstandard2.0\Pester.dll' because it does
not exist."

Note that this will also fail when using PowerShell instead of PSCore since the entire bin folder is missing from the task.
To resolve this the Pester bin folder should also be added to the task.

Steps to reproduce the problem

  • Use a machine without internet
  • Have no registries registered in PSGet (or one that cannot be accessed)
  • Run the task on random tests

Pester Test Runner does not fall back to shipped version due to local import-module command

Where are you running it?

Azure DevOps Server -Version Dev17.M153.5

Version of Extension/Task

Pester Test Runner -Version 9.1.10

Expected behaviour and actual behaviour

When there is no access to PowerShell Gallery, the task defaults to the shipped version of pester.

I believe this may be due to the Import-Module call in ModuleHelper.psm
Line 49 and Line 70 where the local Import-Module calls are not using Join-Path which was applied to Pester.ps1 in the Fix paths for import-module commands commit for build 9.1.10

Steps to reproduce the problem

Run task against an agent that is isolated from the internet.
The output should be similar to the following, notably the 'code coverage not enabled' line due to 4.10.1 not being used but instead the installed OS default is being used.

WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»
WARNING: Unable to download the list of available providers. Check your internet connection.
WARNING: Unable to find module repositories.
##[warning]Falling back to version of Pester shipped with extension. To use a newer version please update the version of PowerShellGet available on this machine.
##[debug]Processed: ##vso[task.logissue type=warning]Falling back to version of Pester shipped with extension. To use a newer version please update the version of PowerShellGet available on this machine.
Running in AMD64 PowerShell
Running Pester from the folder [E:\Agents\01_work\93\s*] output sent to [E:\Agents\01_work\93\s\TEST-Pester.XML]
WARNING: Code coverage output not supported on Pester versions before 4.0.4.

If TestsFolder contains a space an error is thrown

Where are you running it?

  • Azure DevOps Service (VSTS)

Version of Extension/Task

Current version

Expected behaviour and actual behaviour

If the TestFolder variable uses a path that contains a space in it then the Pester test runner will fail. For example my self-hosted agents are installed the the following directory C:\Build Agent\ so when I use $(System.DefaultWorkingDirectory)* it is evaluated to C:\Build Agent_work\27\s\*, this then throws the following error

Using executable 'powershell.exe'
powershell.exe C:\Build Agent\_work\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.2.4\Pester.ps1 -TestFolder C:\Build Agent\_work\26\s\* -resultsFile C:\Build Agent\_work\26\s\Test-Pester.XML -run32Bit False
##[error]C:\Build : The term 'C:\Build' is not recognized as the name of a cmdlet, function, script file, or operable program. 

##[error]C:\Build : The term 'C:\Build' is not recognized as the name of a cmdlet, function, script file, or operable program. 

##[error]Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Steps to reproduce the problem

Use a TestsFolder path that contains a space in the path

Documentation is a bit inconsistent and short

Where are you running it?

You can run the extensions in the cloud or on-premise

  • Azure DevOps Service (VSTS)

Version of Extension/Task

Pester.PesterRunner.Pester-Task.Pester@10

Expected behaviour and actual behaviour

Documentation is a bit inconsistent between the marketplace https://marketplace.visualstudio.com/items?itemName=Pester.PesterRunner&ssr=false#overview and the readme.md. I'd expect them to be similar.

For example,
readme.md:
Scripts Folder or Script - Location of test files to run. Also supports the hashtable syntax that allows specifying parameters for tests, as seen in this example.
Azure DevOpsMarketplace:
Folder to run scripts from e.g $(Build.SourcesDirectory)\* or a script hashtable @{Path='$(Build.SourcesDirectory)'; Parameters=@{param1='111'; param2='222'}}"

Having more samples/ examples/ quick starts/ fleshed out documentation would be very useful to understand the best way to use this extension, and accelerate usage.

File is not found during code coverage report generation

Where are you running it?

  • Azure DevOps Service (VSTS)

Version of Extension/Task

Version: 10.0.3

Expected behaviour

When the task "PublishCodeCoverageResults" is used in a pipeline, the report contains the file and the user can see the line of file are covered or not

Actual behaviour

In the log, the following warning are logged:
2020-05-19T19:49:35: File 'X.psm1' does not exist (any more).

The report does not contains the file content:
image

Steps to reproduce the problem

The PowerShell Module contains nested module.

YAML Configuration

 - task: Pester@9
    displayName: "Test PowerShell Module with Pester"
    inputs:
      scriptFolder: '$(build.sourcesdirectory)'
      resultsFile: "$(build.sourcesdirectory)/PowerShellModuleProject.Tests.XML"
      CodeCoverageOutputFile: '$(build.sourcesdirectory)\coverage.powershell-module.xml'
      CodeCoverageFolder: '$(build.sourcesdirectory)'
      usePSCore: False
  - task: PublishTestResults@2
    displayName: "Publish Test Results"
    inputs:
      testResultsFormat: 'NUnit'
      testResultsFiles: "$(build.sourcesdirectory)/PowerShellModuleProject.Tests.XML"
      mergeTestResults: true
      failTaskOnFailedTests: true
      testRunTitle: 'PowerShell Module Tests'
  - task: PublishCodeCoverageResults@1
    inputs:
      codeCoverageTool: 'JaCoCo'
      summaryFileLocation: '$(build.sourcesdirectory)\coverage.powershell-module.xml'
      pathToSources: '$(build.sourcesdirectory)'
      failIfCoverageEmpty: true

PowerShell Hangs due missing -NonInteractive

Where are you running it?

Azure DevOps Service (VSTS) + Self Hosted Agent with Windows 10 + Visual Studio

Version of Extension/Task

Version 10.0.3

Expected behaviour and actual behaviour

My task just does "nothing" and was frozen. I tried to find out what the issue was and started the command from the log manually:

powershell.exe d:\azdevops-build\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.0.3\Pester.ps1 -TestFolder d:\azdevops-build\1\s\Tests.Pester -resultsFile d:\azdevops-build\1\s\Tests.Pester\Test-Result.xml -run32Bit False -additionalModulePath d:\azdevops-build\1\s/Modules
TestFolder d:\azdevops-build\1\s\Tests.Pester

which results in a

Der Anbieter "nuget v2.8.5.208" ist nicht installiert.
"nuget" kann manuell von https://onegetcdn.azureedge.net/providers/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll heruntergeladen und installiert werden.
Soll PackageManagement automatisch heruntergeladen und "nuget" jetzt installiert werden?
[J] Ja [N] Nein [H] Anhalten [?] Hilfe (Standard ist "J"):

So the Task stopped by waiting for some user input, which is of course not possible. The powershell.exe should be started noninteractive like:
powershell d:\azdevops-build\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.0.3\Pester.ps1 -NonInteractive [...]

Steps to reproduce the problem

Start something waiting for interaction.

CommandNotFoundException only in AzureDevops

Where are you running it?

  • Azure DevOps Service (VSTS)

Expected behaviour and actual behaviour

CommandNotFoundException: Could not find Command PSIISReset

I import with in Tests.ps1
. "$PSScriptRoot..\ArielDbCore\IISOperations.ps1"

	Mock -CommandName PSIISReset -MockWith { 
			Write-Output "Called fake PSIISReset"
		}

My pipeline :

  • task: Pester@10
    inputs:
    scriptFolder: "$(System.DefaultWorkingDirectory)\ArielDb-Orchestrator\Tests.ps1"
    resultsFile: "$(System.DefaultWorkingDirectory)\Test-Pester-ArielDb-Orchestrator.XML"
    CodeCoverageOutputFile: "$(System.DefaultWorkingDirectory)\ArielDb-OrchestratorCoverage.XML"
    usePSCore: False
    CodeCoverageFolder: "$(System.DefaultWorkingDirectory)\ArielDb-Orchestrator"
    preferredPesterVersion: '5.0.4'
    additionalModulePath: '$(System.DefaultWorkingDirectory)\ArielDb-Orchestrator'

Steps to reproduce the problem

It run fine on my machine using pester 5.0.4 but not with AzureDevops
I try setting 32bit=true, switching from importmodule to dotsourcing, preferredPesterVersion , additionalModulePath (which is not the good one right now, I dont have only one path for all import)

I think it's because i used powershell v5.1 on my machine, and remote is 7.1 ?

Task fail on standard error

Where are you running it?

Azure DevOps Services

Expected behaviour and actual behaviour

My Pester task seems to fail because the program under test write to the standard error.
All tests passed

Tests completed in 59.3s


Tests Passed: 4, 
Failed: 0, 
Skipped: 0 
NotRun: 0


Pester Script finished
Finishing: Pester

but because my program write to the error stream (the program writes an error message if the available disk space is less than 10GiB)

##[error]LOW DISK SPACE.

the whole task fail.

I don't know if it really qualify as a bug but I'd love to have an option failOnStderr like with the PowerShell task.
In the meantime, I set continueOnError: True.

Thanks,
Sam

Codecoverage not possible

#Codecoverage not possible

###Azure Devops version:
Onpremise Version Dev17.M153.3

###Version of Extension/Task:
Pester Test Runner 9.1.14

###Expected behaviour:

When the Code Coverage Output File field is filled with a valid Codecoverage result file path and the Code Coverage Folder field is filled, the task should produce a code coverage result.

###Actual behaviour

When the Code Coverage Output File field is filled with a valid Codecoverage result file path and the Code Coverage Folder field is filled, no code coverage result is produced. Only a warning is visible in the log
"WARNING: Code coverage output not supported on Pester versions before 4.0.4."

###Steps to reproduce the problem
Fill the following field with valid folder and/or filelocations:

Scripts Folder or Script: $(Build.SourcesDirectory)\Tests*
Results File: $(Build.SourcesDirectory)\Test-Pester.xml
Code Coverage Output File: $(Build.SourcesDirectory)\CodeCoverage.xml
Code Coverage Folder: $(Build.SourcesDirectory)\Source*.psm1

Run the task in a build. No codecoverage result is produced.

###Cause and proposed fix:
####Cause:
The If-statement

`` if ($CodeCoverageOutputFile -and (Get-Module Pester).Version -ge [Version]::Parse('4.0.4')) {##....}

always failes because the module Pester isn't imported in the scope of the current Pester.ps1 script yet, but only in the scope of the HelperModule.psm1. Get-Module Pester results in Null.
This in turn causes the code to proceed to the else block which produces the warning:
"WARNING: Code coverage output not supported on Pester versions before 4.0.4."

https://github.com/pester/AzureDevOpsExtension/blob/master/Extension/task/Pester.ps1#L113

####Proposed fix:

Add a Global switch to the Import-Module function of the Import-Pester functions to make Pester also available to the parent script:
Import-Module -Name Pester -RequiredVersion $NewestPester.Version -Verbose:$false -Global
https://github.com/pester/AzureDevOpsExtension/blob/master/Extension/task/HelperModule.psm1#L66

Import-Module -Name (Join-Path $PSScriptRoot "4.10.1\Pester.psd1") -Force -Verbose:$false -Global
https://github.com/pester/AzureDevOpsExtension/blob/master/Extension/task/HelperModule.psm1#L70
https://github.com/pester/AzureDevOpsExtension/blob/master/Extension/task/HelperModule.psm1#L49

Explanation Global switch:

"Indicates that this cmdlet imports modules into the global session state so they are available to all commands in the session.

By default, when Import-Module cmdlet is called from the command prompt, script file, or scriptblock, all the commands are imported into the global session state.

When invoked from another module, Import-Module cmdlet imports the commands in a module, including commands from nested modules, into the calling module's session state. "

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-7#parameters

TestDrive cannot be used in Azure DevOps

Where are you running it?

Azure DevOps Service (VSTS)

Version of Extension/Task

10.1.23

Expected behaviour and actual behaviour

Actual behaviour

When the tests are using the TestDrive, all test failed due to an error in the temp registry initialization

System.Exception: Was not able to create a Pester Registry key for TestRegistry 
System.Management.Automation.ValidationMetadataException: The " $_ | Test-Path -PathType Leaf " validation script for 
the argument with value "Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Pester" did not return a 
result of True. Determine why the validation script failed, and then try the command again.
   at System.Management.Automation.ValidateScriptAttribute.ValidateElement(Object element)
   at System.Management.Automation.ValidateEnumeratedArgumentsAttribute.Validate(Object arguments, EngineIntrinsics 
engineIntrinsics)
   at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, 
CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
At C:\Users\VssAdministrator\Documents\WindowsPowerShell\Modules\Pester\5.0.2\Pester.psm1:7827 char:13
+             throw ([Exception]"Was not able to create a Pester Regist ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (System.Object[]:Object[]) [], RuntimeException
    + FullyQualifiedErrorId : System.Exception: Was not able to create a Pester Registry key for TestRegistry System.M 
   anagement.Automation.ValidationMetadataException: The " $_ | Test-Path -PathType Leaf " validation script for the   
  argument with value "Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Pester" did not return a resul   
 t of True. Determine why the validation script failed, and then try the command again.
   at System.Management.Automation.ValidateScriptAttribute.ValidateElement(Object element)
       at System.Management.Automation.ValidateEnumeratedArgumentsAttribute.Validate(Object arguments, EngineIntrinsic 
   s engineIntrinsics)
       at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledC 
   ommandParameter parameterMetadata, ParameterBindingFlags flags)
 at Get-TempRegistry, C:\Users\VssAdministrator\Documents\WindowsPowerShell\Modules\Pester\5.0.2\Pester.psm1: line 7827
at New-RandomTempRegistry, C:\Users\VssAdministrator\Documents\WindowsPowerShell\Modules\Pester\5.0.2\Pester.psm1: line 12890
at New-TestRegistry, C:\Users\VssAdministrator\Documents\WindowsPowerShell\Modules\Pester\5.0.2\Pester.psm1: line 12807
at <ScriptBlock>, C:\Users\VssAdministrator\Documents\WindowsPowerShell\Modules\Pester\5.0.2\Pester.psm1: line 12958

Expected behaviour

When the tests are using the TestDrive, all tests runs and the TestDrive can be used.

Steps to reproduce the problem

Pester (In-)Compatibility Not Correctly Handled

Where are you running it?

Azure DevOps Service (VSTS) + Self Hosted Agent with Windows 10 + Visual Studio

Version of Extension/Task

Version 10.0.5

Expected behaviour and actual behaviour

I found out only by reading the source code, the Task >= V10 does only support Pester V5.
The input fields do not mention any Pester V5 requirement, but also mentioned Pester V4 is part of the task, which is of course not the case and also incompatible. The build in is 5.0.1.
image

If specifying preferredPesterVersion V3.40.0, the task fails with an error due the unknown type:

##[error]Der Typ [PesterConfiguration] wurde nicht gefunden.

##[error]In D:\azdevops-build_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.0.5\Pester.ps1:143 Zeichen:43

  • $result = Invoke-Pester -Configuration ([PesterConfiguration]$Pester ...

Steps to reproduce the problem

Specify preferredPesterVersion V3.40.0.

Suggestion

There is a version check in Pester.ps1, which only opt-outs V4:

if ($TargetPesterVersion -match '^4') {
    Write-Host "##vso[task.logissue type=error]This version of the task does not support Pester V4, please use task version 9."
    exit 1
}

A idea would be the following:

if ([Version]$TargetPesterVersion -lt [Version]"5.0.0") {
    Write-Host "##vso[task.logissue type=error]This version of the task does not support Pester below V5. Please use task version 9."
    exit 1
}

That would also not use string operations for versions.

The description of "TargetPesterVersion" task.json should be updated, maybe its also possible to do some verification there.

Update of task-lib update

1. General summary of the issue

Hi,

We are facing a warning in pester task:

(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr
(node:4544) Warning: Use Cipheriv for counter mode of aes-256-ctr

Environment:
Custom agents on windows servers.

I probably found a solution for this to update task-lib. (microsoft/azure-pipelines-tasks#12147)

Errors are thrown, when Pestermodule is not installed locally

Where are you running it?

  • TFS Server 16.131.28601.4

Version of Extension/Task

9.1.10

Expected behaviour and actual behaviour

Pester task runs without throwing errors even when it is not able to check for updates or find Pester installed locally - in my understanding it should use the builtin executable. Actual behaviour: The tests are run, but errors are thrown, which causes the task to fail even if all tests were successsful.
Logs:

2020-05-08T16:46:58.0927609Z ##[section]Starting: Pester Test Runner
2020-05-08T16:46:58.1110758Z ==============================================================================
2020-05-08T16:46:58.1110850Z Task         : Pester Test Runner
2020-05-08T16:46:58.1110964Z Description  : Run Pester tests by either installing the latest version of Pester at run time (if possible) or using the version shipped with the task (4.6.0)
2020-05-08T16:46:58.1111085Z Version      : 9.1.10
2020-05-08T16:46:58.1111125Z Author       : Pester
2020-05-08T16:46:58.1111173Z Help         : Version: #{Build.BuildNumber}#. [More Information](https://github.com/pester/AzureDevOpsExtension)
2020-05-08T16:46:58.1111242Z ==============================================================================
2020-05-08T16:46:58.3870412Z Using executable 'powershell.exe'
2020-05-08T16:46:58.3871527Z powershell.exe D:\development20181\_work\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.1.10\Pester.ps1 -scriptFolder D:\development20181\_work\r1\a\XXX\Infrastructure\PsTools\RiStatus.Tests.ps1 -resultsFile D:\development20181\_work\r1\a\PesterRiTest.XML -run32Bit false
2020-05-08T16:46:59.2709271Z scriptFolder D:\development20181\_work\r1\a\XXX\Infrastructure\PsTools\RiStatus.Tests.ps1
2020-05-08T16:46:59.2710870Z resultsFile D:\development20181\_work\r1\a\PesterRiTest.XML
2020-05-08T16:46:59.2710954Z run32Bit false
2020-05-08T16:46:59.2711086Z additionalModulePath 
2020-05-08T16:46:59.2711211Z tag 
2020-05-08T16:46:59.2711306Z ExcludeTag 
2020-05-08T16:46:59.2712138Z CodeCoverageOutputFile 
2020-05-08T16:46:59.2712252Z CodeCoverageFolder 
2020-05-08T16:46:59.2712369Z ScriptBlock 
2020-05-08T16:47:02.1602366Z WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»
2020-05-08T16:47:02.1608485Z WARNING: Unable to download the list of available providers. Check your internet connection.
2020-05-08T16:47:11.7519408Z WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
2020-05-08T16:47:11.8843233Z ##[error]PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'Pester'. Try 
2020-05-08T16:47:11.8853626Z ##[error]PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'Pester'. Try 
2020-05-08T16:47:11.8872961Z ##[error]Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.1\PSModule.psm1:8845 char:3
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio 
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
2020-05-08T16:47:11.8875102Z ##[error]Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.1\PSModule.psm1:8845 char:3
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio 
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
2020-05-08T16:47:13.7019084Z Running in AMD64 PowerShell
2020-05-08T16:47:13.7028660Z Running Pester from the folder [D:\development20181\_work\r1\a\XXX\Infrastructure\PsTools\RiStatus.Tests.ps1] output sent to [D:\development20181\_work\r1\a\PesterRiTest.XML]
2020-05-08T16:47:13.9829537Z Pester v4.10.1

Steps to reproduce the problem

Have it run without throwing errors.

v9 of the task to may import Pester v5 on a box with it installed

I noticed this in recent troubleshooting of an internal issue on our build boxes (we don't use the hosted agents)
Seems that this default value

[string]$TargetPesterVersion = "latest"

will then have an impact on potentially importing pester at this point
Import-Pester -Version $TargetPesterVersion

I propose to fix this with some additional defensive coding just to be sure that Pester v5 will never accidentally import

Does not accept spaces in paths for the Pre-Test Scriptblock

Where are you running it?

  • Azure DevOps Service (VSTS)

Version of Extension/Task

Current public version

Expected behaviour and actual behaviour

Execute a Pre-Test Script whose path contains spaces, such as the one passed here:
ScriptBlock d:\a\r1\a\_DeploymentTools\Deployment Tools\ARM\01_DebugARM_Init.ps1
Fails with

##[error]Exception calling "Invoke" with "0" argument(s): "The term 'd:\a\r1\a\_DeploymentTools\Deployment' is not recognized 
as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was

Steps to reproduce the problem

Just try to invoke a pre-test script in a path that has a space in it.

NUnit2.5 is not a valid Pester export format

Where are you running it?

You can run the extensions in the cloud or on-premise

  • Azure DevOps Service (VSTS) - On-Premises Build Agent

Version of Extension/Task

I assume it is the currently public version, if you are using an older version on-premises let me know, but the answer will probably involve upgrading to the currently public version
10.2.4

Expected behaviour and actual behaviour

Expected: TestResult Object and Code Coverage output files are created.
Actual: Neither file mentioned above are created. When attempting to write out the TestResult object there is an error as seen below:

System.Management.Automation.RuntimeException: 'NUnit2.5' is not a valid Pester export format.
at Export-PesterResults, C:\Users\totallyRealUser\Documents\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psm1: line 14335
at Invoke-Pester<End>, C:\Users\totallyRealUser\Documents\WindowsPowerShell\Modules\Pester\5.1.0\Pester.psm1: line 4871
at <ScriptBlock>, C:\BuildAgent\AzureDevOps\_work\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\10.2.4\Pester.ps1: line 142
at <ScriptBlock>, <No file>: line 1

Steps to reproduce the problem

- task: Pester@10
    displayName: Pester Test Runner
    inputs:
      TestFolder: $(Build.ArtifactStagingDirectory)
      resultsFile: $(Build.ArtifactStagingDirectory)\Test-Results\Test-Pester.XML
      CodeCoverageOutputFile: $(Build.ArtifactStagingDirectory)\Test-Results\CodeCoverage-Pester.XML
      CodeCoverageFolder: $(Build.ArtifactStagingDirectory)

Additional Info

This issue recently opened for Pester seems related: pester/Pester#1794 .

If I'm reading that issue correctly, the TestResult.OutputFormat has been ignored up until Pester 5.1, and it just always used NUnit2.5. In this version of Pester NUnit2.5 is not a valid option. However, NUnitXml appears to be the current replacement. It looks like the lines below could be changed to fix this.

$PesterConfig.TestResult = @{
Enabled = $true
OutputFormat = 'NUnit2.5'
OutputPath = $resultsFile
}

Publish Test Results

Add parameter etc to publish the test results into Azure Devops once the run is complete.

Pester returns errors even when no tests fail

Where are you running it?

  • Azure DevOps Service (VSTS)

Version of Extension/Task

10.0.5

Expected behaviour and actual behaviour

Expected: Pester task passes without error when no tests fail

Actual: Pester task fails with error even though all tests pass

Steps to reproduce the problem

Here's a link to a public project where this issue can be repro'd

https://dev.azure.com/cfarrelly/test/_build/results?buildId=4&view=logs&j=275f1d19-1bd8-5591-b06b-07d489ea915a&t=f969aa47-2434-555b-2817-6587663ed32a

I thought originally it may be down to tags and skipping tests but I created a simple repro here with 1 test to run and the test runner fails with 'Pester returned errors', appears to be an issue when checking the results here

if ($result.failedCount -ne 0) {

Thanks,

Colin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.