From 949ce6f8d27454b8b814a283e89adaefc74407c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Sat, 9 Aug 2025 12:51:06 +0200 Subject: [PATCH] Fix Pester tests --- Tests/Convert-PDFToText.Tests.ps1 | 4 ++-- Tests/Set-PDFForm.Tests.ps1 | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Tests/Convert-PDFToText.Tests.ps1 b/Tests/Convert-PDFToText.Tests.ps1 index 097749d..4c95c51 100644 --- a/Tests/Convert-PDFToText.Tests.ps1 +++ b/Tests/Convert-PDFToText.Tests.ps1 @@ -1,8 +1,8 @@ Describe 'Convert-PDFToText' { It 'returns objects with PageNumber and Text' { - $file = Join-Path $PSScriptRoot 'Input' 'SampleAcroForm.pdf' + $file = [IO.Path]::Combine($PSScriptRoot, 'Input', 'SampleAcroForm.pdf') $text = Convert-PDFToText -FilePath $file - $text | Should -AllBeOfType [pscustomobject] + $text | ForEach-Object { $_ | Should -BeOfType [psobject] } $text[0].PageNumber | Should -Be 1 $text[0].Text | Should -Match 'Text 1' } diff --git a/Tests/Set-PDFForm.Tests.ps1 b/Tests/Set-PDFForm.Tests.ps1 index d63a81c..23d0181 100644 --- a/Tests/Set-PDFForm.Tests.ps1 +++ b/Tests/Set-PDFForm.Tests.ps1 @@ -1,6 +1,6 @@ Describe 'Set-PDFForm' -Tags "PDFForm" { BeforeAll { - New-Item -Path $PSScriptRoot -Force -ItemType Directory -Name 'Output' + New-Item -Path $PSScriptRoot -Force -ItemType Directory -Name 'Output' | Out-Null } It 'Set-PDForm Flatten should flatten forms' { @@ -115,10 +115,12 @@ Describe 'Set-PDFForm' -Tags "PDFForm" { Close-PDF -Document $PDF } - # cleanup - $FolderPath = [IO.Path]::Combine("$PSScriptRoot", "Output") - $Files = Get-ChildItem -LiteralPath $FolderPath -File - foreach ($_ in $Files) { - Remove-Item -LiteralPath $_.FullName -ErrorAction SilentlyContinue + AfterAll { + $FolderPath = [IO.Path]::Combine("$PSScriptRoot", "Output") + if (Test-Path $FolderPath) { + Get-ChildItem -LiteralPath $FolderPath -File | ForEach-Object { + Remove-Item -LiteralPath $_.FullName -ErrorAction SilentlyContinue + } + } } }