From 61988a0279262a12a8b2411985bfa3ebaba1c3e8 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Fri, 8 Oct 2021 14:08:06 +0800 Subject: [PATCH] (maint) Refactor testing GitHub Actions Previously the CI testing used Azure DevOps pipelines with hosted agents. This commit: * Changes the build and test process to not be destructive and instead create the moudle in the 'Output' directory * Adds the ability the use a different directory to load the module from before running the Pester tests * Uploads the Test Results and Code Coverage as per AzDo pipelines * Installs PowerShell on the test agent when needed. Mainly needed to x86 version of PowerShell 7 * Updates the module testing to use relative path to the module root instead of assuming the path is in a fixed location --- .github/workflows/ci.yaml | 99 +++++++++++++ .github/workflows/pwsh32.ps1 | 25 ++++ .gitignore | 4 + Azure-Pipelines/build.ps1 | 105 -------------- Azure-Pipelines/build.yml | 123 ---------------- .../BurntToast-Template.psm1 | 0 Tasks/build.ps1 | 135 ++++++++++++++++++ Tests/New-BTColumn.Tests.ps1 | 4 +- Tests/New-BTContent.Tests.ps1 | 3 +- Tests/New-BTImage.Tests.ps1 | 3 +- Tests/New-BurntToastNotification.Tests.ps1 | 3 +- Tests/_envPrep.ps1 | 9 +- 12 files changed, 279 insertions(+), 234 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/pwsh32.ps1 create mode 100644 .gitignore delete mode 100644 Azure-Pipelines/build.ps1 delete mode 100644 Azure-Pipelines/build.yml rename {Azure-Pipelines => Tasks}/BurntToast-Template.psm1 (100%) create mode 100644 Tasks/build.ps1 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..fe58f4e --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,99 @@ +name: BurntToast CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + Win2019-x64-pwsh: + name: Server 2019 - PowerShell - x64 + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Perform a Pester test from the command-line + shell: pwsh + run: ./Tasks/build.ps1 -Bootstrap -Test + + Win2019-x86-pwsh: + name: Server 2019 - PowerShell - x86 + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Perform a Pester test from the command-line + shell: pwsh + run: | + $Pwsh32 = .github/workflows/pwsh32.ps1 + & $Pwsh32 -File ./Tasks/build.ps1 -Bootstrap -Test + + Win2019-x64-winpwsh: + name: Server 2019 - Windows PowerShell - x64 + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Perform a Pester test from the command-line + shell: powershell + run: ./Tasks/build.ps1 -Bootstrap -Test + + Win2019-x86-winpwsh: + name: Server 2019 - Windows PowerShell - x86 + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Perform a Pester test from the command-line + shell: powershell + # TODO: This could be problematic with hardcoding + run: C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -File ./Tasks/build.ps1 -Bootstrap -Test + + build-and-oat-module: + name: Build Module and OAT + needs: ["Win2019-x64-pwsh", "Win2019-x64-winpwsh", "Win2019-x86-pwsh", "Win2019-x86-winpwsh"] + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Compile Module + shell: pwsh + run: ./Tasks/build.ps1 -Bootstrap -Compile + - name: OAT + shell: pwsh + env: + # Use the compiled module for testing + BURNTTOAST_MODULE_ROOT: './Output/BurntToast/BurntToast.psd1' + run: | + ./Tasks/build.ps1 -Test -CodeCoverage + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v2 + with: + name: test-results + path: "*.xml" + - name: Upload PowerShell Module + if: always() + uses: actions/upload-artifact@v2 + with: + name: burnttoast-module + path: "./Output/BurntToast/" + + publish-test-results: + name: "Publish Tests Results" + needs: build-and-oat-module + runs-on: ubuntu-latest + if: always() + steps: + - name: Download Artifacts + uses: actions/download-artifact@v2 + with: + name: test-results + path: artifacts + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + files: artifacts/**/TestResults.xml + - uses: codecov/codecov-action@v2 + if: always() + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: artifacts/CoverageResults.xml diff --git a/.github/workflows/pwsh32.ps1 b/.github/workflows/pwsh32.ps1 new file mode 100644 index 0000000..eb1b57a --- /dev/null +++ b/.github/workflows/pwsh32.ps1 @@ -0,0 +1,25 @@ +param( + [Switch]$Force +) +$CurrentPSVersion = "$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor).$($PSVersionTable.PSVersion.Patch)" + +$DownloadDir = Join-Path $PSScriptRoot '../../downloads' +If (-Not(Test-Path $DownloadDir)) { New-Item -Path $DownloadDir -ItemType 'Directory' | Out-Null } + +$PwshZip = Join-Path $DownloadDir 'pwsh.zip' +If ((Test-Path $PwshZip) -and $Force) { Remove-Item -Path $DownloadDir -Force -Confirm:$false | Out-Null } +If (-Not (Test-Path $PwshZip)) { + $DownloadUrl = "https://github.com/PowerShell/PowerShell/releases/download/v$CurrentPSVersion/PowerShell-$CurrentPSVersion-win-x86.zip" + Write-Host "Downloading $DownloadURL ..." + Invoke-WebRequest -Uri $DownloadUrl -OutFile $PwshZip +} else { + Write-Host "ZIP file has been downloaded" +} + +$PwshExtract = Join-Path $DownloadDir 'pwsh32' +If ((Test-Path $PwshExtract) -and $Force) { Remove-Item -Path $PwshExtract -Force -Confirm:$false -Recurse | Out-Null } +If (-Not (Test-Path $PwshExtract)) { + Expand-Archive -Path $PwshZip -DestinationPath $PwshExtract +} + +Join-Path $PwshExtract 'pwsh.exe' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc95a7a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +downloads/ +Output/ +TestResults.xml +CoverageResults.xml diff --git a/Azure-Pipelines/build.ps1 b/Azure-Pipelines/build.ps1 deleted file mode 100644 index 9dd2a20..0000000 --- a/Azure-Pipelines/build.ps1 +++ /dev/null @@ -1,105 +0,0 @@ -[CmdletBinding()] -param( - [switch] - $Bootstrap, - - [switch] - $Compile, - - [switch] - $Test, - - [switch] - $CodeCoverage -) - -# Bootstrap step -if ($Bootstrap.IsPresent) { - Write-Information "Validate and install missing prerequisits for building ..." - - # For testing Pester - if (-not (Get-Module -Name Pester -ListAvailable) -or (Get-Module -Name Pester -ListAvailable)[0].Version -eq [Version]'3.4.0') { - Write-Warning "Module 'Pester' is missing. Installing 'Pester' ..." - Install-Module -Name Pester -Scope CurrentUser -Force -RequiredVersion 4.10.1 -SkipPublisherCheck - } - - if ((Get-Module -Name Pester -ListAvailable)[0].Version -ne [Version]'4.10.1') { - Install-Module -Name Pester -Scope CurrentUser -Force -RequiredVersion 4.10.1 - } - - Import-Module -Name Pester -RequiredVersion 4.10.1 - - if (-not (Get-Module -Name PSCodeCovIo -ListAvailable)) { - Write-Warning "Module 'PSCodeCovIo' is missing. Installing 'PSCodeCovIo' ..." - Install-Module -Name PSCodeCovIo -Scope CurrentUser -Force - } -} - -# Compile step -if ($Compile.IsPresent) { - if (Get-Module BurntToast) { - Remove-Module BurntToast -Force - } - - if ((Test-Path ./Output)) { - Remove-Item -Path ./Output -Recurse -Force - } - - # Copy non-script files to output folder - if (-not (Test-Path .\Output)) { - $null = New-Item -Path .\Output -ItemType Directory - } - - Copy-Item -Path '.\BurntToast\*' -Filter '*.*' -Exclude '*.ps1', '*.psm1' -Recurse -Destination .\Output -Force - Remove-Item -Path .\Output\Private, .\Output\Public -Recurse -Force - - # Copy Module README file - Copy-Item -Path '.\README.md' -Destination .\Output -Force - - Get-ChildItem -Path ".\BurntToast\Private\*.ps1" -Recurse | Get-Content | Add-Content .\Output\BurntToast.psm1 - - $Public = @( Get-ChildItem -Path ".\BurntToast\Public\*.ps1" -ErrorAction SilentlyContinue ) - - $Public | Get-Content | Add-Content .\Output\BurntToast.psm1 - - "`$PublicFunctions = '$($Public.BaseName -join "', '")'" | Add-Content .\Output\BurntToast.psm1 - - Get-Content -Path .\Azure-Pipelines\BurntToast-Template.psm1 | Add-Content .\Output\BurntToast.psm1 - - Remove-Item -Path .\BurntToast -Recurse -Force - Rename-Item -Path .\Output -NewName 'BurntToast' - - # Compress output, for GitHub release - Compress-Archive -Path .\BurntToast\* -DestinationPath .\Azure-Pipelines\BurntToast.zip - - # Re-import module, extract release notes and version - Import-Module ./BurntToast/BurntToast.psd1 -Force - (Get-Module BurntToast)[0].ReleaseNotes | Add-Content .\Azure-Pipelines\release-notes.txt - (Get-Module BurntToast)[0].Version.ToString() | Add-Content .\Azure-Pipelines\release-version.txt -} - -# Test step -if($Test.IsPresent) { - if (-not (Get-Module -Name Pester -ListAvailable)) { - throw "Cannot find the 'Pester' module. Please specify '-Bootstrap' to install build dependencies." - } - - if (-not (Get-Module -Name PSCodeCovIo -ListAvailable)) { - throw "Cannot find the 'PSCodeCovIo' module. Please specify '-Bootstrap' to install build dependencies." - } - - $RelevantFiles = (Get-ChildItem ./BurntToast -Recurse -Include "*.psm1","*.ps1").FullName - - if ($env:TF_BUILD) { - $res = Invoke-Pester "./Tests" -OutputFormat NUnitXml -OutputFile TestResults.xml -CodeCoverage $RelevantFiles -CodeCoverageOutputFileFormat 'JaCoCo' -CodeCoverageOutputFile "$Env:AgentTemp\CoverageResults.xml" -PassThru - if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed." } - } else { - $res = Invoke-Pester "./Tests" -CodeCoverage $RelevantFiles -PassThru - } - - if ($CodeCoverage.IsPresent) { - Export-CodeCovIoJson -CodeCoverage $res.CodeCoverage -RepoRoot $pwd -Path coverage.json - - Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh - } -} diff --git a/Azure-Pipelines/build.yml b/Azure-Pipelines/build.yml deleted file mode 100644 index aa69e0e..0000000 --- a/Azure-Pipelines/build.yml +++ /dev/null @@ -1,123 +0,0 @@ -stages: -- stage: ThawBread - displayName: 'Thaw Frozen Bread' - jobs: - - job: Srv2019_64bit - displayName: 'Server 2019 - 64 bit' - pool: 'AzPS7.1-Preview' - steps: - - task: PowerShell@2 - displayName: 'Run tests (individual .ps1 files) - Windows PowerShell - x64' - inputs: - targetType: Inline - script: ./Azure-Pipelines/build.ps1 -Bootstrap -Test - env: - AgentTemp: $(Agent.TempDirectory) - - task: PowerShell@2 - displayName: 'Run tests (individual .ps1 files) - PowerShell 7.1 Preview 5 - x64' - inputs: - targetType: Inline - script: ./Azure-Pipelines/build.ps1 -Bootstrap -Test - pwsh: true - env: - AgentTemp: $(Agent.TempDirectory) - - job: Win10_32bit - displayName: 'Windows 10 - 32 bit' - pool: 'LabPS7x86' - steps: - - task: PowerShell@2 - displayName: 'Run tests (individual .ps1 files) - Windows PowerShell - x86' - inputs: - targetType: Inline - script: ./Azure-Pipelines/build.ps1 -Bootstrap -Test - env: - AgentTemp: $(Agent.TempDirectory) - - task: PowerShell@2 - displayName: 'Run tests (individual .ps1 files) - PowerShell 7.1 Preview 5 - x86' - inputs: - targetType: Inline - script: ./Azure-Pipelines/build.ps1 -Bootstrap -Test - pwsh: true - env: - AgentTemp: $(Agent.TempDirectory) -- stage: CookToast - displayName: 'Cook Toast' - dependsOn: 'ThawBread' - jobs: - - job: PreBuild - displayName: 'Pre-Build Tests' - pool: - vmImage: 'windows-2019' - steps: - - task: PowerShell@2 - displayName: 'Run tests (individual .ps1 files) - Windows PowerShell' - inputs: - targetType: Inline - script: ./Azure-Pipelines/build.ps1 -Bootstrap -Test - env: - AgentTemp: $(Agent.TempDirectory) - - job: 'BuildRetest' - displayName: 'Build & Re-test' - dependsOn: 'PreBuild' - pool: - vmImage: 'windows-2019' - steps: - - task: PowerShell@2 - displayName: 'Run tests (individual .ps1 files) - PowerShell Core' - inputs: - targetType: Inline - script: ./Azure-Pipelines/build.ps1 -Bootstrap -Test - pwsh: true - env: - AgentTemp: $(Agent.TempDirectory) - - - task: PowerShell@2 - displayName: 'Compile module' - inputs: - targetType: Inline - script: ./Azure-Pipelines/build.ps1 -Bootstrap -Compile - - - task: PowerShell@2 - displayName: 'Run tests (compiled .psm1)' - inputs: - targetType: Inline - script: ./Azure-Pipelines/build.ps1 -Test -CodeCoverage - env: - AgentTemp: $(Agent.TempDirectory) - - - task: PublishTestResults@2 - displayName: 'Publish test results' - inputs: - testRunner: NUnit - testResultsFiles: '**/TestResults.xml' - condition: succeededOrFailed() - - task: PublishCodeCoverageResults@1 - displayName: 'Publish code coverage results' - inputs: - summaryFileLocation: $(Agent.TempDirectory)/CoverageResults.xml - pathToSources: $(Agent.TempDirectory) - condition: succeededOrFailed() - - - task: Bash@3 - displayName: 'Upload coverage to Codecov' - inputs: - targetType: 'filePath' # Optional. Options: filePath, inline - filePath: ./codecov.sh - arguments: -f coverage.json -t $(CODECOV_TOKEN) - #script: '# Write your commands here# Use the environment variables input below to pass secret variables to this script' # Required when targetType == Inline - #workingDirectory: # Optional - #failOnStderr: false # Optional - - - task: PublishPipelineArtifact@0 - displayName: 'Publish compiled module artifact' - inputs: - artifactName: 'BurntToast' - targetPath: ./BurntToast - condition: succeededOrFailed() - - - task: PublishPipelineArtifact@0 - displayName: 'Publish Pipelines scripts as artifact' - inputs: - artifactName: 'PipelinesScripts' - targetPath: ./Azure-Pipelines - condition: succeededOrFailed() diff --git a/Azure-Pipelines/BurntToast-Template.psm1 b/Tasks/BurntToast-Template.psm1 similarity index 100% rename from Azure-Pipelines/BurntToast-Template.psm1 rename to Tasks/BurntToast-Template.psm1 diff --git a/Tasks/build.ps1 b/Tasks/build.ps1 new file mode 100644 index 0000000..e69d7e7 --- /dev/null +++ b/Tasks/build.ps1 @@ -0,0 +1,135 @@ +[CmdletBinding()] +param( + [switch] + $Bootstrap, + + [switch] + $Compile, + + [switch] + $Test, + + [switch] + $CodeCoverage +) + +# Write information +Write-Host "PS Version Information" +Write-Host "----------------------" +Write-Host ($PSVersionTable | ConvertTo-JSON -Depth 1) +Write-Host "Process Bitness" +Write-Host "---------------" +If ([IntPtr]::Size -eq 4) { + Write-Host "32 bit" +} +Else { + Write-Host "64 bit" +} +Write-Host '' + +$RootDir = Join-Path $PSScriptRoot '..' +$OutputDir = Join-Path $RootDir 'Output' + +# Bootstrap step +if ($Bootstrap.IsPresent) { + Write-Information "Validate and install missing prerequisits for building ..." + + # For testing Pester + if (-not (Get-Module -Name Pester -ListAvailable) -or (Get-Module -Name Pester -ListAvailable)[0].Version -eq [Version]'3.4.0') { + Write-Warning "Module 'Pester' is missing. Installing 'Pester' ..." + Install-Module -Name Pester -Scope CurrentUser -Force -RequiredVersion 4.10.1 -SkipPublisherCheck + } + + if ((Get-Module -Name Pester -ListAvailable)[0].Version -ne [Version]'4.10.1') { + Install-Module -Name Pester -Scope CurrentUser -Force -RequiredVersion 4.10.1 + } + + Import-Module -Name Pester -RequiredVersion 4.10.1 + + if (-not (Get-Module -Name PSCodeCovIo -ListAvailable)) { + Write-Warning "Module 'PSCodeCovIo' is missing. Installing 'PSCodeCovIo' ..." + Install-Module -Name PSCodeCovIo -Scope CurrentUser -Force + } +} + +# Compile step +if ($Compile.IsPresent) { + $CompileDir = Join-Path $OutputDir 'BurntToast' + $OutputZip = Join-Path $RootDir 'Output/BurntToast.zip' + + if ((Test-Path $OutputDir)) { + Remove-Item -Path $OutputDir -Recurse -Force + } + + # Copy non-script files to output folder + $null = New-Item -Path $CompileDir -ItemType Directory + + Write-Host "Copying support files ..." + Copy-Item -Path "$RootDir/BurntToast/*" -Filter '*.*' -Exclude '*.ps1', '*.psm1' -Recurse -Destination $CompileDir -Force + Remove-Item -Path "$CompileDir/Private", "$CompileDir/Public" -Recurse -Force + + # Copy Module README file + Copy-Item -Path "$RootDir/README.md" -Destination $CompileDir -Force + + Write-Host "Adding Private Functions ..." + Get-ChildItem -Path "$RootDir\BurntToast\Private\*.ps1" -Recurse | Get-Content | Add-Content "$CompileDir/BurntToast.psm1" + + Write-Host "Adding Public Functions ..." + $Public = @( Get-ChildItem -Path "$RootDir/BurntToast/Public/*.ps1" -ErrorAction SilentlyContinue ) + + $Public | Get-Content | Add-Content "$CompileDir/BurntToast.psm1" + + "`$PublicFunctions = '$($Public.BaseName -join "', '")'" | Add-Content "$CompileDir/BurntToast.psm1" + + Write-Host "Adding Module Template file ..." + Get-Content -Path (Join-Path $PSScriptRoot 'BurntToast-Template.psm1') | Add-Content "$CompileDir/BurntToast.psm1" + + # Compress output, for GitHub release + Write-Host "Creating ZIP file ..." + Compress-Archive -Path "$CompileDir/*" -DestinationPath $OutputZip + + # Re-import module, extract release notes and version + if (Get-Module BurntToast) { + Remove-Module BurntToast -Force + } + + Import-Module "$CompileDir/BurntToast.psd1" -Force + Write-Host "Extracting Release Notes and Version ..." + (Get-Module BurntToast)[0].ReleaseNotes | Add-Content (Join-Path $OutputDir 'release-notes.txt') + (Get-Module BurntToast)[0].Version.ToString() | Add-Content (Join-Path $OutputDir 'release-version.txt') + Write-Host "Finished Compiling" +} + +# Test step +if ($Test.IsPresent) { + if (-not (Get-Module -Name Pester -ListAvailable)) { + throw "Cannot find the 'Pester' module. Please specify '-Bootstrap' to install build dependencies." + } + + if (-not (Get-Module -Name PSCodeCovIo -ListAvailable)) { + throw "Cannot find the 'PSCodeCovIo' module. Please specify '-Bootstrap' to install build dependencies." + } + + if ($ENV:BURNTTOAST_MODULE_ROOT) { + $ModuleDir = (Get-Item -Path $ENV:BURNTTOAST_MODULE_ROOT).Directory.FullName + Write-Host "Using Module Root directory of $ModuleDir" + $RelevantFiles = (Get-ChildItem $ModuleDir -Recurse -Include "*.psm1", "*.ps1").FullName + } else { + $RelevantFiles = (Get-ChildItem ./BurntToast -Recurse -Include "*.psm1", "*.ps1").FullName + } + + if ($env:CI) { + Write-Host "Running Pester within CI with code coverage for $($RelevantFiles.Count) file/s" + $res = Invoke-Pester "./Tests" -OutputFormat JUnitXml -OutputFile TestResults.xml -CodeCoverage $RelevantFiles -CodeCoverageOutputFileFormat 'JaCoCo' -CodeCoverageOutputFile CoverageResults.xml -PassThru + if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed." } + } + else { + $res = Invoke-Pester "./Tests" -CodeCoverage $RelevantFiles -PassThru + } + + if ($CodeCoverage.IsPresent) { + Export-CodeCovIoJson -CodeCoverage $res.CodeCoverage -RepoRoot $pwd -Path coverage.json + + Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh + } +} diff --git a/Tests/New-BTColumn.Tests.ps1 b/Tests/New-BTColumn.Tests.ps1 index f48a782..26a72c6 100644 --- a/Tests/New-BTColumn.Tests.ps1 +++ b/Tests/New-BTColumn.Tests.ps1 @@ -2,7 +2,9 @@ Describe 'New-BTColumn' { Context 'via New-BurntToastNotification' { - $ImagePath = Resolve-Path -Path $PSScriptRoot\..\BurntToast\Images\BurntToast.png + $ModuleRoot = (Get-Item (Get-Module 'BurntToast').Path).Directory.FullName + $ImagePath = Resolve-Path -Path (Join-Path $ModuleRoot 'Images\BurntToast.png') + Start-Transcript tmp.log try { $TitleLabel = New-BTText -Text 'Title:' -Style Base diff --git a/Tests/New-BTContent.Tests.ps1 b/Tests/New-BTContent.Tests.ps1 index 061229c..50634e2 100644 --- a/Tests/New-BTContent.Tests.ps1 +++ b/Tests/New-BTContent.Tests.ps1 @@ -1,7 +1,8 @@ . (Join-Path -Path $PSScriptRoot -ChildPath '_envPrep.ps1') Describe 'New-BTContent' { - $ImagePath = Resolve-Path -Path $PSScriptRoot\..\BurntToast\Images\BurntToast.png + $ModuleRoot = (Get-Item (Get-Module 'BurntToast').Path).Directory.FullName + $ImagePath = Resolve-Path -Path (Join-Path $ModuleRoot 'Images\BurntToast.png') $Text1 = New-BTText -Content 'This is a test' $Text2 = New-BTText -Content 'This more testing' diff --git a/Tests/New-BTImage.Tests.ps1 b/Tests/New-BTImage.Tests.ps1 index 433ecc4..b6f9a07 100644 --- a/Tests/New-BTImage.Tests.ps1 +++ b/Tests/New-BTImage.Tests.ps1 @@ -1,7 +1,8 @@ . (Join-Path -Path $PSScriptRoot -ChildPath '_envPrep.ps1') Describe 'New-BTImage' { - $ImagePath = Resolve-Path -Path $PSScriptRoot\..\BurntToast\Images\BurntToast.png + $ModuleRoot = (Get-Item (Get-Module 'BurntToast').Path).Directory.FullName + $ImagePath = Resolve-Path -Path (Join-Path $ModuleRoot 'Images\BurntToast.png') Context 'standard image' { Start-Transcript tmp.log diff --git a/Tests/New-BurntToastNotification.Tests.ps1 b/Tests/New-BurntToastNotification.Tests.ps1 index 49567bc..be60da6 100644 --- a/Tests/New-BurntToastNotification.Tests.ps1 +++ b/Tests/New-BurntToastNotification.Tests.ps1 @@ -1,7 +1,8 @@ . (Join-Path -Path $PSScriptRoot -ChildPath '_envPrep.ps1') Describe 'New-BurntToastNotification' { - $ImagePath = Resolve-Path -Path $PSScriptRoot\..\BurntToast\Images\BurntToast.png + $ModuleRoot = (Get-Item (Get-Module 'BurntToast').Path).Directory.FullName + $ImagePath = Resolve-Path -Path (Join-Path $ModuleRoot 'Images\BurntToast.png') Context 'has registered alias' { $Aliases = Get-Alias -Name 'Toast' -ErrorAction SilentlyContinue diff --git a/Tests/_envPrep.ps1 b/Tests/_envPrep.ps1 index 18b4a9e..259b42c 100644 --- a/Tests/_envPrep.ps1 +++ b/Tests/_envPrep.ps1 @@ -1,5 +1,5 @@ if (Get-Module -Name 'BurntToast') { - Remove-Module -Name 'BurntToast' + Remove-Module -Name 'BurntToast' -Force } try { @@ -9,4 +9,9 @@ try { $PlatformAvailable = $false } -Import-Module "$PSScriptRoot/../BurntToast/BurntToast.psd1" -Force +if ($ENV:BURNTTOAST_MODULE_ROOT) { + Import-Module $ENV:BURNTTOAST_MODULE_ROOT -Force +} else { + Import-Module "$PSScriptRoot/../BurntToast/BurntToast.psd1" -Force +} +