Skip to content

Commit f1d93ae

Browse files
author
Friedrich Weinmann
committed
NUnit Result Reporting added
1 parent 1fce0e0 commit f1d93ae

File tree

7 files changed

+39
-6
lines changed

7 files changed

+39
-6
lines changed

templates/PSFModule/PSMDTemplate.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,13 @@
1919
psframework = {
2020
(Get-Module PSFramework).Version.ToString()
2121
}
22+
testfolder = {
23+
24+
}
25+
testresults = {
26+
@'
27+
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
28+
'@
29+
}
2230
}
2331
}

templates/PSFModule/þnameþ.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function Import-ModuleFile
2727
$Path
2828
)
2929

30-
if ($doDotSource) { . $Path }
31-
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null) }
30+
if ($doDotSource) { . (Resolve-Path $Path) }
31+
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText((Resolve-Path $Path)))), $null, $null) }
3232
}
3333

3434
# Detect whether at some level dotsourcing was enforced

templates/PSFProject/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ library/þnameþ/þnameþ/obj/*
1414
þnameþ/þnameþ.psproj.bak
1515
þnameþ/þnameþ.psprojs
1616
þnameþ/þnameþ.psproj
17+
18+
# ignore the TestResults
19+
TestResults/*

templates/PSFProject/PSMDTemplate.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,17 @@
2828
psframework = {
2929
(Get-Module PSFramework).Version.ToString()
3030
}
31+
testfolder = {
32+
@'
33+
Write-PSFMessage -Level Important -Message "Creating test result folder"
34+
$null = New-Item -Path "$PSScriptRoot\..\.." -Name TestResults -ItemType Directory -Force
35+
'@
36+
}
37+
testresults = {
38+
@'
39+
$TestOuputFile = Join-Path "$PSScriptRoot\..\..\TestResults" "TEST-$($file.BaseName).xml"
40+
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru -OutputFile $TestOuputFile -OutputFormat NUnitXml
41+
'@
42+
}
3143
}
3244
}

templates/PSFTests/PSMDTemplate.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@
1010
guid = {
1111
[System.Guid]::NewGuid().ToString()
1212
}
13+
testfolder = {
14+
15+
}
16+
testresults = {
17+
@'
18+
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
19+
'@
20+
}
1321
} # Insert additional scriptblocks as needed. Each scriptblock will be executed once only on create, no matter how often it is referenced.
1422
}

templates/PSFTests/pester.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Remove-Module þnameþ -ErrorAction Ignore
1919
Import-Module "$PSScriptRoot\..\þnameþ.psd1"
2020
Import-Module "$PSScriptRoot\..\þnameþ.psm1" -Force
2121

22+
þ!testfolder!þ
23+
2224
$totalFailed = 0
2325
$totalRun = 0
2426

@@ -29,7 +31,7 @@ Write-PSFMessage -Level Important -Message "Modules imported, proceeding with ge
2931
foreach ($file in (Get-ChildItem "$PSScriptRoot\general" -Filter "*.Tests.ps1"))
3032
{
3133
Write-PSFMessage -Level Significant -Message " Executing <c='em'>$($file.Name)</c>"
32-
$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
34+
þ!testresults!þ
3335
foreach ($result in $results)
3436
{
3537
$totalRun += $result.TotalCount
@@ -56,7 +58,7 @@ foreach ($file in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -File -Filte
5658
if ($file.Name -like $Exclude) { continue }
5759

5860
Write-PSFMessage -Level Significant -Message " Executing $($file.Name)"
59-
$results = Invoke-Pester -Script $file.FullName -Show None -PassThru
61+
þ!testresults!þ
6062
foreach ($result in $results)
6163
{
6264
$totalRun += $result.TotalCount

templates/module/þnameþ.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function Import-ModuleFile
2727
$Path
2828
)
2929

30-
if ($script:dontDotSource) { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null) }
31-
else { . $Path }
30+
if ($script:dontDotSource) { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText((Resolve-Path $Path)))), $null, $null) }
31+
else { . (Resolve-Path $Path) }
3232
}
3333
#endregion Helper function
3434

0 commit comments

Comments
 (0)