Skip to content

Commit 2bf5b5f

Browse files
committed
chore(tests): ✨ Add build script execution in BeforeDiscovery
* Ensure the build script is executed if the environment variable `BHProjectPath` is not set. * This change is applied across multiple test files to maintain consistency in the test setup.
1 parent 1cfca44 commit 2bf5b5f

12 files changed

+69
-33
lines changed

tests/ConditionEval.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
BeforeAll {
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
26
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
37
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
48
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName

tests/ExpandFileSourceSpec.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
BeforeDiscovery {
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
26
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
37
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
48
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName

tests/GetPlasterTemplate.Tests.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
BeforeDiscovery {
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
26
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
37
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
48
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
@@ -37,7 +41,7 @@ Describe 'Get-PlasterTemplate' {
3741
Context "when searching modules for templates" {
3842
It "finds built-in templates" {
3943
$templates = Get-PlasterTemplate
40-
$templates | Where-Object Title -eq 'New PowerShell Manifest Module' | Should -Not -BeNullOrEmpty
44+
$templates | Where-Object Title -EQ 'New PowerShell Manifest Module' | Should -Not -BeNullOrEmpty
4145
}
4246

4347
It "finds built-in templates by name" {
@@ -52,10 +56,10 @@ Describe 'Get-PlasterTemplate' {
5256

5357
It "finds templates included with modules" {
5458
$builtInTemplates = Get-PlasterTemplate
55-
$oldPSModulePath = $env:PSModulePath;
59+
$oldPSModulePath = $env:PSModulePath
5660
# Only use example path, because tester could have many templates
5761
# installed and ordering is Alphbetical.
58-
$env:PSModulePath = $examplesPath;
62+
$env:PSModulePath = $examplesPath
5963

6064
$templates = Get-PlasterTemplate -IncludeInstalledModules
6165
$templates.Count -gt $builtInTemplates.Count | Should -Be $true
@@ -64,4 +68,4 @@ Describe 'Get-PlasterTemplate' {
6468
$env:PSModulePath = $oldPSModulePath
6569
}
6670
}
67-
}
71+
}

tests/Help.tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Taken with love from @juneb_get_help (https://raw.githubusercontent.com/juneb/PesterTDD/master/Module.Help.Tests.ps1)
22

33
BeforeDiscovery {
4+
if ($null -eq $env:BHProjectPath) {
5+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
6+
. $path -Task Build
7+
}
48
function global:FilterOutCommonParams {
59
param ($Params)
610
$commonParameters = [System.Management.Automation.PSCmdlet]::CommonParameters +

tests/InvokePlaster.Tests.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
BeforeDiscovery {
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
26
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
37
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
48
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
@@ -91,7 +95,7 @@ Describe 'Invoke-Plaster Tests' {
9195

9296
# Snagged from Pester documentation
9397
function GetFullPath {
94-
Param(
98+
param(
9599
[string] $Path
96100
)
97101
$full = $Path.Replace('TestDrive:', (Get-PSDrive TestDrive).Root)

tests/Manifest.tests.ps1

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
BeforeAll {
2-
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
36
# NEW: Pre-Specify RegEx Matching Patterns
4-
$gitTagMatchRegEx = 'tag:\s?.(\d+(\.\d+)*)' # NOTE - was 'tag:\s*(\d+(?:\.\d+)*)' previously
5-
$changelogTagMatchRegEx = "^##\s\[(?<Version>(\d+\.){1,3}\d+)\]"
6-
7-
$moduleName = $env:BHProjectName
8-
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
9-
$outputDir = Join-Path -Path $ENV:BHProjectPath -ChildPath 'Output'
10-
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
11-
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
7+
$gitTagMatchRegEx = 'tag:\s?.(\d+(\.\d+)*)' # NOTE - was 'tag:\s*(\d+(?:\.\d+)*)' previously
8+
$changelogTagMatchRegEx = "^##\s\[(?<Version>(\d+\.){1,3}\d+)\]"
9+
10+
$moduleName = $env:BHProjectName
11+
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
12+
$outputDir = Join-Path -Path $ENV:BHProjectPath -ChildPath 'Output'
13+
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
14+
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
1215
$outputManifestPath = Join-Path -Path $outputModVerDir -Child "$($moduleName).psd1"
13-
$manifestData = Test-ModuleManifest -Path $outputManifestPath -Verbose:$false -ErrorAction Stop -WarningAction SilentlyContinue
16+
$manifestData = Test-ModuleManifest -Path $outputManifestPath -Verbose:$false -ErrorAction Stop -WarningAction SilentlyContinue
1417

15-
$changelogPath = Join-Path -Path $env:BHProjectPath -Child 'CHANGELOG.md'
18+
$changelogPath = Join-Path -Path $env:BHProjectPath -Child 'CHANGELOG.md'
1619
$changelogVersion = Get-Content $changelogPath | ForEach-Object {
1720
if ($_ -match $changelogTagMatchRegEx) {
1821
$changelogVersion = $matches.Version
1922
break
2023
}
2124
}
2225

23-
$script:manifest = $null
26+
$script:manifest = $null
2427
}
2528
Describe 'Module manifest' {
2629

@@ -51,15 +54,15 @@ Describe 'Module manifest' {
5154
}
5255

5356
It 'Has a valid guid' {
54-
{[guid]::Parse($manifestData.Guid)} | Should -Not -Throw
57+
{ [guid]::Parse($manifestData.Guid) } | Should -Not -Throw
5558
}
5659

5760
It 'Has a valid copyright' {
5861
$manifestData.CopyRight | Should -Not -BeNullOrEmpty
5962
}
6063

6164
It 'Has a valid version in the changelog' {
62-
$changelogVersion | Should -Not -BeNullOrEmpty
65+
$changelogVersion | Should -Not -BeNullOrEmpty
6366
$changelogVersion -as [Version] | Should -Not -BeNullOrEmpty
6467
}
6568

@@ -72,7 +75,7 @@ Describe 'Module manifest' {
7275
Describe 'Git tagging' -Skip {
7376
BeforeAll {
7477
$gitTagVersion = $null
75-
78+
7679
# Ensure to only pull in a single git executable (in case multiple git's are found on path).
7780
if ($git = (Get-Command git -CommandType Application -ErrorAction SilentlyContinue)[0]) {
7881
$thisCommit = & $git log --decorate --oneline HEAD~1..HEAD
@@ -81,7 +84,7 @@ Describe 'Git tagging' -Skip {
8184
}
8285

8386
It 'Is tagged with a valid version' {
84-
$gitTagVersion | Should -Not -BeNullOrEmpty
87+
$gitTagVersion | Should -Not -BeNullOrEmpty
8588
$gitTagVersion -as [Version] | Should -Not -BeNullOrEmpty
8689
}
8790

tests/Meta.tests.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
BeforeAll {
2-
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
36
Set-StrictMode -Version latest
47

58
# Make sure MetaFixers.psm1 is loaded - it contains Get-TextFilesList
@@ -10,9 +13,9 @@ BeforeAll {
1013
$projectRoot = $PSScriptRoot
1114
}
1215

13-
$allTextFiles = Get-TextFilesList $projectRoot
16+
$allTextFiles = Get-TextFilesList $projectRoot
1417
$unicodeFilesCount = 0
15-
$totalTabsCount = 0
18+
$totalTabsCount = 0
1619
foreach ($textFile in $allTextFiles) {
1720
if (Test-FileUnicode $textFile) {
1821
$unicodeFilesCount++
@@ -25,7 +28,7 @@ BeforeAll {
2528
$unicodeFilesCount | Should -Be 0
2629

2730
$fileName = $textFile.FullName
28-
(Get-Content $fileName -Raw) | Select-String "`t" | Foreach-Object {
31+
(Get-Content $fileName -Raw) | Select-String "`t" | ForEach-Object {
2932
Write-Warning (
3033
"There are tabs in $fileName." +
3134
" Use Fixer 'Get-TextFilesList `$pwd | ConvertTo-SpaceIndentation'."

tests/ModuleManifest.Tests.ps1

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/NewPlasterManifest.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
BeforeDiscovery {
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
26
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
37
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
48
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName

tests/PlasterManifestValidation.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
BeforeDiscovery {
2+
if ($null -eq $env:BHProjectPath) {
3+
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
4+
. $path -Task Build
5+
}
26
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
37
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
48
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName

0 commit comments

Comments
 (0)