Skip to content

Instantly share code, notes, and snippets.

@Sarafian
Created April 27, 2017 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sarafian/24177f31e729ea8d64a887e8d34d7ea5 to your computer and use it in GitHub Desktop.
Save Sarafian/24177f31e729ea8d64a887e8d34d7ea5 to your computer and use it in GitHub Desktop.
Check if powershell code is executed as part of a Pester test
function Test-PesterInvocation {
$commandStack=Get-PSCallStack | Select-Object -ExpandProperty Command
#region Render
<#
for($i=$commandStack.Count-1;$i -ge 0;$i--)
{
$prefix="+".PadRight($commandStack.Count-1-$i,'-')
Write-Host ($prefix+$commandStack[$i])
}
#>
#endregion
($commandStack -contains "Invoke-Pester") -or ($commandStack -contains "Describe")
}
@Sarafian
Copy link
Author

if you would enable the render section for troubleshooting it would look like this

+Describe
+-<ScriptBlock>
+--It
+---ItImpl
+----Invoke-Test
+-----<ScriptBlock>
+------Should
+-------Get-TestResult
+--------PesterThrow
+---------<ScriptBlock>
+----------Get-SCTAStageFolderPath
+-----------Test-PesterInvocation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment