pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.11k stars 473 forks source link

Detailed Output vs Test Report - Skipped #2220

Closed Splaxi closed 2 years ago

Splaxi commented 2 years ago

Checklist

What is the issue?

It seems that the logic with expanding the path of a given test, is being handled differently when we are talking about the detailed output and the output object.

BeforeDiscovery {
    $colLogicApps = @(
        @{ Name = "1" }
        @{ Name = "2" }
        @{ Name = "3" }
        @{ Name = "4" }
    )
}

Describe "Execute <name>" -ForEach $colLogicApps {
    BeforeEach {
        if ($Name -eq "3") {
            Set-ItResult -Skipped -Because "Just because"
        }
    }

    It " Skip when 2" {
        if ($Name -eq "2") {
            Set-ItResult -Skipped -Because "Just because"
        }

        1 + 1 | Should -be 2
    }
}

The detailed output expands the path of each test / describe:

image

But the output object looks like this:

$temp = Invoke-Pester -Path "..." -Output Detailed -PassThru
$temp.tests | ft Name, Path, ExpandedPath
image

Expected Behavior

I would expect the expanded path to work the same way as the detailed output, so when you are generating NUnit/JUnit files, the would reflect the same values.

Steps To Reproduce

No response

Describe your environment

No response

Possible Solution?

No response

fflaten commented 2 years ago

Thanks for the report. ExpandedName and ExpandedPath are evaluated after the setups because they could create variables used in the name iirc. So skipping inside BeforeEach vs It will be different since the latter will already be finished with setups -> name is expanded.

We could however update the placeholder-value for ExpandedPath that you see now to be expanded as far as we reached before skip/failure. That would solve the sample in this issue where only the block has a variable + make it easier to identify the correct block in general. šŸ‘

Splaxi commented 2 years ago

Thanks for the feedback.

Is there any way I can assist with this, so we can have the change to be part of the next release? I'm new to the code base of pester, but I'm up for the challenge to see if I can fix it and do the PR.

Just need some pointers, then I can test local and see if my scenario can be handled or not.

fflaten commented 2 years ago

Absolutely, contributions are always welcome šŸ˜ƒ You can see how to build and test in CONTRIBUTING.md. I personally use the devcontainer in the repo so I don't need .NET locally.

As for the code:

fflaten commented 2 years ago

Still interested in submitting a PR @Splaxi? šŸ™‚

Splaxi commented 2 years ago

Yeah - but when I tried the last time, I couldn't find a way to solve the issue.

So I feel that I'm smart enough to tackle the challenge, regardless of me having the issue šŸ¤¦ā€ā™‚ļø

fflaten commented 2 years ago

Looking back at it months later - it wasn't my best explanation šŸ˜„ I think I've covered it in the related PR.