Недавно я перешел на Pester 5.0.2, чтобы начать тестирование сценария Powershell, который я написал. Я могу проникнуть в блок BeforeAll, и пути заполняются, как я и ожидал, однако, когда я добираюсь до области Get-ChildItem в моем блоке Describe, переменные из BeforeAll равны $null.
BeforeAll {
$testDir = Split-Path $PSCommandPath -Parent
$prodDir = Split-Path $testDir -Parent
}
Describe "Tests - All Files in prod" {
Get-ChildItem $prodDir -File | ForEach-Object {
$fileName = (Split-Path $_ -leaf).PadRight(20, ' ')
$filePath = $_.PSPath
It "Vars not declared or changed between function definitions" {
[System.Collections.ArrayList]$preSource = (Get-Variable).Name
. "$filePath" -Sourcing
[System.Collections.ArrayList]$postSource = (Get-Variable).Name
$postSource.Remove('preSource')
$postSource.Remove('UnderTest')
[array]$diff = Compare-Object $preSource $postSource -PassThru
$diff | Should -BeNullOrEmpty
}
It "$fileName all #*, #?, #TODO tags are removed" {
$_ | Should -Not -FileContentMatch $([regex]::escape('#TODO'))
$_ | Should -Not -FileContentMatch $([regex]::escape('#*'))
$_ | Should -Not -FileContentMatch $([regex]::escape('#?'))
}
}
}