From 6959cffa24154afe1013f303eb986254069d34f2 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Tue, 5 May 2020 02:22:53 -0500 Subject: [PATCH] added ImportOnly test and added additional macOS stage on azure-pipelines.yml --- CI/CI.ps1 | 27 ++++++++++++++++--- .../ImportExcelTests/TestImportOnly.tests.ps1 | 6 +++++ azure-pipelines.yml | 18 ++++++++++++- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 __tests__/ImportExcelTests/TestImportOnly.tests.ps1 diff --git a/CI/CI.ps1 b/CI/CI.ps1 index 5f88bc2..b5bd37b 100644 --- a/CI/CI.ps1 +++ b/CI/CI.ps1 @@ -13,7 +13,10 @@ param # AppVeyor and Azure - Upload module as AppVeyor Artifact. [Switch]$Artifact, # Azure - Runs PsScriptAnalyzer against one or more folders and pivots the results to form a report. - [Switch]$Analyzer + [Switch]$Analyzer, + # Installs the module and invokes only the ModuleImport test. + # Used for validating that the module imports still when external dependencies are missing, e.g. mono-libgdiplus on macOS. + [Switch]$TestImportOnly ) $ErrorActionPreference = 'Stop' if ($Initialize) { @@ -21,7 +24,7 @@ if ($Initialize) { $ModuleVersion = (. ([Scriptblock]::Create((Get-Content -Path $Psd1 | Out-String)))).ModuleVersion Update-AppveyorBuild -Version "$ModuleVersion ($env:APPVEYOR_BUILD_NUMBER) $env:APPVEYOR_REPO_BRANCH" } -if ($Test) { +if ($Test -or $TestImportOnly) { function Get-EnvironmentInfo { if ([environment]::OSVersion.Platform -like "win*") { # Get Windows Version @@ -97,7 +100,23 @@ if (-not $VersionFilePath) { '[Progress] Installing Module.' . .\CI\Install.ps1 '[Progress] Invoking Pester.' - Invoke-Pester -OutputFile ('TestResultsPS{0}.xml' -f $PSVersionTable.PSVersion) + $pesterParams = @{ + OutputFile = ('TestResultsPS{0}.xml' -f $PSVersionTable.PSVersion) + PassThru = $true + } + if ($TestImportOnly) { + $pesterParams['Tag'] = 'TestImportOnly' + } + else { + $pesterParams['ExcludeTag'] = 'TestImportOnly' + } + $testResults = Invoke-Pester @pesterParams + 'Pester invocation complete!' + if ($testResults.FailedCount -gt 0) { + "Test failures:" + $testResults.TestResult | Where-Object {-not $_.Passed} | Format-List + Write-Error "$($testResults.FailedCount) Pester tests failed. Build cannot continue!" + } } if ($Finalize) { '[Progress] Finalizing.' @@ -205,4 +224,4 @@ if ($Analyzer) { else { "[Info] Invoke-ScriptAnalyzer didn't return any problems." } -} \ No newline at end of file +} diff --git a/__tests__/ImportExcelTests/TestImportOnly.tests.ps1 b/__tests__/ImportExcelTests/TestImportOnly.tests.ps1 new file mode 100644 index 0000000..c0a1387 --- /dev/null +++ b/__tests__/ImportExcelTests/TestImportOnly.tests.ps1 @@ -0,0 +1,6 @@ +Param() +Describe "Module" -Tag "TestImportOnly" { + It "Should import without error" { + { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force -ErrorAction Stop } | Should -Not -Throw + } +} diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 99e61a7..97ecbdb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -92,4 +92,20 @@ jobs: inputs: testResultsFormat: 'NUnit' testResultsFiles: '**/TestResults*.xml' - failTaskOnFailedTests: true \ No newline at end of file + failTaskOnFailedTests: true + + - job: macOSNoDeps + pool: + vmImage: 'macOS-latest' + + steps: + - powershell: 'Install-Module -Name Pester -Force -MaximumVersion 4.99.99' + displayName: 'Update Pester' + - powershell: './CI/CI.ps1 -TestImportOnly' + displayName: 'Install and Test Import Only' + + - task: PublishTestResults@2 + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: '**/TestResults*.xml' + failTaskOnFailedTests: true