gaelcolas / Sampler

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

Issues with functional tests of rebuilt modules #492

Closed DennisL68 closed 1 week ago

DennisL68 commented 3 weeks ago

I noticed, when rebuilding my module in iterative stages, that my changes wouldn't be reloaded by PowerShell (for a deeper explanation see PowerShell - Reloading module does not reload submodules)

So I had to resort to restarting my PowerShell console between each build. This got so tedious that I placed the following functions in my $profile script to ease the suffering...

function Start-PSChildProcess {
  if (
    (
      Get-Process -Id (
        Get-CimInstance Win32_Process -Filter "ProcessId = $PID"
      ).ParentProcessId
    ).ProcessName -ne 'powershell'
  ) {
    Write-Output ("Starting a PowerShell child session...`n" +
      "Use Exit-PSChildProcess to exit to parent...`n")
    powershell.exe
  }
  else {
    Write-Error 'You are already running in a PowerShell child process.'
  }
}

function Exit-PSChildProcess {
  if (
    (
      Get-Process -Id (
        Get-CimInstance Win32_Process -Filter "ProcessId = $PID"
      ).ParentProcessId
    ).ProcessName -eq 'powershell'
  ) {
    Write-Output "Exiting to parent PowerShell process...`n"
    exit
  }
  else {
    Write-Error ("You are not running in a PowerShell child process.`n" +
      "Exiting will terminating the top PowerShell process, closing this Window.`n")
  }

}

Perhaps these two functions could be added by Sampler as an option?

johlju commented 3 weeks ago

I first use this: https://github.com/gaelcolas/Sampler/issues/87#issuecomment-2277283023

If the module contain classes or assemblies that are changed between test runs I have a Invoke-PesterJob that starts Pester in a separate job, that way I can re-build the module and it is not blocked by loaded classes and assemblies. I planning to publish Invoke-PesterJob to the module Viscalyx.Common eventually.

johlju commented 3 weeks ago

I suggest adding that above functions to your own module and publish it to PS Gallery.

johlju commented 1 week ago

I merged the my Invoke-PesterJob in the module Viscalyx.Common.

I hope it helps the community.

johlju commented 1 week ago

Closing this as per comment https://github.com/gaelcolas/Sampler/issues/492#issuecomment-2299025299.