From 8d555269cfcd8e3aee13d1efb10f962afc922f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 14 Oct 2020 10:54:26 +0200 Subject: [PATCH] Default to expanded name and path (#1718) Fix #1715 --- src/Pester.Runtime.psm1 | 18 +++++++++++-- tst/Pester.RSpec.Nunit.TestResults.ts.ps1 | 31 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Pester.Runtime.psm1 b/src/Pester.Runtime.psm1 index 59bf6b6fc..3749a34a0 100644 --- a/src/Pester.Runtime.psm1 +++ b/src/Pester.Runtime.psm1 @@ -192,7 +192,14 @@ function New-Block { # new block $block = [Pester.Block]::Create() $block.Name = $Name + # using the non-expanded name as default to fallback to it if we don't + # reach the point where we expand it, for example because of setup failure + $block.ExpandedName = $Name + $block.Path = $Path + # using the non-expanded path as default to fallback to it if we don't + # reach the point where we expand it, for example because of setup failure + $block.ExpandedPath = $Path $block.Tag = $Tag $block.ScriptBlock = $ScriptBlock $block.StartLine = $StartLine @@ -465,7 +472,13 @@ function New-Test { $test.Id = $Id $test.ScriptBlock = $ScriptBlock $test.Name = $Name + # using the non-expanded name as default to fallback to it if we don't + # reach the point where we expand it, for example because of setup failure + $test.ExpandedName = $Name $test.Path = $path + # using the non-expanded path as default to fallback to it if we don't + # reach the point where we expand it, for example because of setup failure + $test.ExpandedPath = $path $test.StartLine = $StartLine $test.Tag = $Tag $test.Focus = $Focus @@ -858,9 +871,10 @@ function Discover-Test { # OneTime* and Each* setups, and capture multiple blocks in a # container $root = [Pester.Block]::Create() - $root.Name = "Root" + $root.ExpandedName = $root.Name = "Root" + $root.IsRoot = $true - $root.Path = "Path" + $root.ExpandedPath = $root.Path = "Path" $root.First = $true $root.Last = $true diff --git a/tst/Pester.RSpec.Nunit.TestResults.ts.ps1 b/tst/Pester.RSpec.Nunit.TestResults.ts.ps1 index ba0dd311a..cbe86b22d 100644 --- a/tst/Pester.RSpec.Nunit.TestResults.ts.ps1 +++ b/tst/Pester.RSpec.Nunit.TestResults.ts.ps1 @@ -431,4 +431,35 @@ i -PassThru:$PassThru { $xmlSuites[0].'results'.'test-case'.'description' | Verify-Equal "Included test" } } + + b "When beforeall crashes tests are reported correctly" { + # https://github.com/pester/Pester/issues/1715 + t "test has name" { + $sb = { + Describe "Failing describe" { + BeforeAll { + throw + } + + It "Test1" { + $true | Should -Be $true + } + } + } + + $r = Invoke-Pester -Configuration ([PesterConfiguration]@{ + Run = @{ ScriptBlock = $sb; PassThru = $true }; + Output = @{ Verbosity = 'None' } + }) + + $xmlResult = $r | ConvertTo-NUnitReport + + $xmlSuites = @($xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-suite') + $xmlSuites.Count | Verify-Equal 1 + $xmlSuites[0].'description' | Verify-Equal "Failing describe" + $xmlSuites[0].'results'.'test-case'.'name' | Verify-Equal "Failing describe Test1" + $xmlSuites[0].'results'.'test-case'.'description' | Verify-Equal "Test1" + + } + } }