gaelcolas / gaelcolas/Sampler

Pester Mocking seems to not working while running Sampler Build. Am I missing something?

Open
#481 6 comments 0 reactions 0 assignees View on GitHub
waiting for author response
Dominant language
PowerShell
Stars
243
Forks
46
Avg merge
1h 41m
Merged PRs (30d)
1

Description

### Problem description

I have a function Show-ParlObjectUsingANSIColor and a test (see both below). When I run them directly (in a PowerShell console) with Pester both as inline or as dot sourced, they run fine and the test passes. When I run both files in a Sampler project using the .\build.ps1 command/script, I get error messages. I use Sampler 0.118.1 and Pester 5.6.1.

Am I missing something? Do I need to configure something somewhere in a config file? If so, I couldn't find it in the documentation of Sampler, or it wasn't clear enough for me. In the latter case, I'm sorry to have bothered you with this problem, as long as you can point me in the right direction ;-)

**Function**:
```
function Show-ParlObjectUsingANSIColor
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope='Function')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidTrailingWhitespace', '', Scope='Function')]

[CmdletBinding()]
param (
[Parameter( Mandatory = $true,
Position = 0)]
[psobject]
$Object,

[Parameter()]
[array]
$ModifyEmptyParameterName,

[Parameter()]
[ValidateSet('Black', 'Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan', 'White')]
[string]
$ModifyEmptyParameterColor = 'Red',

[Parameter()]
[array]
$SkipParameter
)

begin {
Write-Verbose "[BEGIN ] Starting: $($MyInvocation.Mycommand)"

Write-Verbose "[META ] Computer = $env:COMPUTERNAME"
Write-Verbose "[META ] User = $env:USERDOMAIN\$env:USERNAME"
Write-Verbose "[META ] Command = $($MyInvocation.Mycommand)"
Write-Verbose "[META ] PSEdition = $($PSVersionTable.PSEdition)"
Write-Verbose "[META ] PSVersion = $($PSVersionTable.PSVersion)"
Write-Verbose "[META ] Test Date = $(Get-Date)"

# Define ANSI color codes
$Colors = @{
Black = "`e[30m"
Red = "`e[91;1m"
Green = "`e[92;1m"
Yellow = "`e[93;1m"
Blue = "`e[94;1m"
Magenta = "`e[95;1m"
Cyan = "`e[96;1m"
White = "`e[37m"
Reset = "`e[0m" # Resets Color
}

# Calculate the longest property name for alignment
$LongestNameCount = $Object.PSObject.Properties.Name | Measure-Object -Property Length -Maximum | Select-Object -ExpandProperty Maximum

# Checks if ModifyEmptyParameterName has been entered, if not use all property keys
if (-not $PSBoundParameters.ContainsKey('ModifyEmptyParameterName'))
{
$ModifyEmptyParameterName = $Object.PSObject.Properties.Name
} #if
}

process {
foreach ($Property in $Object.PSObject.Properties)
{
if ($SkipParameter -contains $Property.Name)
{
continue
}

# Adds Padding to make all parameter name texts the same length
$Name = $Property.Name.PadRight($LongestNameCount, " ")
# Replace null values by empty strings
$Value = if ([string]::IsNullOrWhiteSpace($Property.Value)) { $null } else { $Property.Value }
# Correct the date format if Value is of type DateTime
if (($value -is [datetime]) -and ($null -ne $Value))
{
$Value = $Value.ToShortDateString()
}

# Check if Value is null and Property is listed, set the ModifyEmptyParameterColor accordingly
$ColorCode = if (($null -eq $Value) -and ($ModifyEmptyParameterName -contains $Property.Name))
{
$Colors[$ModifyEmptyParameterColor]
} else {
$Colors["Green"]
}

# Write the property name with color
Write-Host "$($ColorCode)$Name :$($Colors["Reset"]) $($Colors["White"])$Value$($Colors["Reset"])"
}
}

