Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Detailed Output vs Test Report - Skipped

Open Splaxi opened this issue 2 years ago • 3 comments

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

Splaxi avatar Jul 21 '22 07:07 Splaxi

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. 👍

fflaten avatar Jul 22 '22 09:07 fflaten

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.

Splaxi avatar Jul 22 '22 12:07 Splaxi

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:

  • Test (It) You can see how ExpandedPath is set here. I'm thinking we could set it once more earlier in Invoke-TestItem before the skip-check and/or framework-setup. $Test should be the same as CurrentTest at that point.

  • Block (Describe/Context) Current logic is here. ExpandedPath could be set the same way probably around L321.

  • We should also add a test or two similar to this to verify that it works when a) a block fails due to BeforeAll, b) a test with -Skip or that fails (or Set-ItResult which is a special exception) in BeforeEach. These are P-test which are used to test behavior of Pester-engine itself from the outside. b is like describe/context, i is like it and we can only use the Verify-* assertions found in the tst\axiom-folder.

fflaten avatar Jul 22 '22 19:07 fflaten

Still interested in submitting a PR @Splaxi? 🙂

fflaten avatar Oct 31 '22 11:10 fflaten

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 🤦‍♂️

Splaxi avatar Oct 31 '22 13:10 Splaxi

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

fflaten avatar Nov 01 '22 20:11 fflaten