Skip to content
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

Open
dfinke opened this issue Sep 14, 2016 · 11 comments
Open

Add -Watch switch #607

dfinke opened this issue Sep 14, 2016 · 11 comments
Labels
Milestone

Comments

@dfinke
Copy link

dfinke commented Sep 14, 2016

This would enable the watching of file & directory trees, and enable continuous testing at the console.

@dlwyatt
Copy link
Member

dlwyatt commented Sep 14, 2016

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?

@dfinke
Copy link
Author

dfinke commented Sep 14, 2016

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

@dlwyatt
Copy link
Member

dlwyatt commented Sep 14, 2016

Have you tried https://github.com/smurawski/PowerShellGuard ? Same idea, just a separate module.

@dfinke
Copy link
Author

dfinke commented Sep 14, 2016

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 -Watch. Guess I'm spoiled from npm

@codialsoftware
Copy link

If I could vote this up 1000 times...

@nohwnd nohwnd added this to the v4.1 milestone Aug 18, 2017
@it-praktyk it-praktyk modified the milestones: v4.1, 4.2 Nov 11, 2017
@GoEddie
Copy link

GoEddie commented Nov 14, 2017

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)

@nohwnd
Copy link
Member

nohwnd commented Nov 15, 2017

@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.

@nohwnd nohwnd removed this from the 4.3 milestone May 6, 2018
@nohwnd nohwnd added this to the New runtime milestone Dec 16, 2018
@nohwnd
Copy link
Member

nohwnd commented Mar 31, 2019

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.

@nohwnd nohwnd modified the milestones: 5.0, 5.x Mar 31, 2019
@fflaten
Copy link
Collaborator

fflaten commented Jun 1, 2022

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. 🙂

@dkaszews
Copy link

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 -Output Detailed I try to use with -TestCommand. The latter has the same issue and does not support passing arbitrary arguments either, complaining about Pester 4 deprecated options.

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.

@dkaszews
Copy link

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants