After speaking with @rjmholt I've learned that the Import-Module part of the codebase has gotten rather complex and needs to be refactored. However, due to numerous subtleties in how Import-Module works we need to achieve much better testing coverage of Import-Module before work can be done to refactor.
For some context the following PR is what is leading me to create this issue as I noticed some odd behavior which is described in the comments : https://github.com/PowerShell/PowerShell/pull/8758
I'm opening this meta issue to track ongoing work relating to this refactoring and hopefully it can lead to useful discussions. I will also use it to add my own insights, ideas and questions as I dive into it.
A few PRs in this vein:
Note an example of a regression caused by this refactoring, fixed in https://github.com/PowerShell/PowerShell/pull/8218.
Hey @rjmholt, @iSazonov 😄 ,
A potential refactoring I've been thinking about has to to with LoadModuleManifest method within ModuleCmdletBase.cs
This method does essentially two things :
Since we already have a TestModuleManifest.cs which uses LoadModuleManifest + flag disabling all the imports it might be interesting to move the checks to TestModuleManifest.cs (something along the lines of CheckManifestProperties) and have LoadModuleManifest call that method before carrying on with the imports.
This has the following benefits :
TestModuleManifest.cs so that the property checking can be "owned" by the file implementing the associated cmdlet.ModuleCmdletBase.cs size by 25% making it more readable and relieving it of some of its responsibilities improving overall readability.This has the following potential issues :
LoadModuleManifest intertwines simple property checks with imports of related modules and therefore taking into account the previous point we could very well be introducting breaking changes by following through with that refactoring idea.TestSomeProperties => ImportModules => TestSomeMorePropertiesTestAllProperties => ImportModulesHere are the steps to get to where we'd like to go if this strategy gets a green light :
One question I've had regarding the testing base in general is :
How do we know …
/cc @JamesWTruher is working on fixing CodeCov.