Skip to content

Commit

Permalink
Default to expanded name and path (#1718)
Browse files Browse the repository at this point in the history
Fix #1715
  • Loading branch information
nohwnd authored Oct 14, 2020
1 parent 7caabed commit 8d55526
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Pester.Runtime.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions tst/Pester.RSpec.Nunit.TestResults.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}
}
}

0 comments on commit 8d55526

Please sign in to comment.