end {
Write-Verbose "[END ] Ending: $($MyInvocation.Mycommand)"
}
}
```

**Pester test:**
```
BeforeAll {
$script:ModuleName = 'Parl.ScriptTools'
Get-Module -Name $script:ModuleName -All | Remove-Module -Force
$Module = Get-Module -Name $script:ModuleName -ListAvailable
Import-Module -Name $Module -Force
}

AfterAll {
# Unload the module being tested so that it doesn't impact any other tests.
Get-Module -Name $script:ModuleName -All | Remove-Module -Force
}

Describe 'Show-ParlObjectUsingANSIColor' {
BeforeAll {
# Arrange
# Mock the Write-Host to intercept and check the output
Mock Write-Host {throw "Don't call Write-Host for real"}
}

It 'Should display property names in green when they have values' {
# Arrange
Mock Write-Host { }
$testObject = [PSCustomObject]@{
Name = 'TestObject'
Value = $null
Count = 43
Status = ''
}
# Act
Write-Output "Starting Act"
Show-ParlObjectUsingANSIColor -Object $testObject -ModifyEmptyParameterName @('Value', 'Status')
# Assert
Write-Output "Starting Assert"
Should -Invoke Write-Host -Times 4 -Exactly
Should -Invoke Write-Host -ParameterFilter {$Object -eq "`e[92;1mName :`e[0m `e[37mTestObject`e[0m"}
Should -Invoke Write-Host -ParameterFilter {$Object -eq "`e[92;1mCount :`e[0m `e[37m42`e[0m"}
}
}
```

### Verbose logs

```text
PS H:\PowerShell\Tests\Parl.ScriptTools> .\build.ps1
[pre-build] Starting Build Init
[build] Starting build with InvokeBuild.
[build] Parsing defined tasks
[build] Loading Configuration from H:\PowerShell\Tests\Parl.ScriptTools\build.yaml
Importing tasks from module Sampler.GitHubTasks
Loading New-Release.GitHub.build.Sampler.GitHubTasks.ib.tasks...
Importing tasks from module Sampler
Loading Build-Module.ModuleBuilder.build.Sampler.ib.tasks...
Loading ChocolateyPackage.build.Sampler.ib.tasks...
Loading Clean.ModuleBuilder.build.Sampler.ib.tasks...
Loading Create_Changelog_Branch.build.Sampler.ib.tasks...
Loading Create_Release_Git_Tag.build.Sampler.ib.tasks...
Loading DeployAll.PSDeploy.build.Sampler.ib.tasks...
Loading DscResource.Test.build.Sampler.ib.tasks...
Loading generateHelp.PlatyPS.build.Sampler.ib.tasks...
Loading GuestConfig.build.Sampler.ib.tasks...
Loading Invoke-Pester.pester.build.Sampler.ib.tasks...
Loading JaCoCo.coverage.build.Sampler.ib.tasks...
Loading release.module.build.Sampler.ib.tasks...
Loading Set-SamplerTaskVariable...
Loading SetPsModulePath.build.Sampler.ib.tasks...
Adding Workflow from configuration:
+-> pack
+-> test
+-> publish
+-> .
+-> build
[build] Executing requested workflow: .
Build . H:\PowerShell\Tests\Parl.ScriptTools\build.ps1
Redefined task '.'.

===============================================================================
CLEAN
Deleting the content of the Build Output folder, except ./modules
-------------------------------------------------------------------------------
/./build/Clean
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Clean.ModuleBuilder.build.ps1:16

Removing H:\PowerShell\Tests\Parl.ScriptTools\output\* excluding RequiredModules
Done /./build/Clean 00:00:00.2780642

===============================================================================
BUILD MODULEOUTPUT MODULEBUILDER
Build the Module based on its Build.psd1 definition
-------------------------------------------------------------------------------
/./build/Build_Module_ModuleBuilder/Build_ModuleOutput_ModuleBuilder
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Build-Module.ModuleBuilder.build.ps1:41

