Skip to content

Commit

Permalink
fix: Start-Htmx ( Fixes #7 )
Browse files Browse the repository at this point in the history
Registering for PowerShellExiting event and simplifying test
  • Loading branch information
James Brundage committed Oct 25, 2024
1 parent a477298 commit fd1c35a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Commands/Start-Htmx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
21 changes: 6 additions & 15 deletions HtmxPS.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit fd1c35a

Please sign in to comment.