pester / AzureDevOpsExtension

MIT License
27 stars 14 forks source link

CommandNotFoundException only in AzureDevops #55

Open FelixBrunet opened 3 years ago

FelixBrunet commented 3 years ago

Where are you running it?

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 :

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 ?

ChrisLGardner commented 3 years ago

Azure DevOps will default to Windows PowerShell (5.1) and ony use PowerShell (7.x) when you specify the usePSCore option to true.

Can you share some more of your tests file? Where are you declaring the mock? Where are you doing the import/dotsourcing?

FelixBrunet commented 3 years ago

I found it today This was working with debugger but not with Invoke-Pester , i fix it placing import in BeforeAll. When you have no beforeall , it run fine using Tests.ps1 but not with Invoke-Pester