Skip to content

Commit fd1c35a

Browse files
author
James Brundage
committed
fix: Start-Htmx ( Fixes #7 )
Registering for PowerShellExiting event and simplifying test
1 parent a477298 commit fd1c35a

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

Commands/Start-Htmx.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ function Start-Htmx {
477477
)
478478
}
479479

480+
$null = Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action {
481+
Get-Job | ? HttpListener | Stop-Htmx
482+
}
480483
while ($serverJob.JobStateInfo.State -eq 'NotStarted') {
481484
Start-Sleep -Milliseconds (Get-Random -Maximum 20 -Minimum 1)
482485
}

HtmxPS.tests.ps1

+6-15
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,12 @@ describe HtmxPS {
1212
}
1313

1414
context 'Start-Htmx and Stop-Htmx' {
15-
it "Will start and stop a small htmx server" {
16-
if (-not $env:GITHUB_WORKSPACE) {
17-
$startedLocalJob = Start-Htmx -Htmx (
18-
htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')"
19-
)
20-
Invoke-RestMethod -Uri $startedLocalJob.ServerUrl
21-
$startedLocalJob | Stop-Htmx -PassThru | Remove-Job
22-
} else {
23-
$startedLocalJob = Start-Htmx -Htmx (
24-
htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')"
25-
) -ServerUrl "http://127.0.0.1:8080/"
26-
# Start-Sleep -Seconds 1
27-
Invoke-RestMethod -Uri $startedLocalJob.ServerUrl
28-
$startedLocalJob | Stop-Htmx -PassThru | Remove-Job
29-
}
15+
it "Will start and stop a small htmx server" {
16+
$startedLocalJob = Start-Htmx -Htmx (
17+
htmx button "Click Me" hx-on:click="alert('Thanks, I needed that!')"
18+
)
19+
Invoke-RestMethod -Uri $startedLocalJob.ServerUrl
20+
$startedLocalJob | Stop-Htmx -PassThru | Remove-Job
3021
}
3122
}
3223
}

0 commit comments

Comments
 (0)