@@ -20,18 +20,9 @@ LogGroup 'Init - Get test kit versions' {
2020
2121LogGroup ' Init - Load inputs' {
2222 $path = [string ]::IsNullOrEmpty($env: PSMODULE_INVOKE_PESTER_INPUT_Path ) ? ' .' : $env: PSMODULE_INVOKE_PESTER_INPUT_Path
23- $providedItem = Resolve-Path - Path $path | Select-Object - ExpandProperty Path | Get-Item
24- if ($providedItem -is [System.IO.DirectoryInfo ]) {
25- $providedPath = $providedItem.FullName
26- } elseif ($providedItem -is [System.IO.FileInfo ]) {
27- $providedPath = $providedItem.Directory.FullName
28- } else {
29- Write-GitHubError " ❌ Provided path [$providedItem ] is not a valid directory or file."
30- exit 1
31- }
3223
3324 $inputs = @ {
34- Path = $providedPath
25+ Path = $path
3526
3627 Run_Path = $env: PSMODULE_INVOKE_PESTER_INPUT_Run_Path
3728 Run_ExcludePath = $env: PSMODULE_INVOKE_PESTER_INPUT_Run_ExcludePath
@@ -104,9 +95,9 @@ LogGroup 'Init - Load configuration - Action overrides' {
10495 ScriptBlock = $inputs.Run_ScriptBlock
10596 Container = $inputs.Run_Container
10697 TestExtension = $inputs.Run_TestExtension
107- Exit = $inputs.Run_Exit
108- Throw = $inputs.Run_Throw
109- SkipRun = $inputs.Run_SkipRun
98+ Exit = $null -ne $ inputs.Run_Exit ? $inputs .Run_Exit -eq ' true ' : $null
99+ Throw = $null -ne $ inputs.Run_Throw ? $inputs .Run_Throw -eq ' true ' : $null
100+ SkipRun = $null -ne $ inputs.Run_SkipRun ? $inputs .Run_SkipRun -eq ' true ' : $null
110101 SkipRemainingOnFailure = $inputs.Run_SkipRemainingOnFailure
111102 }
112103 Filter = @ {
@@ -117,19 +108,19 @@ LogGroup 'Init - Load configuration - Action overrides' {
117108 FullName = $inputs.Filter_FullName
118109 }
119110 CodeCoverage = @ {
120- Enabled = $inputs.CodeCoverage_Enabled
111+ Enabled = $null -ne $ inputs.CodeCoverage_Enabled ? $inputs .CodeCoverage_Enabled -eq ' true ' : $null
121112 OutputFormat = $inputs.CodeCoverage_OutputFormat
122113 OutputPath = $inputs.CodeCoverage_OutputPath
123114 OutputEncoding = $inputs.CodeCoverage_OutputEncoding
124115 Path = $inputs.CodeCoverage_Path
125- ExcludeTests = $inputs.CodeCoverage_ExcludeTests
126- RecursePaths = $inputs.CodeCoverage_RecursePaths
127- CoveragePercentTarget = $inputs.CodeCoverage_CoveragePercentTarget
128- UseBreakpoints = $inputs.CodeCoverage_UseBreakpoints
129- SingleHitBreakpoints = $inputs.CodeCoverage_SingleHitBreakpoints
116+ ExcludeTests = $null -ne $ inputs.CodeCoverage_ExcludeTests ? $inputs .CodeCoverage_ExcludeTests -eq ' true ' : $null
117+ RecursePaths = $null -ne $ inputs.CodeCoverage_RecursePaths ? $inputs .CodeCoverage_RecursePaths -eq ' true ' : $null
118+ CoveragePercentTarget = [ decimal ] $inputs.CodeCoverage_CoveragePercentTarget
119+ UseBreakpoints = $null -ne $ inputs.CodeCoverage_UseBreakpoints ? $inputs .CodeCoverage_UseBreakpoints -eq ' true ' : $null
120+ SingleHitBreakpoints = $null -ne $ inputs.CodeCoverage_SingleHitBreakpoints ? $inputs .CodeCoverage_SingleHitBreakpoints -eq ' true ' : $null
130121 }
131122 TestResult = @ {
132- Enabled = $inputs.TestResult_Enabled
123+ Enabled = $null -ne $ inputs.TestResult_Enabled ? $inputs .TestResult_Enabled -eq ' true ' : $null
133124 OutputFormat = $inputs.TestResult_OutputFormat
134125 OutputPath = $inputs.TestResult_OutputPath
135126 OutputEncoding = $inputs.TestResult_OutputEncoding
@@ -139,11 +130,11 @@ LogGroup 'Init - Load configuration - Action overrides' {
139130 ErrorAction = $inputs.Should_ErrorAction
140131 }
141132 Debug = @ {
142- ShowFullErrors = $inputs.Debug_ShowFullErrors
143- WriteDebugMessages = $inputs.Debug_WriteDebugMessages
133+ ShowFullErrors = $null -ne $ inputs.Debug_ShowFullErrors ? $inputs .Debug_ShowFullErrors -eq ' true ' : $null
134+ WriteDebugMessages = $null -ne $ inputs.Debug_WriteDebugMessages ? $inputs .Debug_WriteDebugMessages -eq ' true ' : $null
144135 WriteDebugMessagesFrom = $inputs.Debug_WriteDebugMessagesFrom
145- ShowNavigationMarkers = $inputs.Debug_ShowNavigationMarkers
146- ReturnRawResultObject = $inputs.Debug_ReturnRawResultObject
136+ ShowNavigationMarkers = $null -ne $ inputs.Debug_ShowNavigationMarkers ? $inputs .Debug_ShowNavigationMarkers -eq ' true ' : $null
137+ ReturnRawResultObject = $null -ne $ inputs.Debug_ReturnRawResultObject ? $inputs .Debug_ReturnRawResultObject -eq ' true ' : $null
147138 }
148139 Output = @ {
149140 CIFormat = $inputs.Output_CIFormat
@@ -153,10 +144,10 @@ LogGroup 'Init - Load configuration - Action overrides' {
153144 RenderMode = $inputs.Output_RenderMode
154145 }
155146 TestDrive = @ {
156- Enabled = $inputs.TestDrive_Enabled
147+ Enabled = $null -ne $ inputs.TestDrive_Enabled ? $inputs .TestDrive_Enabled -eq ' true ' : $null
157148 }
158149 TestRegistry = @ {
159- Enabled = $inputs.TestRegistry_Enabled
150+ Enabled = $null -ne $ inputs.TestRegistry_Enabled ? $inputs .TestRegistry_Enabled -eq ' true ' : $null
160151 }
161152 }
162153
@@ -165,13 +156,13 @@ LogGroup 'Init - Load configuration - Action overrides' {
165156}
166157
167158LogGroup ' Init - Load configuration' {
168- $defaults = New-PesterConfigurationHashtable
159+ $defaults = New-PesterConfigurationHashtable - Default
169160 $configuration = Merge-PesterConfiguration - BaseConfiguration $defaults - AdditionalConfiguration $customConfig , $customInputs
170161
171162 if ([string ]::IsNullOrEmpty($configuration.Run.Path )) {
172163 $configuration.Run.Path = $inputs.Path
173164 }
174- Write-Output ( $configuration | Format-Hashtable | Out-String )
165+ $configuration | Format-Hashtable | Out-String
175166}
176167
177168LogGroup ' Init - Export containers' {
@@ -187,16 +178,39 @@ LogGroup 'Init - Export containers' {
187178 Write-Output " Containers from configuration: [$ ( $containers.Count ) ]"
188179 # Search for "*.Container.*" files in each Run.Path directory
189180 Write-Output ' Searching for containers in same location as config.'
181+ $path = New-Item - Path . - ItemType Directory - Name ' temp' - Force
190182 foreach ($testDir in $inputs.Path ) {
183+ # If testDir is a file, get the directory
184+ $testItem = Get-Item - Path $testDir
185+ if ($testItem.PSIsContainer -eq $false ) {
186+ $testDir = $testItem.DirectoryName
187+ }
188+
191189 $containerFiles = Get-ChildItem - Path $testDir - Filter * .Container.* - Recurse
192190 Write-Output " Containers found in [$testDir ]: [$ ( $containerFiles.Count ) ]"
191+ if ($containerFiles.Count -eq 0 ) {
192+ # Look for test files and make a container for each test file.
193+ $testFiles = Get-ChildItem - Path $testDir - Filter * .Tests.ps1 - Recurse
194+ Write-Output " Test files found in [$testDir ]: [$ ( $testFiles.Count ) ]"
195+ foreach ($testFile in $testFiles ) {
196+ $container = @ {
197+ Path = $testFile.FullName
198+ }
199+ LogGroup " Init - Export containers - Generated - $containerFileName " {
200+ $containerFileName = ($testFile | Split-Path - Leaf).Replace(' .Tests.ps1' , ' .Container.ps1' )
201+ Write-Output " Exporting container [$path /$containerFileName ]"
202+ Export-Hashtable - Hashtable $container - Path " $path /$containerFileName "
203+ }
204+ Write-Output " Containers created from test files: [$ ( $containers.Count ) ]"
205+ }
206+ }
193207 foreach ($containerFile in $containerFiles ) {
194208 $container = Import-Hashtable $containerFile
195209 $containerFileName = $containerFile | Split-Path - Leaf
196210 LogGroup " Init - Export containers - $containerFileName " {
197211 Format-Hashtable - Hashtable $container
198- Write-Verbose ' Converting hashtable to PesterContainer '
199- Export-Hashtable - Hashtable $container - Path " $PSScriptRoot /$containerFileName "
212+ Write-Output " Exporting container [ $path / $containerFileName ] "
213+ Export-Hashtable - Hashtable $container - Path " $path /$containerFileName "
200214 }
201215 }
202216 }
@@ -210,5 +224,6 @@ LogGroup 'Init - Export configuration' {
210224 $configuration.Run.PassThru = $true
211225
212226 Format-Hashtable - Hashtable $configuration
213- Export-Hashtable - Hashtable $configuration - Path " $PSScriptRoot /Invoke-Pester.Configuration.ps1"
227+ Write-Output " Exporting configuration [$path /Invoke-Pester.Configuration.ps1]"
228+ Export-Hashtable - Hashtable $configuration - Path " $path /Invoke-Pester.Configuration.ps1"
214229}
0 commit comments