-
-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add -Watch
switch
#607
Comments
Hmm... how do you see this behaving with the various Output options? Separate parameter set that only writes to the console and nothing else? Run until you hit Control+C or something and then output to PassThru / file / etc? Constant output to file? |
I don't know ;-) I'm using vs code and have not taken the time to setup a Pester task. I make code changes, switch back to the console, up arrow and press enter. If I had a -watch, it'd be done |
Have you tried https://github.com/smurawski/PowerShellGuard ? Same idea, just a separate module. |
Yeah, I like things in one place. Figured it be nice feature. No additional dependencies or figuring out how to wire it up, just do a |
If I could vote this up 1000 times... |
I've written a module to support -Watch like we would have in javascript if anyone wants to use it feel free. I am going to shove in the gallery. https://github.com/GoEddie/PestWatch Invoke-PesterWatcher -WatchFolder . -PesterOptions etc (forwards all pester arguments onto pester) |
@GoEddie Thank you for your contribution. There are other projects that do the same or similar thing, but it does not hurt to have another one. If you want you can add your project to our list of projects connected to Pester. |
Moving this to 5.x, as mentioned here it is not as practical as it might seem so I'd like to do a bit more testing and thinking. |
The Pester Tests VSCode extension has a auto run on save feature. Won't close this issue as it's editor specific, but it may help some of you. 🙂 |
I have tried both https://github.com/smurawski/PowerShellGuard and https://github.com/GoEddie/PestWatch and neither works too well. The former is quite glithy, rerunning tests multiple times on every save, and ignoring the I think that is the issue with delegating what many consider core functionality to other projects - it requires their maintainers to keep up, while neither has been updated in over 5 years. |
I ended up using the following script, it should be relatively easy to integrate into Pester: $Jobs = @()
$Watcher = New-Object 'System.IO.FileSystemWatcher' -Property @{
Path = Resolve-Path $PSScriptRoot
Filter = '*.*'
IncludeSubdirectories = $true
EnableRaisingEvents = $true
NotifyFilter = 'FileName'
}
$global:_WatchTestsDebounce = [DateTime]::UnixEpoch
$Action = {
# Using script-scope just hangs the script
$Elapsed = ([DateTime]::Now - $global:_WatchTestsDebounce).Seconds
if ($Elapsed -gt 3) {
Clear-Host
Invoke-Pester -Output Detailed | Out-Default
$global:_WatchTestsDebounce = [DateTime]::Now
} else {
Write-Warning "Ignoring debounced event: ${Elapsed}"
}
}
try {
$Jobs += Register-ObjectEvent $Watcher 'Created' -Action $Action
$Jobs += Register-ObjectEvent $Watcher 'Changed' -Action $Action
& $Action
while ($true) {
Wait-Event -Timeout 60
}
} finally {
$Jobs | Remove-Job -Force
} |
This would enable the watching of file & directory trees, and enable continuous testing at the console.
The text was updated successfully, but these errors were encountered: