Search code examples
powershellsublimetextsublimetext3powershell-3.0pester

Efficient way to run PowerShell Pester tests from Sublime Text


I'm using Sublime Text (ST) to create my PowerShell scripts, Pester to test them.

To run test script, one must to switch to that tab, then press CTRL + B. This process must be repeated for each test script.

Is there an easy way to Sublime Text to run all of the tests in the project's directory?

Is there a way to have these test automatically run when a script or test changes (similar to guard)?


Solution

  • I added a script named Tests.ps1 to the project's directory with a single instruction:

    Invoke-Pester
    

    To run all tests, I open this file and press Ctrl+B.

    ** edit **

    Created a new build system named 'Pester'. The contents of Pester.sublimebuild:

    {
        "cmd": ["powershell.exe", "-noprofile", "Invoke-Pester"],
        "selector": "source.powershell"
    }
    

    To run all tests, press Ctrl+B.

    If this doesn't work automatically, assign Pester as the build system using Tools | Build System | Pester and try again.