- This topic has 2 replies, 2 voices, and was last updated 1 week, 5 days ago by
August 18, 2020 at 3:15 pm #250709ParticipantTopics: 8Replies: 10Points: 67Rank: Member
I’m new to Pester and trying to use it as an excuse to reorganize my PS modules. Currently, I have put my functions in the .psm1 file, so my modules have a flat folder structure with just the .psm1, .psd1, a test file, and some PowerShell Studio project files.
With the introduction of Pester, I’m trying to adopt a structure where:
- Each function resides in an individual .ps1 file in .\Functions\Public or .\Functions\Private.
- The .psm1 file has a generic process that dot sources each of the public and private functions and exports the public functions.
- The Pester tests will either reside at .\Tests or .\Functions\Public\Tests or .\Functions\Private\Tests (I haven’t decided yet). They will also likely be broken into Unit and Integration folders, but again, not decided yet.
The initial problem I’m having is that when I run Import-Module <module_name>, the Pester tests are getting executed. I don’t understand what is triggering this, so I’m not sure how to stop it, but it’s definitely not desired. Any ideas are greatly appreciated.
Additionally, I’m interested in any thoughts on this module organization and any recommended changes. Thanks.
August 18, 2020 at 6:38 pm #250727ParticipantTopics: 8Replies: 10Points: 67Rank: Member
I resolved the auto-execution of the Pester tests when I found and deleted a test that was still in the same folder as .ps1 script files. However, I’m still interested in how others structure their modules.
September 7, 2020 at 11:46 am #255020ParticipantTopics: 0Replies: 44Points: 427Rank: Contributor
Slightly out of date at this point (I now generally use a source folder), but:
– Source Folder containing
– Public Folder, with individual public function .ps1 files
– Private Folder, with individual private function .ps1 files
– Classes / Data folders if required
– Tests folder, containing the same structure as source – one unit test file per function, integration tests in a separate folder.
– Build / Pipelines / GitVersion files in the root
We use ModuleBuilder which takes the arrangement above (plus some arguments, maybe in a Build.psd1) and “compiles” the different files into a single PSD1/PSM1 (and automatically handles exporting the public functions). This results in a significant performance increase when signing and importing the module.
Edit: Really need to do an update pass on that example repository.
- This reply was modified 1 week, 5 days ago by James Ruskin.
- You must be logged in to reply to this topic.