-
Notifications
You must be signed in to change notification settings - Fork 500
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
Failed Pester 5 tests are not shown in Problems #2931
Comments
Thanks for the update. Seems to be related to pester/Pester#1452 and pester/Pester#1577. Should still track the issue here I guess considering the problemmatcher is a feature of the extension. |
There was this PR #2447 where we talked about this, but I actually did not do anything. @fflaten if you want to implement this PRs are more than welcome. On Pester side you'd need to use the mentioned environment variables to detect if we are running in vscode to enable the appropriate output (if needed). I There already is an option on the configuration object but that one is ignored as described in pester/Pester#1577. |
Thanks @nohwnd for the update, on the vscode side looks like the change would happen here https://github.com/powershell/vscode-powershell/blob/master/package.json#L456-L474 I will go ahead and mark this issue as up for grabs |
@nohwnd I'll take a look when I get a chance.
Quote from: https://code.visualstudio.com/docs/editor/tasks-appendix Do the patterns need to match the line order perfectly when using the |
@fflaten IDK tagging @tillig who fixed the matcher in #2447 and @rkeithhill who I think wrote the original matcher for v4. Hope they can help. |
Something I noticed, which may or may not affect things here, is that Pester 5 doesn't issue any failure for exceptions occurring in Describe "Reproduce Issue" {
Context "Failing BeforeAll in Context block" {
BeforeAll {
$pathToCommand = Get-Command nosuchcommand.exe | Select-Object -ExpandProperty Source
&othermissingcommand $pathToCommand
}
}
It "has two failures - context and test" {
$False | Should -Be $True
}
} ...only the failure in the test is logged.
That affects, in part, the problem matcher because it was written to detect both context and individual test failures. |
Oh, nevermind, I see it's a 5.x update problem. BeforeAll can't be in Context anymore. |
I've messed around with it for a while and I think @fflaten comment here is on the nose:
The v4 failure output looked like:
The v5 failure output has reordered things:
I was able to get test failures to show up using a custom problem matcher in the tasks.json file: {
"linux": {
"options": {
"shell": {
"args": [
"-NoProfile",
"-Command"
],
"executable": "/usr/bin/pwsh"
}
}
},
"osx": {
"options": {
"shell": {
"args": [
"-NoProfile",
"-Command"
],
"executable": "/usr/local/microsoft/powershell/7/pwsh"
}
}
},
"tasks": [
{
"command": "Invoke-Pester",
"group": {
"isDefault": true,
"kind": "test"
},
"label": "test",
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": {
"fileLocation": "absolute",
"owner": "powershell",
"pattern": [
{
"message": 1,
"regexp": "^\\s*\\[-\\]\\s+(.+)$"
},
{
"regexp": ".*"
},
{
"file": 2,
"line": 3,
"regexp": "^\\s*[Aa]t\\s+([^,]+,\\s*)?(.+?):(\\d+)$"
}
],
"severity": "error"
},
"type": "shell"
}
],
"version": "2.0.0",
"windows": {
"options": {
"shell": {
"args": [
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-Command"
],
"executable": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
}
}
}
} Note that there's an extra The problem is, this doesn't work if the problem has a multi-line message. For example, if I have a failure in the BeforeAll, it looks like this:
Note that's two lines between the message and the location. I didn't see a way to say "eat a bunch of lines until it matches the location expression." I did try using the {
"regexp": "^(?!\\s*[Aa]t\\s+).*$",
"loop": true
} so instead of matching It'd be easiest if the Pester output would be formatted like
Sort of how it was in v4. I mean, better still would be if there was an all-on-one-line machine parsable output format that also looked OK in a console, like a build error.
Where the message, path, line, and character are there, all nice and regex-able. But, barring that... it seems like Pester 5 would need a new matcher specific to this new format, it'd need to know how to "eat" the extra error message line, and I don't think you'd be able to show context/BeforeAll sorts of failures anymore because the arbitrary lines in between message and location can't be dealt with properly. |
And now you know why back in the v3 days, @dlwyatt and I worked out a Pester configuration option to output specifically for VSCode so I could make the problem matcher regex work. Really though, Pester should adopt an output format that is stable & easy for problem matchers like this e.g:
|
It can, it's just that your BeforeAll is in Context that has no It, so BeforeAll won't run because it would not setup any test. |
Issue Description
When using Pester 5.0.3 to execute a test task, the failed tests are not shown in Problems-view like they used to do with Pester 3.4. This seems to be caused by the new output-format in Pester 5 which doesn't fit with the
$pester
-problemMatcher regex.Replacing the current matcher
^\s*(?:\[-\]\s+)(.*?)(?:\s+\d+\.?\d*\s*m?s)\s*$
with^\s*(?:\[-\]\s+)(.*?)(?:\s+\d+\.?\d*\s*m?s)(?:\s+\(.*?\))?\s*$
in a regex online tester seems to detect both Pester 3.4 and Pester 5 output, but I had problems making it work by editing directly in package.json (remember to escape\
), so might need something more.Proof-of-concept(Click to Expand)
demo.tests.ps1
tasks.json
Output Pester 3.4 (shown in Problems-tab):
Output Pester 5.0.3 (not shown in Problems-tab):
Attached Logs
Follow the instructions in the README about
capturing and sending logs.
Environment Information
Visual Studio Code
PowerShell Information
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)
The text was updated successfully, but these errors were encountered: