diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5582905..6db06fc 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -46,7 +46,7 @@ jobs: run: Invoke-Build -Configuration Release - name: Upload module - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Module path: ./out/modules/PSDocs/* @@ -125,7 +125,7 @@ jobs: run: ./scripts/pipeline-deps.ps1 - name: Download module - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Module path: ./out/modules/PSDocs diff --git a/.gitignore b/.gitignore index e0bd5a3..004a415 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ src/**/*-help.xml src/**/*.help.txt BenchmarkDotNet.Artifacts/ PSDocs.Benchmark*.log +.idea/.idea.PSDocs/.idea/.gitignore +.idea/.idea.PSDocs/.idea/indexLayout.xml +.idea/.idea.PSDocs/.idea/vcs.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd4a07..e485c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,16 @@ What's changed since v0.9.0: - Engineering: - - Bump YamlDotNet to v13.7.1. - [#284](https://github.com/microsoft/PSDocs/pull/284) - - Bump Newtonsoft.Json to v13.0.3. - [#284](https://github.com/microsoft/PSDocs/pull/284) + - CI update Pester to v5.6.1 + - Bump BenchmarkDotNet to v0.14.0. + - Bump Microsoft.CodeCoverage to v17.10.0. + - Bump Microsoft.NET.Test.Sdk to v17.10.0. + - Bump xunit to v2.9.0. + - Bump xunit.runner.visualstudio to v2.5.7. + - Bump YamlDotNet to v13.7.1. + [#284](https://github.com/microsoft/PSDocs/pull/284) + - Bump Newtonsoft.Json to v13.0.3. + [#284](https://github.com/microsoft/PSDocs/pull/284) ## v0.9.0 diff --git a/modules.json b/modules.json index 429fc4e..ce93480 100644 --- a/modules.json +++ b/modules.json @@ -2,7 +2,7 @@ "dependencies": {}, "devDependencies": { "Pester": { - "version": "4.10.1" + "version": "5.6.1" }, "platyPS": { "version": "0.14.2" diff --git a/pipeline.build.ps1 b/pipeline.build.ps1 index 84c0cc4..19e179e 100644 --- a/pipeline.build.ps1 +++ b/pipeline.build.ps1 @@ -191,14 +191,20 @@ task Dependencies NuGet, { # Synopsis: Test the module task TestModule Dependencies, { - Import-Module Pester -RequiredVersion 4.10.1 -Force; + Import-Module Pester -RequiredVersion 5.6.1 -Force; - # Run Pester tests - $pesterParams = @{ Path = $PWD; OutputFile = 'reports/pester-unit.xml'; OutputFormat = 'NUnitXml'; PesterOption = @{ IncludeVSCodeMarker = $True }; PassThru = $True; }; + # Define Pester configuration + $pesterConfig = [PesterConfiguration]::Default + $pesterConfig.Run.PassThru = $True + # Enable NUnitXml output + $pesterConfig.TestResult.OutputFormat = "NUnitXml" + $pesterConfig.TestResult.OutputPath = 'reports/pester-unit.xml' + $pesterConfig.TestResult.Enabled = $True if ($CodeCoverage) { - $pesterParams.Add('CodeCoverage', (Join-Path -Path $PWD -ChildPath 'out/modules/**/*.psm1')); - $pesterParams.Add('CodeCoverageOutputFile', (Join-Path -Path $PWD -ChildPath reports/pester-coverage.xml)); + $pesterConfig.CodeCoverage.OutputFormat = 'JaCoCo' + $pesterConfig.CodeCoverage.OutputPath = 'reports/pester-coverage.xml' + $pesterConfig.CodeCoverage.Path = (Join-Path -Path $PWD -ChildPath 'out/modules/**/*.psm1') } if (!(Test-Path -Path reports)) { @@ -206,20 +212,22 @@ task TestModule Dependencies, { } if ($Null -ne $TestGroup) { - $pesterParams['Tags'] = $TestGroup; + $pesterConfig.Filter.Tag = $TestGroup } - $results = Invoke-Pester @pesterParams; + # Run Pester tests + $results = Invoke-Pester -Configuration $pesterConfig - # Throw an error if pester tests failed + # Throw an error if Pester tests failed if ($Null -eq $results) { - throw 'Failed to get Pester test results.'; + throw 'Failed to get Pester test results.' } - elseif ($results.FailedCount -gt 0) { - throw "$($results.FailedCount) tests failed."; + elseif ($results.Result.FailedCount -gt 0) { + throw "$($results.Result.FailedCount) tests failed." } } + task Benchmark { if ($Benchmark -or $BuildTask -eq 'Benchmark') { dotnet run --project src/PSDocs.Benchmark -f net7.0 -c Release -- benchmark --output $PWD; diff --git a/src/PSDocs.Benchmark/PSDocs.Benchmark.csproj b/src/PSDocs.Benchmark/PSDocs.Benchmark.csproj index 2c9bc0d..caf39b7 100644 --- a/src/PSDocs.Benchmark/PSDocs.Benchmark.csproj +++ b/src/PSDocs.Benchmark/PSDocs.Benchmark.csproj @@ -17,7 +17,7 @@ - + diff --git a/tests/PSDocs.Tests/PSDocs.BlockQuote.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.BlockQuote.Tests.ps1 index 3a4b2b1..818d6f6 100644 --- a/tests/PSDocs.Tests/PSDocs.BlockQuote.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.BlockQuote.Tests.ps1 @@ -8,27 +8,30 @@ [CmdletBinding()] param () -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$here = (Resolve-Path $PSScriptRoot).Path; -$nl = [System.Environment]::NewLine; +BeforeAll{ + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $here = (Resolve-Path $PSScriptRoot).Path; + $nl = [System.Environment]::NewLine; +} Describe 'PSDocs -- BlockQuote keyword' -Tag BlockQuote { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; - $testObject = [PSCustomObject]@{ - Name = 'TestObject' - } - + Context 'Markdown' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - PassThru = $True + BeforeAll{ + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + $testObject = [PSCustomObject]@{ + Name = 'TestObject' + } + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + PassThru = $True + } } It 'Should handle single line input' { $result = Invoke-PSDocument @invokeParams -Name 'BlockQuoteSingleMarkdown'; diff --git a/tests/PSDocs.Tests/PSDocs.Code.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Code.Tests.ps1 index a64a7ad..a3c8643 100644 --- a/tests/PSDocs.Tests/PSDocs.Code.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Code.Tests.ps1 @@ -8,27 +8,30 @@ [CmdletBinding()] param () -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$here = (Resolve-Path $PSScriptRoot).Path; -$nl = [System.Environment]::NewLine; + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $here = (Resolve-Path $PSScriptRoot).Path; + $nl = [System.Environment]::NewLine; +} Describe 'PSDocs -- Code keyword' -Tag Code { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; - $testObject = [PSCustomObject]@{ - Name = 'TestObject' - } - Context 'Markdown' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - PassThru = $True + BeforeAll { + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + $testObject = [PSCustomObject]@{ + Name = 'TestObject' + } + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + PassThru = $True + } } It 'Should have generated output' { $result = Invoke-PSDocument @invokeParams -Name 'CodeMarkdown'; diff --git a/tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 index 4cb791c..5d1e5b7 100644 --- a/tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Common.Tests.ps1 @@ -8,44 +8,45 @@ [CmdletBinding()] param () -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; - -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; - -$outputPath = Join-Path -Path $rootPath -ChildPath out/tests/PSDocs.Tests/Common; -Remove-Item -Path $outputPath -Force -Recurse -Confirm:$False -ErrorAction Ignore; -$Null = New-Item -Path $outputPath -ItemType Directory -Force; -$here = (Resolve-Path $PSScriptRoot).Path; - -$dummyObject = New-Object -TypeName PSObject -Property @{ - Object = [PSObject]@{ - Name = 'ObjectName' - Value = 'ObjectValue' - } - - Hashtable = @{ - Name = 'HashName' - Value = 'HashValue' +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; + + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath.Path -ChildPath out/modules/PSDocs) -Force; + $outputPath = Join-Path -Path $rootPath.Path -ChildPath out/tests/PSDocs.Tests/Common; + Remove-Item -Path $outputPath -Force -Recurse -Confirm:$False -ErrorAction Ignore; + $Null = New-Item -Path $outputPath -ItemType Directory -Force; + $here = (Resolve-Path $PSScriptRoot).Path; + + $dummyObject = New-Object -TypeName PSObject -Property @{ + Object = [PSObject]@{ + Name = 'ObjectName' + Value = 'ObjectValue' + } + + Hashtable = @{ + Name = 'HashName' + Value = 'HashValue' + } } + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Cmdlets.Doc.ps1'; } Describe 'PSDocs instance names' -Tag 'Common', 'InstanceName' { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Cmdlets.Doc.ps1'; - Context 'Generate a document without an instance name' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $dummyObject - OutputPath = $outputPath + BeforeAll { + $invokeParams = @{ + Path = $docFilePath + InputObject = $dummyObject + OutputPath = $outputPath + } + $result = Invoke-PSDocument @invokeParams -Name 'WithoutInstanceName'; } - $result = Invoke-PSDocument @invokeParams -Name 'WithoutInstanceName'; It 'Should generate an output named WithoutInstanceName.md' { - Test-Path -Path $result.FullName | Should be $True; + Test-Path -Path $result.FullName | Should -Be $True; $outputDoc = Get-Content -Path $result.FullName -Raw; $outputDoc | Should -Match 'WithoutInstanceName'; $outputDoc | Should -Match 'ObjectName'; @@ -54,12 +55,14 @@ Describe 'PSDocs instance names' -Tag 'Common', 'InstanceName' { } Context 'Generate a document with an instance name' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $dummyObject - OutputPath = $outputPath + BeforeAll { + $invokeParams = @{ + Path = $docFilePath + InputObject = $dummyObject + OutputPath = $outputPath + } + $null = Invoke-PSDocument @invokeParams -InstanceName 'Instance1' -Name 'WithInstanceName'; } - $null = Invoke-PSDocument @invokeParams -InstanceName 'Instance1' -Name 'WithInstanceName'; It 'Should not create a output with the document name' { Test-Path -Path "$outputPath\WithInstanceName.md" | Should -Be $False; Test-Path -Path "$outputPath\Instance1.md" | Should -Be $True; @@ -68,51 +71,59 @@ Describe 'PSDocs instance names' -Tag 'Common', 'InstanceName' { } Context 'Generate a document with multiple instance names' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $dummyObject - OutputPath = $outputPath + BeforeAll { + $invokeParams = @{ + Path = $docFilePath + InputObject = $dummyObject + OutputPath = $outputPath + } + $null = Invoke-PSDocument @invokeParams -InstanceName 'Instance2', 'Instance3' -Name 'WithMultiInstanceName'; } - $null = Invoke-PSDocument @invokeParams -InstanceName 'Instance2','Instance3' -Name 'WithMultiInstanceName'; It 'Should not create a output with the document name' { - Test-Path -Path "$outputPath\WithMultiInstanceName.md" | Should be $False; + Test-Path -Path "$outputPath\WithMultiInstanceName.md" | Should -Be $False; } It 'Should generate an output named Instance2.md' { - Test-Path -Path "$outputPath\Instance2.md" | Should be $True; - Get-Content -Path "$outputPath\Instance2.md" -Raw | Should match 'Instance2'; + Test-Path -Path "$outputPath\Instance2.md" | Should -Be $True; + Get-Content -Path "$outputPath\Instance2.md" -Raw | Should -Match 'Instance2'; } It 'Should generate an output named Instance3.md' { - Test-Path -Path "$outputPath\Instance3.md" | Should be $True; - Get-Content -Path "$outputPath\Instance3.md" -Raw | Should match 'Instance3'; + Test-Path -Path "$outputPath\Instance3.md" | Should -Be $True; + Get-Content -Path "$outputPath\Instance3.md" -Raw | Should -Match 'Instance3'; } } Context 'Generate a document with a specific encoding' { - $testObject = [PSCustomObject]@{ - Name = 'TestObject' - } - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - OutputPath = $outputPath + BeforeAll { + $testObject = [PSCustomObject]@{ + Name = 'TestObject' + } + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + OutputPath = $outputPath + } + $encodings = @('UTF8', 'UTF7', 'Unicode', 'ASCII', 'UTF32') } # Check each encoding can be written then read - foreach ($encoding in @('UTF8', 'UTF7', 'Unicode', 'ASCII', 'UTF32')) { + foreach ($encoding in $encodings) { + $currentEncoding = $encoding It "Should generate $encoding encoded content" { - Invoke-PSDocument @invokeParams -InstanceName "With$encoding" -Encoding $encoding -Name 'WithEncoding'; - Get-Content -Path (Join-Path -Path $outputPath -ChildPath "With$encoding.md") -Encoding $encoding | Out-String | Should -Match "^(With$encoding(\r|\n|\r\n))$"; + Invoke-PSDocument @invokeParams -InstanceName "With$currentEncoding" -Encoding $currentEncoding -Name 'WithEncoding'; + Get-Content -Path (Join-Path -Path $outputPath -ChildPath "With$currentEncoding.md") -Encoding $currentEncoding | Out-String | Should -Match "^(With$currentEncoding(\r|\n|\r\n))$"; } } } Context 'With -PassThru' { - $testObject = [PSCustomObject]@{ - Name = 'TestObject' - } - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - PassThru = $True + BeforeAll { + $testObject = [PSCustomObject]@{ + Name = 'TestObject' + } + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + PassThru = $True + } } It 'Should return results' { $result = Invoke-PSDocument @invokeParams -Name 'WithPassThru'; @@ -122,8 +133,11 @@ Describe 'PSDocs instance names' -Tag 'Common', 'InstanceName' { } Describe 'Invoke-PSDocument' -Tag 'Cmdlet', 'Common', 'Invoke-PSDocument', 'FromPath' { - $testObject = [PSCustomObject]@{}; + Context 'With -Path' { + BeforeAll { + $testObject = [PSCustomObject]@{}; + } It 'Should match name' { # Only generate documents for the named document $testObject | Invoke-PSDocument -Path $here -OutputPath $outputPath -Name FromFileTest2; @@ -139,7 +153,7 @@ Describe 'Invoke-PSDocument' -Tag 'Cmdlet', 'Common', 'Invoke-PSDocument', 'From } It 'Should match all tags' { # Only generate for documents with all matching tags - $testObject | Invoke-PSDocument -Path $here -OutputPath $outputPath -Tag Test4,Test5; + $testObject | Invoke-PSDocument -Path $here -OutputPath $outputPath -Tag Test4, Test5; Test-Path -Path "$outputPath\FromFileTest1.md" | Should -Be $False; Test-Path -Path "$outputPath\FromFileTest4.md" | Should -Be $False; Test-Path -Path "$outputPath\FromFileTest5.md" | Should -Be $True; @@ -155,11 +169,14 @@ Describe 'Invoke-PSDocument' -Tag 'Cmdlet', 'Common', 'Invoke-PSDocument', 'From } Context 'With -Module' { - $testModuleSourcePath = Join-Path $here -ChildPath 'TestModule'; - - It 'Returns documents' { + BeforeAll { + $testObject = [PSCustomObject]@{}; + $testModuleSourcePath = Join-Path $here -ChildPath 'TestModule'; $Null = Import-Module $testModuleSourcePath -Force; $result = @($testObject | Invoke-PSDocument -Module 'TestModule' -Name 'TestDocument1' -Culture 'en-US', 'en-AU', 'en-ZZ'); + } + + It 'Returns documents' { $result | Should -Not -BeNullOrEmpty; $result.Length | Should -Be 3; $result[0].Split([System.Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries) | Should -Be "Culture=en-US"; @@ -169,8 +186,11 @@ Describe 'Invoke-PSDocument' -Tag 'Cmdlet', 'Common', 'Invoke-PSDocument', 'From } Context 'With -PassThru' { + BeforeAll { + $testObject = [PSCustomObject]@{}; + $result = @($testObject | Invoke-PSDocument -Path $here -OutputPath $outputPath -Name FromFileTest1, FromFileTest2 -PassThru); + } It 'Should return results' { - $result = @($testObject | Invoke-PSDocument -Path $here -OutputPath $outputPath -Name FromFileTest1,FromFileTest2 -PassThru); $result | Should -Not -BeNullOrEmpty; $result.Length | Should -Be 2; $result[0] | Should -Match "`# Test title"; @@ -179,8 +199,10 @@ Describe 'Invoke-PSDocument' -Tag 'Cmdlet', 'Common', 'Invoke-PSDocument', 'From } Context 'With -InputPath' { + BeforeAll { + $result = @(Invoke-PSDocument -Path $here -OutputPath $outputPath -InputPath $here/*.yml -Name FromFileTest1, FromFileTest2 -PassThru); + } It 'Should return results' { - $result = @(Invoke-PSDocument -Path $here -OutputPath $outputPath -InputPath $here/*.yml -Name FromFileTest1,FromFileTest2 -PassThru); $result | Should -Not -BeNullOrEmpty; $result.Length | Should -Be 4; $result[0] | Should -Match "`# Test title"; @@ -189,6 +211,9 @@ Describe 'Invoke-PSDocument' -Tag 'Cmdlet', 'Common', 'Invoke-PSDocument', 'From } Context 'With constrained language' { + BeforeAll { + $testObject = [PSCustomObject]@{}; + } # Check that '[Console]::WriteLine('Should fail')' is not executed It 'Should fail to execute blocked code' { { $testObject | Invoke-PSDocument -Path $here -OutputPath $outputPath -Name 'ConstrainedTest2' -Option @{ 'Execution.LanguageMode' = 'ConstrainedLanguage' } -ErrorAction Stop } | Should -Throw 'Cannot invoke method. Method invocation is supported only on core types in this language mode.'; @@ -205,48 +230,54 @@ Describe 'Invoke-PSDocument' -Tag 'Cmdlet', 'Common', 'Invoke-PSDocument', 'From } Describe 'Get-PSDocument' -Tag 'Cmdlet', 'Common', 'Get-PSDocument' { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Cmdlets.Doc.ps1'; - Context 'With -Module' { - $testModuleSourcePath = Join-Path $here -ChildPath 'TestModule'; - - It 'Returns documents' { + BeforeAll { + $testModuleSourcePath = Join-Path $here -ChildPath 'TestModule' + $mock = Mock -ModuleName 'PSDocs' LoadModule + Import-Module $testModuleSourcePath -Force + if ($Null -ne (Get-Module -Name TestModule -ErrorAction SilentlyContinue)) { + $Null = Remove-Module -Name TestModule; + } $Null = Import-Module $testModuleSourcePath -Force; $result = @(Get-PSDocument -Module 'TestModule'); + $currentLoadingPreference = Get-Variable -Name PSModuleAutoLoadingPreference -ErrorAction SilentlyContinue -ValueOnly + $Env:PSModulePath = $here; + } + It 'Returns documents' { $result | Should -Not -BeNullOrEmpty; $result.Length | Should -Be 2; $result.Id | Should -BeIn 'TestModule\TestDocument1', 'TestModule\TestDocument2'; } - if ($Null -ne (Get-Module -Name TestModule -ErrorAction SilentlyContinue)) { - $Null = Remove-Module -Name TestModule; - } It 'Loads module with preference' { - Mock -CommandName 'LoadModule' -ModuleName 'PSDocs'; - $currentLoadingPreference = Get-Variable -Name PSModuleAutoLoadingPreference -ErrorAction SilentlyContinue -ValueOnly; - try { # Test negative case - $Global:PSModuleAutoLoadingPreference = [System.Management.Automation.PSModuleAutoLoadingPreference]::None; - $Null = Get-PSDocument -Module 'TestModule'; - Assert-MockCalled -CommandName 'LoadModule' -ModuleName 'PSDocs' -Times 0 -Scope 'It'; - + $Global:PSModuleAutoLoadingPreference = [System.Management.Automation.PSModuleAutoLoadingPreference]::None + Write-Host "Calling Get-PSDocument with preference set to None" + $Null = Get-PSDocument -Module 'TestModule' + #Assert-MockCalled -CommandName 'LoadModule' -ModuleName 'PSDocs' -Times 0 -Scope 'It' + $mock | Should -Invoke LoadModule -ModuleName 'PSDocs' -Times 0 -Scope 'It' # Test positive case - $Global:PSModuleAutoLoadingPreference = [System.Management.Automation.PSModuleAutoLoadingPreference]::All; - $Null = Get-PSDocument -Module 'TestModule'; - Assert-MockCalled -CommandName 'LoadModule' -ModuleName 'PSDocs' -Times 1 -Scope 'It'; + $Global:PSModuleAutoLoadingPreference = [System.Management.Automation.PSModuleAutoLoadingPreference]::All + Write-Host "Calling Get-PSDocument with preference set to All" + $Null = Get-PSDocument -Module 'TestModule' + #Assert-MockCalled -CommandName 'LoadModule' -ModuleName 'PSDocs' -Times 1 -Scope 'It' -Exactly + $mock | Should -Invoke LoadModule -ModuleName 'PSDocs' -Times 1 -Scope 'It' + + Assert-VerifiableMocks } finally { if ($Null -eq $currentLoadingPreference) { - Remove-Variable -Name PSModuleAutoLoadingPreference -Force -ErrorAction SilentlyContinue; + Remove-Variable -Name PSModuleAutoLoadingPreference -Force -ErrorAction SilentlyContinue } else { - $Global:PSModuleAutoLoadingPreference = $currentLoadingPreference; + $Global:PSModuleAutoLoadingPreference = $currentLoadingPreference } } } + It 'Use modules already loaded' { Mock -CommandName 'GetAutoloadPreference' -ModuleName 'PSDocs' -MockWith { return [System.Management.Automation.PSModuleAutoLoadingPreference]::All; @@ -312,17 +343,18 @@ Describe 'Get-PSDocument' -Tag 'Cmdlet', 'Common', 'Get-PSDocument' { } Describe 'Get-PSDocumentHeader' -Tag 'Cmdlet', 'Common', 'Get-PSDocumentHeader' { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Cmdlets.Doc.ps1'; - Context 'With -Path' { - $testObject = [PSCustomObject]@{ - Name = 'TestObject' - } - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - OutputPath = $outputPath + BeforeAll { + $testObject = [PSCustomObject]@{ + Name = 'TestObject' + } + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + OutputPath = $outputPath + } } + It 'Get Metadata header' { $result = Invoke-PSDocument @invokeParams -Name 'WithMetadata'; $result = Get-PSDocumentHeader -Path $outputPath; diff --git a/tests/PSDocs.Tests/PSDocs.Conventions.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Conventions.Tests.ps1 index df7ea13..5dfa070 100644 --- a/tests/PSDocs.Tests/PSDocs.Conventions.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Conventions.Tests.ps1 @@ -7,28 +7,31 @@ [CmdletBinding()] param () +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$outputPath = Join-Path -Path $rootPath -ChildPath out/tests/PSDocs.Tests/Conventions; -$here = (Resolve-Path $PSScriptRoot).Path; - + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $outputPath = Join-Path -Path $rootPath -ChildPath out/tests/PSDocs.Tests/Conventions; + $here = (Resolve-Path $PSScriptRoot).Path; +} Describe 'PSDocs -- Conventions' -Tag Conventions { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Conventions.Doc.ps1'; - $testObject = [PSCustomObject]@{ - Name = 'TestObject' - } + Context '-Convention' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - OutputPath = $outputPath + BeforeAll { + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Conventions.Doc.ps1'; + $testObject = [PSCustomObject]@{ + Name = 'TestObject' + } + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + OutputPath = $outputPath + } } It 'Generate output' { # Singe convention diff --git a/tests/PSDocs.Tests/PSDocs.Include.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Include.Tests.ps1 index 9a8a6f2..168befe 100644 --- a/tests/PSDocs.Tests/PSDocs.Include.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Include.Tests.ps1 @@ -8,29 +8,31 @@ [CmdletBinding()] param () -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; -# Setup tests paths -$rootPath = $PWD; + # Setup tests paths + $rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; - -$outputPath = Join-Path -Path $rootPath -ChildPath out/tests/PSDocs.Tests/Include; -Remove-Item -Path $outputPath -Force -Recurse -Confirm:$False -ErrorAction Ignore; -$Null = New-Item -Path $outputPath -ItemType Directory -Force; -$here = (Resolve-Path $PSScriptRoot).Path; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $outputPath = Join-Path -Path $rootPath -ChildPath out/tests/PSDocs.Tests/Include; + Remove-Item -Path $outputPath -Force -Recurse -Confirm:$False -ErrorAction Ignore; + $Null = New-Item -Path $outputPath -ItemType Directory -Force; + $here = (Resolve-Path $PSScriptRoot).Path; +} Describe 'PSDocs -- Include keyword' -Tag Include { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; - $testObject = [PSCustomObject]@{}; - Context 'Markdown' { - $invokeParams = @{ - Path = $docFilePath - OutputPath = $outputPath - ErrorAction = [System.Management.Automation.ActionPreference]::Stop + BeforeAll { + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + $testObject = [PSCustomObject]@{}; + $invokeParams = @{ + Path = $docFilePath + OutputPath = $outputPath + ErrorAction = [System.Management.Automation.ActionPreference]::Stop + } } It 'Should include a relative path' { @@ -51,7 +53,7 @@ Describe 'PSDocs -- Include keyword' -Tag Include { } It 'Should include from culture' { - $Null = $testObject | Invoke-PSDocument @invokeParams -Culture 'en-AU','en-US' -Name 'IncludeCulture'; + $Null = $testObject | Invoke-PSDocument @invokeParams -Culture 'en-AU', 'en-US' -Name 'IncludeCulture'; $outputDoc = "$outputPath\en-AU\IncludeCulture.md"; Test-Path -Path $outputDoc | Should -Be $True; diff --git a/tests/PSDocs.Tests/PSDocs.Metadata.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Metadata.Tests.ps1 index 74523a3..cb38261 100644 --- a/tests/PSDocs.Tests/PSDocs.Metadata.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Metadata.Tests.ps1 @@ -9,26 +9,29 @@ param ( ) - -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$here = (Resolve-Path $PSScriptRoot).Path; -$dummyObject = New-Object -TypeName PSObject; - +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; + + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $here = (Resolve-Path $PSScriptRoot).Path; + $dummyObject = New-Object -TypeName PSObject; +} Describe 'PSDocs -- Metadata keyword' -Tag Metadata { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; Context 'Markdown' { + BeforeAll{ + + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; $invokeParams = @{ - Path = $docFilePath + Path = $docFilePath InputObject = $dummyObject - PassThru = $True + PassThru = $True } + } It 'Metadata single entry' { $result = Invoke-PSDocument @invokeParams -Name 'MetadataSingleEntry'; $result | Should -Match '---(\r|\n|\r\n)title: Test(\r|\n|\r\n)---'; diff --git a/tests/PSDocs.Tests/PSDocs.Note.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Note.Tests.ps1 index 82a182d..03bef7c 100644 --- a/tests/PSDocs.Tests/PSDocs.Note.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Note.Tests.ps1 @@ -9,27 +9,30 @@ param ( ) +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$here = (Resolve-Path $PSScriptRoot).Path; - + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $here = (Resolve-Path $PSScriptRoot).Path; +} Describe 'PSDocs -- Note keyword' -Tag Note { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; - $testObject = [PSCustomObject]@{ - Name = 'TestObject' - } + Context 'Markdown' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - PassThru = $True + BeforeAll { + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + $testObject = [PSCustomObject]@{ + Name = 'TestObject' + } + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + PassThru = $True + } } It 'Should handle single line input' { $result = Invoke-PSDocument @invokeParams -Name 'NoteSingleMarkdown'; diff --git a/tests/PSDocs.Tests/PSDocs.Options.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Options.Tests.ps1 index 78e6655..f54acc3 100644 --- a/tests/PSDocs.Tests/PSDocs.Options.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Options.Tests.ps1 @@ -8,28 +8,30 @@ [CmdletBinding()] param () -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; -$here = Split-Path -Parent $MyInvocation.MyCommand.Path; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$emptyOptionsFilePath = Join-Path -Path $here -ChildPath 'psdocs.yml'; - +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; + + # Setup tests paths + $rootPath = $PWD; + $here = Split-Path -Parent $MyInvocation.MyCommand.Definition + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $emptyOptionsFilePath = Join-Path -Path $here -ChildPath 'psdocs.yml'; +} Describe 'New-PSDocumentOption' -Tag 'Option' { Context 'Read psdocs.yml' { - - try { - Push-Location -Path $here; - It 'can read default YAML' { - $option = New-PSDocumentOption; - $option.Generator | Should -Be 'PSDocs'; + BeforeAll { + try { + Push-Location -Path $here; + It 'can read default YAML' { + $option = New-PSDocumentOption; + $option.Generator | Should -Be 'PSDocs'; + } + } + finally { + Pop-Location; } - } - finally { - Pop-Location; } } diff --git a/tests/PSDocs.Tests/PSDocs.Section.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Section.Tests.ps1 index 3dd438f..7c92524 100644 --- a/tests/PSDocs.Tests/PSDocs.Section.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Section.Tests.ps1 @@ -7,25 +7,28 @@ [CmdletBinding()] param () - -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$here = (Resolve-Path $PSScriptRoot).Path; -$dummyObject = New-Object -TypeName PSObject; - +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; + + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $here = (Resolve-Path $PSScriptRoot).Path; + $dummyObject = New-Object -TypeName PSObject; +} Describe 'PSDocs -- Section keyword' -Tag Section { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + Context 'Markdown' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $dummyObject - PassThru = $True + BeforeAll { + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + $invokeParams = @{ + Path = $docFilePath + InputObject = $dummyObject + PassThru = $True + } } It 'With defaults' { diff --git a/tests/PSDocs.Tests/PSDocs.Selector.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Selector.Tests.ps1 index 1ecc203..7484331 100644 --- a/tests/PSDocs.Tests/PSDocs.Selector.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Selector.Tests.ps1 @@ -7,48 +7,50 @@ [CmdletBinding()] param () +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; + # Setup tests paths + $rootPath = $PWD; -# Setup tests paths -$rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $outputPath = Join-Path -Path $rootPath -ChildPath out/tests/PSDocs.Tests/Selector; + Remove-Item -Path $outputPath -Force -Recurse -Confirm:$False -ErrorAction Ignore; + $Null = New-Item -Path $outputPath -ItemType Directory -Force; + $here = (Resolve-Path $PSScriptRoot).Path; -$outputPath = Join-Path -Path $rootPath -ChildPath out/tests/PSDocs.Tests/Selector; -Remove-Item -Path $outputPath -Force -Recurse -Confirm:$False -ErrorAction Ignore; -$Null = New-Item -Path $outputPath -ItemType Directory -Force; -$here = (Resolve-Path $PSScriptRoot).Path; - -$dummyObject = @( - [PSObject]@{ - Name = 'ObjectName' - Value = 'ObjectValue' - generator = 'PSDocs' - } - - [PSObject]@{ - Name = 'HashName' - Value = 'HashValue' - generator = 'notPSDocs' - } -) + $dummyObject = @( + [PSObject]@{ + Name = 'ObjectName' + Value = 'ObjectValue' + generator = 'PSDocs' + } -Describe 'PSDocs selectors' -Tag 'Selector' { + [PSObject]@{ + Name = 'HashName' + Value = 'HashValue' + generator = 'notPSDocs' + } + ) $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Selector.Doc.ps1'; $selectorFilePath = Join-Path -Path $here -ChildPath 'Selectors.Doc.yaml'; - +} +Describe 'PSDocs selectors' -Tag 'Selector' { Context 'Invoke definitions' { - $invokeParams = @{ - Path = @($docFilePath, $selectorFilePath) - } + BeforeAll { - It 'Generates documentation for matching objects' { - $result = @($dummyObject | Invoke-PSDocument @invokeParams -Name 'Selector.WithInputObject' -PassThru); - $result | Should -Not -BeNullOrEmpty; - $result | Should -Not -Be 'Name: HashName'; + $invokeParams = @{ + Path = @($docFilePath, $selectorFilePath) + } + + It 'Generates documentation for matching objects' { + $result = @($dummyObject | Invoke-PSDocument @invokeParams -Name 'Selector.WithInputObject' -PassThru); + $result | Should -Not -BeNullOrEmpty; + $result | Should -Not -Be 'Name: HashName'; + } } } diff --git a/tests/PSDocs.Tests/PSDocs.Table.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Table.Tests.ps1 index 9580cd6..01c4f6a 100644 --- a/tests/PSDocs.Tests/PSDocs.Table.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Table.Tests.ps1 @@ -8,28 +8,32 @@ [CmdletBinding()] param () -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$here = (Resolve-Path $PSScriptRoot).Path; +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $here = (Resolve-Path $PSScriptRoot).Path; +} Describe 'PSDocs -- Table keyword' -Tag Table { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; - $testObject = [PSCustomObject]@{}; + Context 'Markdown' { - $invokeParams = @{ - Path = $docFilePath - PassThru = $True + BeforeAll { + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + $testObject = [PSCustomObject]@{}; + $invokeParams = @{ + Path = $docFilePath + PassThru = $True + } } It 'With defaults' { $result = Invoke-PSDocument @invokeParams -InputObject $rootPath -InstanceName Table -Name 'TableTests' -Option @{ 'Markdown.ColumnPadding' = 'None' - 'Markdown.UseEdgePipes' = 'Always' + 'Markdown.UseEdgePipes' = 'Always' }; $result | Should -Match '(\r|\n|\r\n)|LICENSE|False|(\r|\n|\r\n)'; $result | Should -Match '(\r|\n|\r\n)|README.md|False|(\r|\n|\r\n)'; @@ -53,7 +57,7 @@ Describe 'PSDocs -- Table keyword' -Tag Table { It 'With multiline column' { $testObject = [PSCustomObject]@{ - Name = 'Test' + Name = 'Test' Description = "This is a`r`ndescription`r`nsplit`r`nover`r`nmultiple`r`nlines." } @@ -70,7 +74,7 @@ Describe 'PSDocs -- Table keyword' -Tag Table { It 'With null column' { $testObject = [PSCustomObject]@{ - Name = 'Test' + Name = 'Test' Value = 'Value' } $result = Invoke-PSDocument @invokeParams -Name 'TableWithEmptyColumn' -InputObject $testObject -InstanceName 'TableWithEmptyColumn'; diff --git a/tests/PSDocs.Tests/PSDocs.Tests.csproj b/tests/PSDocs.Tests/PSDocs.Tests.csproj index dcd2b95..20a8b9e 100644 --- a/tests/PSDocs.Tests/PSDocs.Tests.csproj +++ b/tests/PSDocs.Tests/PSDocs.Tests.csproj @@ -10,11 +10,11 @@ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/PSDocs.Tests/PSDocs.Title.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Title.Tests.ps1 index 7d7bf4f..8021ce9 100644 --- a/tests/PSDocs.Tests/PSDocs.Title.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Title.Tests.ps1 @@ -8,27 +8,32 @@ [CmdletBinding()] param () -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; - -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$here = (Resolve-Path $PSScriptRoot).Path; +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $here = (Resolve-Path $PSScriptRoot).Path; +} Describe 'PSDocs -- Title keyword' -Tag Title { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; - $testObject = [PSCustomObject]@{ - Name = 'TestObject' - } + Context 'Markdown' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - PassThru = $True - ErrorAction = [System.Management.Automation.ActionPreference]::Stop + BeforeAll { + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + $testObject = [PSCustomObject]@{ + Name = 'TestObject' + } + + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + PassThru = $True + ErrorAction = [System.Management.Automation.ActionPreference]::Stop + } } It 'With single title' { $result = Invoke-PSDocument @invokeParams -Name 'SingleTitle'; diff --git a/tests/PSDocs.Tests/PSDocs.Variables.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Variables.Tests.ps1 index 0886fa0..b4c88e1 100644 --- a/tests/PSDocs.Tests/PSDocs.Variables.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Variables.Tests.ps1 @@ -8,26 +8,29 @@ [CmdletBinding()] param () -# Setup error handling -$ErrorActionPreference = 'Stop'; -Set-StrictMode -Version latest; +BeforeAll { + # Setup error handling + $ErrorActionPreference = 'Stop'; + Set-StrictMode -Version latest; -# Setup tests paths -$rootPath = $PWD; -Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; -$here = (Resolve-Path $PSScriptRoot).Path; - -Describe 'PSDocs variables' -Tag 'Variables' { + # Setup tests paths + $rootPath = $PWD; + Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; + $here = (Resolve-Path $PSScriptRoot).Path; $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Variables.Doc.ps1'; $testObject = [PSCustomObject]@{ Name = 'TestObject' } +} +Describe 'PSDocs variables' -Tag 'Variables' { Context 'PowerShell automatic variables' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - PassThru = $True + BeforeAll { + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + PassThru = $True + } } It 'Paths' { $result = (Invoke-PSDocument @invokeParams -Name 'PSAutomaticVariables' | Out-String).Split([System.Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries); @@ -38,13 +41,15 @@ Describe 'PSDocs variables' -Tag 'Variables' { } Context 'PSDocs automatic variables' { - $invokeParams = @{ - Path = $docFilePath - InputObject = $testObject - PassThru = $True - Option = @{ - 'Configuration.author' = @{ name = 'unit-tester' } - 'Configuration.enabled' = 'faLse' + BeforeAll { + $invokeParams = @{ + Path = $docFilePath + InputObject = $testObject + PassThru = $True + Option = @{ + 'Configuration.author' = @{ name = 'unit-tester' } + 'Configuration.enabled' = 'faLse' + } } } It '$PSDocs' { diff --git a/tests/PSDocs.Tests/PSDocs.Warning.Tests.ps1 b/tests/PSDocs.Tests/PSDocs.Warning.Tests.ps1 index d1c2820..a606ebe 100644 --- a/tests/PSDocs.Tests/PSDocs.Warning.Tests.ps1 +++ b/tests/PSDocs.Tests/PSDocs.Warning.Tests.ps1 @@ -8,6 +8,7 @@ [CmdletBinding()] param () +BeforeAll{ # Setup error handling $ErrorActionPreference = 'Stop'; Set-StrictMode -Version latest; @@ -16,19 +17,22 @@ Set-StrictMode -Version latest; $rootPath = $PWD; Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSDocs) -Force; $here = (Resolve-Path $PSScriptRoot).Path; - +} Describe 'PSDocs -- Warning keyword' -Tag Warning { - $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; + + + Context 'Markdown' { + BeforeAll{ + $docFilePath = Join-Path -Path $here -ChildPath 'FromFile.Keyword.Doc.ps1'; $testObject = [PSCustomObject]@{ Name = 'TestObject' } - - Context 'Markdown' { $invokeParams = @{ Path = $docFilePath InputObject = $testObject PassThru = $True } + } It 'Should handle single line input' { $result = Invoke-PSDocument @invokeParams -Name 'WarningSingleMarkdown'; $result | Should -Match '\> \[\!WARNING\](\r|\n|\r\n)> This is a single line';