Skip to content

Commit fc9fdde

Browse files
authored
Update OffsetInspect.Tests.ps1
1 parent c9e39df commit fc9fdde

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

tests/OffsetInspect.Tests.ps1

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,76 @@
1-
# Pester tests for OffsetInspect module / manifest
1+
# Pester tests for OffsetInspect
22

3-
# --------------- Path discovery ---------------
3+
# Helper to find the module manifest reliably
4+
function Get-OffsetInspectManifestPath {
5+
param(
6+
[string]$TestsRoot
7+
)
48

5-
# tests folder
6-
$repoRoot = Split-Path -Parent $PSScriptRoot
9+
$repoRoot = Split-Path -Parent $TestsRoot
710

8-
# Find the first OffsetInspect.psd1 anywhere under the repo
9-
$manifestItem = Get-ChildItem -Path $repoRoot -Filter 'OffsetInspect.psd1' -Recurse -File |
10-
Select-Object -First 1
11+
$manifestItem = Get-ChildItem -Path $repoRoot -Filter 'OffsetInspect.psd1' -Recurse -File |
12+
Select-Object -First 1
1113

12-
if (-not $manifestItem) {
13-
throw "Could not find 'OffsetInspect.psd1' anywhere under '$repoRoot'. " +
14-
"Make sure your module manifest exists and is committed."
15-
}
16-
17-
$script:ManifestPath = $manifestItem.FullName
14+
if (-not $manifestItem) {
15+
throw "Could not find 'OffsetInspect.psd1' anywhere under '$repoRoot'. " +
16+
"Make sure your module manifest exists and is committed."
17+
}
1818

19-
Write-Host "Using manifest at: $script:ManifestPath"
19+
return $manifestItem.FullName
20+
}
2021

21-
# --------------- Manifest tests ---------------
22+
# ---------------- Manifest tests ----------------
2223

2324
Describe 'OffsetInspect module manifest' {
2425

26+
BeforeAll {
27+
# Resolve once per Describe, inside Pester’s scope
28+
$ManifestPath = Get-OffsetInspectManifestPath -TestsRoot $PSScriptRoot
29+
Write-Host "Using manifest (manifest describe): $ManifestPath"
30+
}
31+
2532
It 'exists' {
26-
Test-Path $script:ManifestPath | Should -BeTrue
33+
Test-Path $ManifestPath | Should -BeTrue
2734
}
2835

2936
It 'has a valid manifest' {
30-
{ Test-ModuleManifest -Path $script:ManifestPath } |
37+
{ Test-ModuleManifest -Path $ManifestPath } |
3138
Should -Not -Throw
3239
}
3340

3441
It 'has expected module version' {
35-
$m = Test-ModuleManifest -Path $script:ManifestPath
36-
# Keep this pattern in sync with your release scheme
42+
$m = Test-ModuleManifest -Path $ManifestPath
43+
# Adjust regex if you bump major/minor later
3744
$m.Version.ToString() | Should -Match '^1\.0\.\d+$'
3845
}
3946
}
4047

41-
# --------------- Export tests ---------------
48+
# ---------------- Export tests ----------------
4249

4350
Describe 'OffsetInspect module exports' {
4451

4552
BeforeAll {
46-
$script:ModuleInfo = Import-Module $script:ManifestPath -Force -PassThru
53+
$ManifestPath = Get-OffsetInspectManifestPath -TestsRoot $PSScriptRoot
54+
Write-Host "Using manifest (exports describe): $ManifestPath"
55+
56+
# Import the module; throws if anything is wrong with manifest/module
57+
$ModuleInfo = Import-Module $ManifestPath -Force -PassThru
4758
}
4859

4960
It 'imports without error' {
50-
{ Import-Module $script:ManifestPath -Force } |
61+
{ Import-Module $ManifestPath -Force } |
5162
Should -Not -Throw
5263
}
5364

5465
It 'exports Invoke-OffsetInspect' {
55-
$cmd = Get-Command Invoke-OffsetInspect -Module $script:ModuleInfo.Name -ErrorAction Stop
66+
$cmd = Get-Command Invoke-OffsetInspect -Module $ModuleInfo.Name -ErrorAction Stop
5667
$cmd | Should -Not -BeNullOrEmpty
5768
}
5869

59-
It 'exposes FilePaths and OffsetInputs as string[] parameters' {
60-
$cmd = Get-Command Invoke-OffsetInspect -Module $script:ModuleInfo.Name -ErrorAction Stop
70+
It 'FilePaths and OffsetInputs are string[] parameters' {
71+
$cmd = Get-Command Invoke-OffsetInspect -Module $ModuleInfo.Name -ErrorAction Stop
6172

62-
$cmd.Parameters['FilePaths'].ParameterType | Should -Be ([string[]])
63-
$cmd.Parameters['OffsetInputs'].ParameterType | Should -Be ([string[]])
73+
$cmd.Parameters['FilePaths'].ParameterType | Should -Be ([string[]])
74+
$cmd.Parameters['OffsetInputs'].ParameterType | Should -Be ([string[]])
6475
}
6576
}

0 commit comments

Comments
 (0)