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

Show Pester CodeCoverage data as green/red lines of source text #495

Open
rkeithhill opened this Issue Feb 9, 2017 · 1 comment

Comments

Projects
None yet
4 participants
@rkeithhill
Copy link
Collaborator

rkeithhill commented Feb 9, 2017

When you run Pester with -CodeCoverage it will give you a percentage of code coverage but it also gives you every line that is not covered:

File                Function                       Line Command
----                --------                       ---- -------
CheckVersion.ps1                                      4 Write-Warning "git command could not be found. Please create...
CheckVersion.ps1                                      5 $Global:GitMissing = $true
CheckVersion.ps1                                     14 Write-Warning "posh-git requires Git $requiredVersion or bet...
CheckVersion.ps1                                     15 $false
GitPrompt.ps1                                       120 $isAdminProcess = 0 -eq (id -u)
GitPrompt.ps1                                       120 id -u
GitPrompt.ps1                                       123 'Administrator: '
GitPrompt.ps1                                       127 $WindowTitleSupported = $false
GitPrompt.ps1       Write-Prompt                    132 Write-Host $Object -NoNewLine -ForegroundColor $ForegroundColor

It would be cool if we could use this data to color script text red/green (covered/not covered) like Visual Studio does.

@daviwil daviwil added this to the Backlog milestone Feb 9, 2017

@gerane

This comment has been minimized.

Copy link

gerane commented Mar 17, 2017

I would love to see this. A red\green icon in the gutter or other decorators would be a nice option as well so it doesn't conflict with other errors. I have been playing with this background task that lights up CodeCoverage, but after looking at other Code Coverage extensions, it seems like a background problem matcher task might not be the best option in the long term. Though, if you just wanted code coverage and not also failed test matches, you could delete the problem matcher for the tests and get just code coverage.

Here are a few example extensions I glanced at. I really like some of what the Wallaby.js extension does.

https://marketplace.visualstudio.com/items?itemName=WallabyJs.wallaby-vscode
https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
https://marketplace.visualstudio.com/items?itemName=alexdima.vscode-lcov
https://marketplace.visualstudio.com/items?itemName=brunomartens.bma-coverage

Here is an example background task Task runner that matches for code coverage and failed tests.

problemmatchercc

{
    "version": "0.1.0",
    "windows": {
        "command": "${env.windir}\\sysnative\\windowspowershell\\v1.0\\PowerShell.exe"
    },
    "linux": {
        "command": "/usr/bin/powershell"
    },
    "osx": {
        "command": "/usr/local/bin/powershell"
    },
    "isShellCommand": true,
    "showOutput": "always",
    "args": [
        "-NoProfile", "-ExecutionPolicy", "Bypass"
    ],
    "tasks": [
        {
            "taskName": "Watch.Project",
            "isTestCommand": true,
            "suppressTaskName": true,
            "args": [
                "Write-Host 'Watching Project';",
                "Import-Module -Name Pester -RequiredVersion 3.4.3 -Force;",
                "Import-Module -Name PowerShellGuard;",
                "New-Guard -Path \"${workspaceRoot}\" -PathFilter \"*.ps1\" -MonitorSubdirectories -TestPath \"${workspaceRoot}\\Tests\" -TestCommand {Write-Host \"Invoking Watch.Project\"; Invoke-Pester -CodeCoverage (gci \"${workspaceRoot}\\${workspaceRootFolderName}\\*.ps1\" -recurse) -PesterOption @{IncludeVSCodeMarker=$true}; Write-Host \"Finished Watch.Project\"} -Wait;"
            ],
            "isBackground": true,
            "problemMatcher": [
                {
                    "owner": "Watch.Project",
                    "fileLocation": "absolute",
                    "pattern": [
                        {
                            "regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
                            "message": 1
                        },
                        {
                            "regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$",
                            "file": 1,
                            "line": 2
                        }
                    ],
                    "watching": {
                        "activeOnStart": true,
                        "beginsPattern": "^Invoking Watch\\.Project$",
                        "endsPattern": "^Passed:\\s\\d+\\sFailed:\\s\\d+\\sSkipped:\\s\\d+\\sPending:\\s\\d+\\sInconclusive:\\s\\d+\\s$"
                    }
                },
                {
                    "owner": "Watch.Project.CodeCoverage",
                    "fileLocation": ["relative", "${workspaceRoot}\\${workspaceRootFolderName}"],
                    "pattern": [
                        {
                            "regexp": "^([Private|Public][\\s\\S]+\\.ps1).*\\s(\\d+)\\s(.*)$",
                            "message": 3,
                            "file": 1,
                            "line": 2
                        }
                    ],
                    "watching": {
                        "activeOnStart": true,
                        "beginsPattern": "^Invoking Watch\\.Project$",
                        "endsPattern": "^Finished Watch\\.Project.*$"
                    }
                }
            ]
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment