diff --git a/Commands/Start-Htmx.ps1 b/Commands/Start-Htmx.ps1 index 96cebda..825c7f6 100644 --- a/Commands/Start-Htmx.ps1 +++ b/Commands/Start-Htmx.ps1 @@ -477,6 +477,9 @@ function Start-Htmx { ) } + $null = Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action { + Get-Job | ? HttpListener | Stop-Htmx + } while ($serverJob.JobStateInfo.State -eq 'NotStarted') { Start-Sleep -Milliseconds (Get-Random -Maximum 20 -Minimum 1) } diff --git a/HtmxPS.tests.ps1 b/HtmxPS.tests.ps1 index 7260480..6b6852f 100644 --- a/HtmxPS.tests.ps1 +++ b/HtmxPS.tests.ps1 @@ -12,21 +12,12 @@ describe HtmxPS { } context 'Start-Htmx and Stop-Htmx' { - it "Will start and stop a small htmx server" { - if (-not $env:GITHUB_WORKSPACE) { - $startedLocalJob = Start-Htmx -Htmx ( - htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')" - ) - Invoke-RestMethod -Uri $startedLocalJob.ServerUrl - $startedLocalJob | Stop-Htmx -PassThru | Remove-Job - } else { - $startedLocalJob = Start-Htmx -Htmx ( - htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')" - ) -ServerUrl "http://127.0.0.1:8080/" - # Start-Sleep -Seconds 1 - Invoke-RestMethod -Uri $startedLocalJob.ServerUrl - $startedLocalJob | Stop-Htmx -PassThru | Remove-Job - } + it "Will start and stop a small htmx server" { + $startedLocalJob = Start-Htmx -Htmx ( + htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')" + ) + Invoke-RestMethod -Uri $startedLocalJob.ServerUrl + $startedLocalJob | Stop-Htmx -PassThru | Remove-Job } } }