gaelcolas / Sampler

Module template with build pipeline and examples, including DSC elements.
MIT License
171 stars 42 forks source link

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

Open KarstenHabay opened 3 months ago

KarstenHabay commented 3 months ago

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

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.<RegisterTypes>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.<RegisterTypes>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.<Main>(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 <ScriptBlock>, 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

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

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

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
johlju commented 3 months ago

I got a similar error when I did not made it a local git repo referencing LibGit2Sharp. 🤔 Though this might be a separate bug.

Unhandled exception. System.IO.DirectoryNotFoundException: Cannot find the .git directory
   at GitVersion.Git.GitRepositoryInfo.GetProjectRootDirectory() in /private/tmp/gitversion-20240722-7185-xp03bq/GitVersion-6.0.0/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs:line 88

Update: Tracking it in issue #482.

johlju commented 3 months ago

@KarstenHabay I can't reproduce the same error you got for the task BUILD MODULEOUTPUT MODULEBUILDER. But I did have to run this to be able to get pass the git error I mentioned in the previous comment:

git init -b main
git add .
git commit -m 'First commmit'

I do have gitversion installed too.

KarstenHabay commented 3 months ago

Can I send you a zip file with the full project? (should be around 500kb without the output folder) I can't seem to get around the problem 🙁 I made a supplemental folder 'Manual' in the test folder with just 1 Pester file which dot sourced the ps1 file. If I run that I get no errors, but that that gets around the whole point of using the Sampler module.


Van: Johan Ljunggren @.> Verzonden: zaterdag 27 juli 2024 23:18 Aan: gaelcolas/Sampler @.> CC: Karsten Habay @.>; Mention @.> Onderwerp: Re: [gaelcolas/Sampler] Pester Mocking seems to not working while running Sampler Build. Am I missing something? (Issue #481)

@KarstenHabayhttps://github.com/KarstenHabay I can't reproduce the same error you got for the task BUILD MODULEOUTPUT MODULEBUILDER. But I did have to run this to be able to get pass the git error I mentioned in the previous comment:

git init -b main git add . git commit -m 'First commmit'

— Reply to this email directly, view it on GitHubhttps://github.com/gaelcolas/Sampler/issues/481#issuecomment-2254256653, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARXXTLUXG422B3NKFVGPRDDZOQFA7AVCNFSM6AAAAABLQL2R2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJUGI2TMNRVGM. You are receiving this because you were mentioned.Message ID: @.***>

johlju commented 3 months ago

Can I send you a zip file with the full project?

Can you set up a public repo on Github that I can clone?

I made a supplemental folder 'Manual' in the test folder with just 1 Pester file which dot sourced the ps1 file. If I run that I get no errors, but that that gets around the whole point of using the Sampler module.

I'm confused what the problem you are having, I thought it was the unhandled exception in the task BUILD MODULEOUTPUT MODULEBUILDER, but that is unrelated to testing - so now I'm confused. 🙂

Also, you have an error in your test script on line 5, it should be Import-Module -Name $script:ModuleName -Force.

KarstenHabay commented 3 months ago

https://github.com/KarstenHabay/Parl.Utility

Also, you have an error in your test script on line 5, it should be Import-Module -Name $script:ModuleName -Force.

Not an error, $Module is a reference to the line before.

As you can see it's a new repo with all the code so far for this project.

I keep getting this error message:

Describing Show-ParlObjectUsingANSIColor
Name   : TestObject
Value  :
Count  : 43
Status :
  [-] Should display property names in green when they have values 25ms (21ms|4ms)
   Expected Write-Host to be called 4 times exactly, but was called 0 times
   at Should -Invoke Write-Host -Times 4 -Exactly, H:\PowerShell\Source\Parl.Utility\tests\Unit\Public\Show-ParlObjectUsingANSIColor.tests.ps1:36
   at <ScriptBlock>, H:\PowerShell\Source\Parl.Utility\tests\Unit\Public\Show-ParlObjectUsingANSIColor.tests.ps1:36
Tests completed in 31.45s

In the code you see that Write-Host is mocked. In the output of .\build.ps1 it outputs the object before giving the error, clearly showing it's not being mocked. Hope the repo helps. Created also a VS Code profile with no extensions, to no avail.

johlju commented 3 months ago

You need to tell Pester in what scope to mock commands. Also there seemed not possible to use $Object as it is a List, so need to compare using the first index in the list. Lastly it was a minor diff in the string being compared. The PR https://github.com/KarstenHabay/Parl.Utility/pull/1/files works.

This was not an error in Sampler though.