Last active
October 29, 2021 12:39
-
-
Save nohwnd/efc339339dc328d93e0fe000249aea25 to your computer and use it in GitHub Desktop.
Use Pester code coverage with CoverageGutters in VSCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put into directory .vscode and remove this comment | |
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Run tests in current file with CC", | |
"type": "PowerShell", | |
"request": "launch", | |
"script": "${workspaceFolder}/test.ps1", | |
"args": [ | |
"-Path", "'${file}'", | |
"-Output", "${config:powershell.pester.debugOutputVerbosity}", | |
"-CodeCoverage", | |
], | |
"cwd": "${file}", | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put into directory .vscode and remove this comment | |
{ | |
// disable gutters to make breakpoints usable | |
"coverage-gutters.showGutterCoverage": false, | |
"coverage-gutters.showLineCoverage": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[String] $Path = ".", | |
[String] $Output = "Detailed", | |
[Switch] $CodeCoverage | |
) | |
Import-Module Pester -MinimumVersion 5.2.0 | |
$Configuration = [PesterConfiguration]::Default | |
$Configuration.Run.Path = $Path | |
$Configuration.Output.Verbosity = $Output | |
$Configuration.CodeCoverage.Enabled = [bool] $CodeCoverage | |
# CoverageGutters is new option in Pester 5.2 | |
$Configuration.CodeCoverage.OutputFormat = "CoverageGutters" | |
$Configuration.CodeCoverage.Path = "$PSScriptRoot/src" | |
$Configuration.CodeCoverage.OutputPath = "$PSScriptRoot/coverage.xml" | |
$Configuration.CodeCoverage.CoveragePercentTarget = 90 | |
$Configuration.Debug.WriteDebugMessages = $true | |
$Configuration.Debug.WriteDebugMessagesFrom = "CodeCoverage" | |
# for convenience just run the passed file when we invoke this via launchConfig.json when | |
# the file is a non-test file | |
$isDirectory = (Get-Item $Path).PSIsContainer | |
$isTestFile = $Path.EndsWith($Configuration.Run.TestExtension.Value) | |
if (-not $isDirectory -and -not $isTestFile) { | |
& $Path | |
return | |
} | |
Invoke-Pester -Configuration $Configuration |
@davidwallis3101 how about -like ("*" + $Configuration.Run.TestExtension.Value)
?
Will prob work better as I see an odd issue where I end up with $path being a path as a string, and then times an object with a path with a property and then EndsWith isn't a valid method when its a null value. I just haven't quite got to the bottom of it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can I suggest that line 29 changes to: