Skip to content

Commit 6b792bf

Browse files
committed
Fix Get-ServiceStatus and Start-DevServer CI failures
Child process tests now use pwsh instead of powershell (5.1 unavailable on CI runners). Create config.json from example before tests that spawn subprocesses to prevent Get-ScriptConfig Read-Host prompt from corrupting output. Skip startup update check in non-interactive sessions.
1 parent 2860a44 commit 6b792bf

3 files changed

Lines changed: 37 additions & 7 deletions

File tree

PowerShellDevToolkit/PowerShellDevToolkit.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ function global:la { Get-DirectoryListing -Force @args }
6060
function global:o. { Open-Item . }
6161

6262
# Startup update check (runs once per configured interval, silent on error)
63-
try { Test-ToolkitUpdate } catch { }
63+
if ([Environment]::UserInteractive) { try { Test-ToolkitUpdate } catch { } }

tests/Get-ServiceStatus.Tests.ps1

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@ BeforeAll {
22
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSCommandPath)
33
$moduleDir = Join-Path $repoRoot "PowerShellDevToolkit"
44
Import-Module $moduleDir -Force
5+
6+
$configPath = Join-Path $repoRoot "config.json"
7+
$examplePath = Join-Path $repoRoot "config.example.json"
8+
$script:hadConfig = Test-Path $configPath
9+
if (-not $script:hadConfig -and (Test-Path $examplePath)) {
10+
Copy-Item $examplePath $configPath
11+
$script:createdConfig = $true
12+
}
13+
}
14+
15+
AfterAll {
16+
if ($script:createdConfig) {
17+
$configPath = Join-Path $repoRoot "config.json"
18+
Remove-Item $configPath -ErrorAction SilentlyContinue
19+
}
520
}
621

722
Describe "Get-ServiceStatus" {
823
It "Should return JSON array with expected fields for git" {
9-
$raw = powershell -NoProfile -ExecutionPolicy Bypass -Command "Import-Module '$moduleDir' -Force; Get-ServiceStatus git -AsJson"
24+
$raw = pwsh -NoProfile -Command "Import-Module '$moduleDir' -Force -DisableNameChecking; Get-ServiceStatus git -AsJson"
1025
$result = $raw | ConvertFrom-Json
1126
($result | Measure-Object).Count | Should -BeGreaterThan 0
1227
$first = $result[0]
@@ -16,22 +31,22 @@ Describe "Get-ServiceStatus" {
1631
}
1732

1833
It "Should report git as available" {
19-
$raw = powershell -NoProfile -ExecutionPolicy Bypass -Command "Import-Module '$moduleDir' -Force; Get-ServiceStatus git -AsJson"
34+
$raw = pwsh -NoProfile -Command "Import-Module '$moduleDir' -Force -DisableNameChecking; Get-ServiceStatus git -AsJson"
2035
$result = $raw | ConvertFrom-Json
2136
$git = $result | Where-Object { $_.id -eq 'git' }
2237
$git | Should -Not -BeNullOrEmpty
2338
$git.status | Should -Be 'running'
2439
}
2540

2641
It "Should handle unknown service name" {
27-
$raw = powershell -NoProfile -ExecutionPolicy Bypass -Command "Import-Module '$moduleDir' -Force; Get-ServiceStatus nonexistent_xyz -AsJson"
42+
$raw = pwsh -NoProfile -Command "Import-Module '$moduleDir' -Force -DisableNameChecking; Get-ServiceStatus nonexistent_xyz -AsJson"
2843
$result = $raw | ConvertFrom-Json
2944
$svc = $result | Where-Object { $_.id -eq 'nonexistent_xyz' }
3045
$svc.status | Should -Be 'unknown'
3146
}
3247

3348
It "Should filter to only requested services" {
34-
$raw = powershell -NoProfile -ExecutionPolicy Bypass -Command "Import-Module '$moduleDir' -Force; Get-ServiceStatus git node -AsJson"
49+
$raw = pwsh -NoProfile -Command "Import-Module '$moduleDir' -Force -DisableNameChecking; Get-ServiceStatus git node -AsJson"
3550
$result = $raw | ConvertFrom-Json
3651
($result | Measure-Object).Count | Should -Be 2
3752
$ids = $result | ForEach-Object { $_.id }

tests/Start-DevServer.Tests.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@ BeforeAll {
22
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSCommandPath)
33
$moduleDir = Join-Path $repoRoot "PowerShellDevToolkit"
44
Import-Module $moduleDir -Force
5+
6+
$configPath = Join-Path $repoRoot "config.json"
7+
$examplePath = Join-Path $repoRoot "config.example.json"
8+
$script:hadConfig = Test-Path $configPath
9+
if (-not $script:hadConfig -and (Test-Path $examplePath)) {
10+
Copy-Item $examplePath $configPath
11+
$script:createdConfig = $true
12+
}
13+
}
14+
15+
AfterAll {
16+
if ($script:createdConfig) {
17+
$configPath = Join-Path $repoRoot "config.json"
18+
Remove-Item $configPath -ErrorAction SilentlyContinue
19+
}
520
}
621

722
Describe "Start-DevServer" {
823
It "Should show error when project type cannot be detected" {
924
$dir = Join-Path $env:TEMP "pester-serve-empty-$(Get-Random)"
1025
New-Item -Path $dir -ItemType Directory -Force | Out-Null
1126
try {
12-
$output = powershell -NoProfile -ExecutionPolicy Bypass -Command "Import-Module '$moduleDir' -Force; Set-Location '$dir'; Start-DevServer 2>&1" | Out-String
27+
$output = pwsh -NoProfile -Command "Import-Module '$moduleDir' -Force -DisableNameChecking; Set-Location '$dir'; Start-DevServer 2>&1" | Out-String
1328
($output -match 'Could not detect') | Should -Be $true
1429
} finally {
1530
Remove-Item $dir -Recurse -Force -ErrorAction SilentlyContinue
@@ -21,7 +36,7 @@ Describe "Start-DevServer" {
2136
New-Item -Path $dir -ItemType Directory -Force | Out-Null
2237
try {
2338
@{ scripts = @{ dev = "echo test" } } | ConvertTo-Json | Set-Content "$dir\package.json"
24-
$output = powershell -NoProfile -ExecutionPolicy Bypass -Command "Import-Module '$moduleDir' -Force; Set-Location '$dir'; Start-DevServer 2>&1" | Out-String
39+
$output = pwsh -NoProfile -Command "Import-Module '$moduleDir' -Force -DisableNameChecking; Set-Location '$dir'; Start-DevServer 2>&1" | Out-String
2540
($output -match 'node') | Should -Be $true
2641
} finally {
2742
Remove-Item $dir -Recurse -Force -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)