From 995ffbc53fbbf0fe7e85b55a137ab02b92c63e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Mon, 13 Oct 2025 08:46:21 +0200 Subject: [PATCH 1/2] feat(invokeCommand.mock): add tracing mock invokes --- Test/include/invokeCommand.mock.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Test/include/invokeCommand.mock.ps1 b/Test/include/invokeCommand.mock.ps1 index 0200065..0889788 100644 --- a/Test/include/invokeCommand.mock.ps1 +++ b/Test/include/invokeCommand.mock.ps1 @@ -3,6 +3,9 @@ # # This includes help commands to mock invokes in a test module # +# Set $env:TraceInvokeMockFilePath to trave Invoke dependencies +# "traceInvoke.log" | %{touch $_ ; $env:TraceInvokeMockFilePath = $_ | Resolve-Path} +# # THIS INCLUDE REQURED module.helper.ps1 if(-not $MODULE_NAME){ throw "Missing MODULE_NAME varaible initialization. Check for module.helerp.ps1 file." } if(-not $MODULE_ROOT_PATH){ throw "Missing MODULE_ROOT_PATH varaible initialization. Check for module.helerp.ps1 file." } @@ -14,6 +17,28 @@ $MOCK_PATH = $testRootPath | Join-Path -ChildPath 'private' -AdditionalChildPath $MODULE_INVOKATION_TAG = "$($MODULE_NAME)Module" $MODULE_INVOKATION_TAG_MOCK = "$($MODULE_INVOKATION_TAG)_Mock" +function Trace-InvokeCommandAlias{ + [CmdletBinding()] + param( + [Parameter(Mandatory,Position=0)][string]$Alias + ) + + $filePath = $env:TraceInvokeMockFilePath + + if(! $filePath){ return } + + if(! (Test-Path $filePath)) {return} + + $content = Get-Content $filePath + + $content = $content ?? @() + + if($content.Contains($Alias)) { return} + + $alias | Out-File $filePath -Append + +} + function Set-InvokeCommandMock{ [CmdletBinding()] param( @@ -22,6 +47,8 @@ function Set-InvokeCommandMock{ ) InvokeHelper\Set-InvokeCommandAlias -Alias $Alias -Command $Command -Tag $MODULE_INVOKATION_TAG_MOCK + + Trace-InvokeCommandAlias $alias } function Reset-InvokeCommandMock{ @@ -257,3 +284,5 @@ function Assert-MockFileNotfound{ } + + From 05cb5cf17fc2614a076671192f1cb15a78001f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Mon, 13 Oct 2025 10:30:48 +0100 Subject: [PATCH 2/2] feat(invokeCommand.mock): Add invoke tracing --- Test/public/invokeCommand.mock.test.ps1 | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Test/public/invokeCommand.mock.test.ps1 b/Test/public/invokeCommand.mock.test.ps1 index df7a0f1..22458a2 100644 --- a/Test/public/invokeCommand.mock.test.ps1 +++ b/Test/public/invokeCommand.mock.test.ps1 @@ -85,4 +85,37 @@ function Test_MockCallExpression{ Assert-Count -Presented $result -Expected 2 Assert-Contains -Presented $result -Expected 'new string from mock 2' Assert-Contains -Presented $result -Expected 'more things to say' +} + +function Test_TraceInvokeCOmmandAlias{ + + + $fileName = "traceInvoke.log" + Assert-ItemNotExist -Path $fileName + + # Set flag + touch $fileName + $fileNamePath = $fileName | Resolve-Path + $env:TraceInvokeMockFilePath = $fileNamePath + Assert-ItemExist -Path $fileNamePath + + # Act record invoke alias + Set-InvokeCommandMock -alias "fakeAlias1" -Command 'echo "hello from fakeAlias1"' + Set-InvokeCommandMock -alias "fakeAlias2" -Command 'echo "hello from fakeAlias2"' + + # Assert the two new alias are recorded + $content = Get-Content $fileNamePath + Assert-Count -Expected 2 -Presented $content + Assert-Contains -Presented $content -Expected 'fakeAlias1' + Assert-Contains -Presented $content -Expected 'fakeAlias2' + + # Assert no duplicate alias are recorded + Set-InvokeCommandMock -alias "fakeAlias1" -Command 'echo "hello from fakeAlias1"' + $content = Get-Content $fileNamePath + Assert-Count -Expected 2 -Presented $content + + # Assert new alias are recorded + Set-InvokeCommandMock -alias "fakeAlias3" -Command 'echo "hello from fakeAlias1"' + $content = Get-Content $fileNamePath + Assert-Count -Expected 3 -Presented $content } \ No newline at end of file