Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Support mocking and execution in manifest modules

Open fflaten opened this issue 3 years ago • 1 comments
trafficstars

PR Summary

Adds support for manifest module to Mock, Should -Invoke and InModuleScope.

Fix #1456 Fix #933

PR Checklist

  • [x] PR has meaningful title
  • [x] Summary describes changes
  • [x] PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • [x] Tests are added/update (if required)
  • [ ] Documentation is updated/added (if required)

fflaten avatar Aug 08 '22 19:08 fflaten

Stumbled into an issue with force-importing manifest module with nested module, https://gist.github.com/fflaten/0df7afe3c2a781e2de29aeb55df0b8ff

This causes alias and mock to be placed in old import of a nested module while public function will execute in new and as a result not find the mock.

Workaround: Always remove manifest-module before re-importing. Ex.

BeforeAll {
    Get-Module ManifestModule -ErrorAction SilentlyContinue | Remove-Module
    Import-Module ManifestModule.psd1`
}

I believe this is intentional to avoid overwriting a module that was already imported in the session, while the manifest module will call the updated one (which we can see is updated in (Get-Module ManifestModule).NestedModules)

fflaten avatar Aug 09 '22 16:08 fflaten