Project Name = 'Parl.ScriptTools'
Source Path = 'H:\PowerShell\Tests\Parl.ScriptTools\source'
Output Directory = 'H:\PowerShell\Tests\Parl.ScriptTools\output'
Release Notes path = 'H:\PowerShell\Tests\Parl.ScriptTools\output\ReleaseNotes.md'
Built Module Subdirectory = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module'
Module Manifest Path (src) = 'H:\PowerShell\Tests\Parl.ScriptTools\source\Parl.ScriptTools.psd1'
Unhandled exception. LibGit2Sharp.LibGit2SharpException: repository path 'H:/PowerShell/Tests/Parl.ScriptTools/' is not owned by current user
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 154
at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 172
at LibGit2Sharp.Core.Proxy.git_repository_open(String path) in /_/LibGit2Sharp/Core/Proxy.cs:line 2560
at LibGit2Sharp.Repository..ctor(String path, RepositoryOptions options, RepositoryRequiredParameter requiredParameter) in /_/LibGit2Sharp/Repository.cs:line 159
at LibGit2Sharp.Repository..ctor(String path) in /_/LibGit2Sharp/Repository.cs:line 70
at GitVersion.Git.GitRepositoryInfo.GetProjectRootDirectory() in /_/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs:line 88
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at GitVersion.Git.GitRepositoryInfo.get_ProjectRootDirectory() in /_/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs:line 31
at GitVersion.Git.GitRepositoryInfo.GetGitRootPath() in /_/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs:line 96
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at GitVersion.Git.GitRepositoryInfo.get_GitRootPath() in /_/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs:line 30
at GitVersion.GitVersionLibGit2SharpModule.<>c.b__0_0(IServiceProvider sp) in /_/src/GitVersion.LibGit2Sharp/GitVersionLibGit2SharpModule.cs:line 16
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at GitVersion.GitVersionCoreModule.<>c.b__0_0(IServiceProvider sp) in /_/src/GitVersion.Core/GitVersionCoreModule.cs:line 28
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at GitVersion.Program.Main(String[] args) in /_/src/GitVersion.App/Program.cs:line 18
at GitVersion.Program.(String[] args)
Module Version = ''
PSModulePath = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module;
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules;
H:\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules;
\\fs1\public\PowerShell\Modules;
c:\Users\khabay\.vscode\extensions\ms-vscode.powershell-2024.2.2\modules;'

Adding OutputDirectory with value H:\PowerShell\Tests\Parl.ScriptTools\output from current Variables
Adding VersionedOutputDirectory with value True from current Variables
Adding CopyPaths with value en-US from Build Info
Adding Encoding with value UTF8 from Build Info
Building Module to H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools...
Done /./build/Build_Module_ModuleBuilder/Build_ModuleOutput_ModuleBuilder 00:00:01.4237815

===============================================================================
BUILD DSCRESOURCESTOEXPORT MODULEBUILDER

-------------------------------------------------------------------------------
/./build/Build_Module_ModuleBuilder/Build_DscResourcesToExport_ModuleBuilder
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Build-Module.ModuleBuilder.build.ps1:327

Project Name = 'Parl.ScriptTools'
Source Path = 'H:\PowerShell\Tests\Parl.ScriptTools\source'
Output Directory = 'H:\PowerShell\Tests\Parl.ScriptTools\output'
Release Notes path = 'H:\PowerShell\Tests\Parl.ScriptTools\output\ReleaseNotes.md'
Built Module Subdirectory = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module'
Module Manifest Path (src) = 'H:\PowerShell\Tests\Parl.ScriptTools\source\Parl.ScriptTools.psd1'
Versioned Output Directory = 'True'
Built Module Manifest = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psd1'
Built Module Base = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1'
Module Version = '0.0.1'
Module Version Folder = '0.0.1'
Pre-release Tag = ''
Built Module Root Script = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psm1'
PSModulePath = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module;
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules;
H:\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules;
\\fs1\public\PowerShell\Modules;
c:\Users\khabay\.vscode\extensions\ms-vscode.powershell-2024.2.2\modules;'

Built DSC Resource Path = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\DSCResources'
Looking for class-based DSC Resources in in 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psm1'
Looking for MOF-based DSC Resources in 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\DSCResources'
Looking for DSC Composite Resources in 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\DSCResources'
Done /./build/Build_Module_ModuleBuilder/Build_DscResourcesToExport_ModuleBuilder 00:00:00.7213393
Done /./build/Build_Module_ModuleBuilder 00:00:02.1457845

===============================================================================
BUILD NESTEDMODULES MODULEBUILDER

-------------------------------------------------------------------------------
/./build/Build_NestedModules_ModuleBuilder
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Build-Module.ModuleBuilder.build.ps1:129

Project Name = 'Parl.ScriptTools'
Source Path = 'H:\PowerShell\Tests\Parl.ScriptTools\source'
Output Directory = 'H:\PowerShell\Tests\Parl.ScriptTools\output'
Release Notes path = 'H:\PowerShell\Tests\Parl.ScriptTools\output\ReleaseNotes.md'
Built Module Subdirectory = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module'
Module Manifest Path (src) = 'H:\PowerShell\Tests\Parl.ScriptTools\source\Parl.ScriptTools.psd1'
Versioned Output Directory = 'True'
Built Module Manifest = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psd1'
Built Module Base = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1'
Module Version = '0.0.1'
Module Version Folder = '0.0.1'
Pre-release Tag = ''
Built Module Root Script = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psm1'
PSModulePath = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module;
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules;
H:\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules;
\\fs1\public\PowerShell\Modules;
c:\Users\khabay\.vscode\extensions\ms-vscode.powershell-2024.2.2\modules;'

Done /./build/Build_NestedModules_ModuleBuilder 00:00:00.7446191

===============================================================================
CREATE CHANGELOG RELEASE OUTPUT
Create ReleaseNotes from changelog and update the Changelog for release
-------------------------------------------------------------------------------
/./build/Create_changelog_release_output
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\release.module.build.ps1:103

Project Name = 'Parl.ScriptTools'
Source Path = 'H:\PowerShell\Tests\Parl.ScriptTools\source'
Output Directory = 'H:\PowerShell\Tests\Parl.ScriptTools\output'
Release Notes path = 'H:\PowerShell\Tests\Parl.ScriptTools\output\ReleaseNotes.md'
Built Module Subdirectory = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module'
Module Manifest Path (src) = 'H:\PowerShell\Tests\Parl.ScriptTools\source\Parl.ScriptTools.psd1'
Versioned Output Directory = 'True'
Built Module Manifest = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psd1'
Built Module Base = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1'
Module Version = '0.0.1'
Module Version Folder = '0.0.1'
Pre-release Tag = ''
Built Module Root Script = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psm1'
PSModulePath = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module;
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules;
H:\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules;
\\fs1\public\PowerShell\Modules;
c:\Users\khabay\.vscode\extensions\ms-vscode.powershell-2024.2.2\modules;'

ChangeLogOutputPath = 'H:\PowerShell\Tests\Parl.ScriptTools\output\CHANGELOG.md'
Creating 'H:\PowerShell\Tests\Parl.ScriptTools\output\CHANGELOG.md'...
Built Manifest H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psd1
Done /./build/Create_changelog_release_output 00:00:00.9002265
Done /./build 00:00:04.0741325

===============================================================================
IMPORT PESTER

-------------------------------------------------------------------------------
/./test/Pester_Tests_Stop_On_Fail/Import_Pester
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Invoke-Pester.pester.build.ps1:55

Done /./test/Pester_Tests_Stop_On_Fail/Import_Pester 00:00:00.0809610

===============================================================================
INVOKE PESTER TESTS V4
Making sure the Module meets some quality standard (help, tests) using Pester 4.
-------------------------------------------------------------------------------
/./test/Pester_Tests_Stop_On_Fail/Invoke_Pester_Tests_v4
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Invoke-Pester.pester.build.ps1:63

Pester 4 is not used in the pipeline, skipping task.

Done /./test/Pester_Tests_Stop_On_Fail/Invoke_Pester_Tests_v4 00:00:00.0089651

===============================================================================
INVOKE PESTER TESTS V5
Making sure the Module meets some quality standard (help, tests) using Pester 5.
-------------------------------------------------------------------------------
/./test/Pester_Tests_Stop_On_Fail/Invoke_Pester_Tests_v5
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Invoke-Pester.pester.build.ps1:422

Project Name = 'Parl.ScriptTools'
Source Path = 'H:\PowerShell\Tests\Parl.ScriptTools\source'
Output Directory = 'H:\PowerShell\Tests\Parl.ScriptTools\output'
Release Notes path = 'H:\PowerShell\Tests\Parl.ScriptTools\output\ReleaseNotes.md'
Built Module Subdirectory = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module'
Module Manifest Path (src) = 'H:\PowerShell\Tests\Parl.ScriptTools\source\Parl.ScriptTools.psd1'
Versioned Output Directory = 'True'
Built Module Manifest = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psd1'
Built Module Base = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1'
Module Version = '0.0.1'
Module Version Folder = '0.0.1'
Pre-release Tag = ''
Built Module Root Script = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psm1'
PSModulePath = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module;
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules;
H:\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules;
\\fs1\public\PowerShell\Modules;
c:\Users\khabay\.vscode\extensions\ms-vscode.powershell-2024.2.2\modules;'

Pester Output Folder = 'H:\PowerShell\Tests\Parl.ScriptTools\output\testResults
Creating folder H:\PowerShell\Tests\Parl.ScriptTools\output\testResults

-------------------------------------------------------------------------------------
Consider updating the build configuration to the new advanced configuration options:
-------------------------------------------------------------------------------------
# PESTER CONFIG START
Pester:
# Pester Advanced configuration.
# If a key is not set it will be using Sampler pipeline default value.
Configuration:
Run:
Path:

ExcludePath:
Filter:
Tag:

ExcludeTag:

Output:
Verbosity:
CodeCoverage:
Path:
OutputFormat:
CoveragePercentTarget: 50
OutputPath:
OutputEncoding:
ExcludeTests:
TestResult:
OutputFormat: NUnitXML
OutputPath:
OutputEncoding:
TestSuiteName:
# Sampler pipeline configuration
ExcludeFromCodeCoverage:

# PESTER CONFIG END
-------------------------------------------------------------------------------------

Using deprecated build configuration for OutputFormat as a invocation task parameter.
Using deprecated build configuration for CodeCoverageThreshold as a invocation task parameter.

Using PesterConfigurationCodeCoverageCoveragePercentTarget from build invocation task parameter.
Using PesterConfigurationTestResultOutputFormat from build invocation task parameter.

Pester Exclude Path =
Pester Exclude Tags =
Pester Tags =
Pester Verbosity = Detailed

Pester Code Coverage Source Path = H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psm1
Pester Exclude Code Coverage Path =
Pester Exclude Tests Source Path = True
Pester Code Coverage Output Path = H:\PowerShell\Tests\Parl.ScriptTools\output\testResults\CodeCov_Parl.ScriptTools_v0.0.1.Windows.PSv.7.4.4.xml
Pester Code Coverage Output Format = JaCoCo
Pester Code Coverage Output Encoding = UTF8
Pester Code Coverage Percent Threshold = 50

Pester Test Result Test Suite Name = Parl.ScriptTools
Pester Test Result Output Path = H:\PowerShell\Tests\Parl.ScriptTools\output\testResults\NUnitXml_Parl.ScriptTools_v0.0.1.Windows.PSv.7.4.4.xml
Pester Test Result Output Format = NUnitXML
Pester Test Result Output Encoding = UTF8
Pester Test Result Percent Threshold = 50

Pester Test Scripts = H:\PowerShell\Tests\Parl.ScriptTools\tests
Pester v5.6.1

Starting discovery in 2 files.
Discovery found 11 tests in 179ms.
Starting code coverage.
Code Coverage preparation finished after 44 ms.
Running tests.

Running tests from 'H:\PowerShell\Tests\Parl.ScriptTools\tests\QA\module.tests.ps1'
Describing Changelog Management
[+] Changelog format compliant with keepachangelog format 5ms (3ms|2ms)
[+] Changelog should have an Unreleased header 3ms (3ms|0ms)

Describing General module control
[+] Should import without errors 9ms (8ms|1ms)
[+] Should remove without error 1ms (1ms|0ms)

Describing Quality for module
[+] Should have a unit test for Show-ParlObjectUsingANSIColor 33ms (31ms|1ms)
[+] Should pass Script Analyzer for Show-ParlObjectUsingANSIColor 62ms (62ms|0ms)

Describing Help for module
[+] Should have .SYNOPSIS for Show-ParlObjectUsingANSIColor 31ms (30ms|1ms)
[+] Should have a .DESCRIPTION with length greater than 40 characters for Show-ParlObjectUsingANSIColor 29ms (29ms|0ms)
[+] Should have at least one (1) example for Show-ParlObjectUsingANSIColor 32ms (31ms|1ms)
[+] Should have described all parameters for Show-ParlObjectUsingANSIColor 37ms (37ms|0ms)

Running tests from 'H:\PowerShell\Tests\Parl.ScriptTools\tests\Unit\Public\Show-ParlObjectUsingANSIColor.tests.ps1'
Describing Show-ParlObjectUsingANSIColor
Name : TestObject
Value :
Count : 43
Status :
[-] Should display property names in green when they have values 6ms (5ms|1ms)
Expected Write-Host to be called 4 times exactly, but was called 0 times
at Should -Invoke Write-Host -Times 4 -Exactly, H:\PowerShell\Tests\Parl.ScriptTools\tests\Unit\Public\Show-ParlObjectUsingANSIColor.tests.ps1:36
at , H:\PowerShell\Tests\Parl.ScriptTools\tests\Unit\Public\Show-ParlObjectUsingANSIColor.tests.ps1:36
Tests completed in 890ms
Tests Passed: 10, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0
Processing code coverage result.
Code Coverage result processed in 46 ms.
Covered 95,92% / 50%. 49 analyzed Commands in 1 File.
Missed commands:

File Class Function Line Command
---- ----- -------- ---- -------
Parl.ScriptTools.psm1 Show-ParlObjectUsingANSIColor 129 $ModifyEmptyParameterName = $Object.PSObject.Properties.Name
Parl.ScriptTools.psm1 Show-ParlObjectUsingANSIColor 148 $Value = $Value.ToShortDateString()

Done /./test/Pester_Tests_Stop_On_Fail/Invoke_Pester_Tests_v5 00:00:02.1484683
Task /./test/Pester_Tests_Stop_On_Fail/Upload_Test_Results_To_AppVeyor skipped.

===============================================================================
PESTER RUN TIMES
List the run time for each Pester test.
-------------------------------------------------------------------------------
/./test/Pester_Tests_Stop_On_Fail/Pester_Run_Times
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Invoke-Pester.pester.build.ps1:1068

Project Name = 'Parl.ScriptTools'
Source Path = 'H:\PowerShell\Tests\Parl.ScriptTools\source'
Output Directory = 'H:\PowerShell\Tests\Parl.ScriptTools\output'
Release Notes path = 'H:\PowerShell\Tests\Parl.ScriptTools\output\ReleaseNotes.md'
Built Module Subdirectory = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module'
Module Manifest Path (src) = 'H:\PowerShell\Tests\Parl.ScriptTools\source\Parl.ScriptTools.psd1'
Versioned Output Directory = 'True'
Built Module Manifest = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psd1'
Built Module Base = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1'
Module Version = '0.0.1'
Module Version Folder = '0.0.1'
Pre-release Tag = ''
Built Module Root Script = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psm1'
PSModulePath = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module;
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules;
H:\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules;
\\fs1\public\PowerShell\Modules;
c:\Users\khabay\.vscode\extensions\ms-vscode.powershell-2024.2.2\modules;'

Pester Output Folder = H:\PowerShell\Tests\Parl.ScriptTools\output\testResults
Pester Output Object = H:\PowerShell\Tests\Parl.ScriptTools\output\testResults\PesterObject_Parl.ScriptTools_v0.0.1.Windows.PSv.7.4.4.xml

Test Script File Duration Result Passed Failed Skipped Total
---------------- -------- ------ ------ ------ ------- -----
module.tests.ps1 0 seconds Passed 10 0 0 10
Show-ParlObjectUsingANSIColor.tests.ps1 0 seconds Failed 0 1 0 1

Total run time: 0 minutes 0 seconds (11 tests was run)

Done /./test/Pester_Tests_Stop_On_Fail/Pester_Run_Times 00:00:00.7281033

===============================================================================
FAIL BUILD IF PESTER TESTS FAILED
This task ensures the build job fails if the test aren't successful.
-------------------------------------------------------------------------------
/./test/Pester_Tests_Stop_On_Fail/Fail_Build_If_Pester_Tests_Failed
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Invoke-Pester.pester.build.ps1:361

Asserting that no test failed

Project Name = 'Parl.ScriptTools'
Source Path = 'H:\PowerShell\Tests\Parl.ScriptTools\source'
Output Directory = 'H:\PowerShell\Tests\Parl.ScriptTools\output'
Release Notes path = 'H:\PowerShell\Tests\Parl.ScriptTools\output\ReleaseNotes.md'
Built Module Subdirectory = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module'
Module Manifest Path (src) = 'H:\PowerShell\Tests\Parl.ScriptTools\source\Parl.ScriptTools.psd1'
Versioned Output Directory = 'True'
Built Module Manifest = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psd1'
Built Module Base = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1'
Module Version = '0.0.1'
Module Version Folder = '0.0.1'
Pre-release Tag = ''
Built Module Root Script = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module\Parl.ScriptTools\0.0.1\Parl.ScriptTools.psm1'
PSModulePath = 'H:\PowerShell\Tests\Parl.ScriptTools\output\module;
H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules;
H:\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules;
\\fs1\public\PowerShell\Modules;
c:\Users\khabay\.vscode\extensions\ms-vscode.powershell-2024.2.2\modules;'

Pester Output Folder = 'H:\PowerShell\Tests\Parl.ScriptTools\output\testResults'
Code Coverage Threshold = '50'
Pester Output Object = H:\PowerShell\Tests\Parl.ScriptTools\output\testResults\PesterObject_Parl.ScriptTools_v0.0.1.Windows.PSv.7.4.4.xml
ERROR: Assertion failed. Failed 1 tests. Aborting Build
At H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Invoke-Pester.pester.build.ps1:415 char:9
+ Assert-Build -Condition ($pesterObject.FailedCount -eq 0) -Me …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Invoke-Pester.pester.build.ps1:361 char:1
+ task Fail_Build_If_Pester_Tests_Failed {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Build FAILED. 15 tasks, 1 errors, 0 warnings 00:00:08.5530582
Assert-Build: H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\tasks\Invoke-Pester.pester.build.ps1:415:9
Line |
415 | Assert-Build -Condition ($pesterObject.FailedCount -eq 0) -Me …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Assertion failed. Failed 1 tests. Aborting Build
```

### How to reproduce

Create a sampler project, put the function in a public folder and then the test in a public test folder.
Run .\build.ps1 -resolveDependency -Tasks noop
Run .\build.ps1

### Expected behavior

Passing test

### Current behavior

Error message

### Suggested solution

Need help

### Operating system the target node is running

```text
OsName : Microsoft Windows 11 Pro
OsOperatingSystemSKU : 48
OsArchitecture : 64 bits
WindowsVersion : 2009
WindowsBuildLabEx : 22621.1.amd64fre.ni_release.220506-1250
OsLanguage : nl-NL
OsMuiLanguages : {nl-NL}
```

### PowerShell version and build the target node is running

```text
Name Value
---- -----
PSVersion 7.4.4
PSEdition Core
GitCommitId 7.4.4
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

### Module version used

```text
Name Version Path
---- ------- ----
Sampler 0.118.1 H:\PowerShell\Tests\Parl.ScriptTools\output\RequiredModules\Sampler\0.118.1\Sampler.psd1
Sampler 0.118.1 H:\PowerShell\Modules\Sampler\0.118.1\Sampler.psd1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.