Skip to content

Commit abb0e09

Browse files
committed
Update ReadMe and Test.ps1
1 parent f821a05 commit abb0e09

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

ReadMe.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,53 +32,49 @@ cd Modulebuilder
3232

3333
#### 2. Install dependencies
3434

35-
We have a few modules which are required for building. They're listed in `RequiredModules.psd1` -- the `.\Install-RequiredModule.ps1` script installs them (it defaults to CurrentUser scope, but has a `-Scope` parameter if you're running elevated and want to install them for the `AllUsers`). They only change rarely, so you won't need to run this repeatedly.
35+
We have a few modules which are required for building. They're listed in `RequiredModules.psd1` -- the `Install-RequiredModule` script installs them (it defaults to CurrentUser scope, but has a `-Scope` parameter if you're running elevated and want to install them for the `AllUsers`). They only change rarely, so you shouldn't need to run this repeatedly, but it does _import_ the modules too, so if you need to use newer versions of these modules (like Pester 5), you can use this to import the ones we need:
3636

3737
```powershell
38-
.\Install-RequiredModule.ps1
38+
./Install-RequiredModule.ps1
3939
```
4040

4141
#### 3. Run the `build.ps1` script.
4242

43-
By default, the build script uses [gitversion](/gittols/gitversion) to calculate the version of the build automatically:
43+
By default, the build script uses [gitversion](/gittols/gitversion) to calculate the version of the build automatically, and will put the build in a folder like "ModuleBuilder\2.0.0" where 2.0.0 is the current version number.
4444

4545
```powershell
46-
.\build.ps1
46+
./build.ps1
4747
```
4848

49-
If you don't have gitversion handy, you can just specify a version for the `-Semver` parameter:
49+
If you don't have `gitversion` handy, you can just specify a version for the `-Semver` parameter:
5050

5151
```powershell
52-
.\build.ps1 -Semver 2.0.0-beta
52+
./build.ps1 -Semver 2.1.0-beta
5353
```
5454

55-
#### 4. Make the compiled module available to Powershell
55+
#### 4. Run tests with Pester
5656

57-
The `.\build.ps1` process will output the path to the folder named with the current version number, like "1.0.0" -- the compiled psm1 and psd1 files are in that folder. In order for PowerShell to find them when you ask it to import, they need to be in the PSModulePath. PowerShell expects to find modules in a folder with a matching name that sits in one of the folders in your PSModulePath.
58-
59-
Since we cloned the "ModuleBuilder" project into a "ModuleBuilder" folder, the easiest thing to do is just add the parent of the `ModuleBuilder` folder to your PSModulePath. Personally, I keep all my git repos in my user folder at `~\Projects` and I add that to my PSModulePath in my profile script. You could do it temporarily for your current PowerShell session by running this:
57+
The `test.ps1` script runs Pester and ScriptAnalyzer. It finds the build output from our `build.ps1` script in the default build output location -- that is, right next to these scripts in the root of the repository. It actually removes the `ModuleBuilder` module and re-imports the highest version in that root:
6058

6159
```powershell
62-
$Env:PSModulePath += ';' + (Resolve-Path ..)
60+
./test.ps1
6361
```
6462

65-
Alternatively, you could copy the build output to your PSModulePath -- but then you need to start by creating the new "ModuleBuilder" folder to put the version number folder in. You could do that as you build by running something like this instead of just running the `.\build.ps1` script:
63+
If you want to test against a different version, you can import it manually and `Invoke-Pester` yourself.
64+
65+
##### You have a lot of other options here ...
66+
67+
You could import the module explicitly from the output path:
6668

6769
```powershell
68-
$UserModules = Join-Path (Split-Path $Profile.CurrentUserAllHosts) "Modules\ModuleBuilder"
69-
New-Item $UserModules -Type Directory -Force
70-
Copy-Item (.\build.ps1) -Destination $UserModules -Force -Recurse
70+
./build.ps1 | Split-Path | Import-Module -Force
7171
```
7272

73-
You final directory stucture Would look something like this: `C:\Users\Jaykul\Documents\PowerShell\Modules\ModuleBuilder\1.0.0\`
74-
75-
#### 5. Run tests with Pester
73+
You could build into your personal Modules directory, instead:
7674

7775
```powershell
78-
Invoke-Pester
76+
./build -Output ($Profile | Split-Path | Join-Path -ChildPath Modules)
7977
```
80-
Note: If Pester completely fails you likely haven't loaded the module properly. Try running `Import-Module ModuleBuilder` and see step 4.
81-
8278
### What's in the module, so far:
8379

8480
#### `Build-Module`

test.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#requires -Module PowerShellGet, Pester
22
using namespace Microsoft.PackageManagement.Provider.Utility
3+
using namespace System.Management.Automation
34
param(
45
[switch]$SkipScriptAnalyzer,
56
[switch]$SkipCodeCoverage,
@@ -14,22 +15,22 @@ $PSDefaultParameterValues += @{}
1415
$PSDefaultParameterValues["Disabled"] = $true
1516

1617
# Find a built module as a version-numbered folder:
17-
$FullModulePath = Get-ChildItem [0-9]* -Directory | Sort-Object { $_.Name -as [SemanticVersion[]] } |
18+
$FoundModule = Get-ChildItem [0-9]* -Directory | Sort-Object { $_.Name -as [SemanticVersion[]] } |
1819
Select-Object -Last 1 -Ov Version |
1920
Get-ChildItem -Filter "$($ModuleName).psd1"
2021

21-
if (!$FullModulePath) {
22-
throw "Can't find $($ModuleName).psd1 in $($Version.FullName)"
23-
}
22+
if (!$FoundModule) {
23+
throw "Can't find $($ModuleName).psd1 in $($Version.FullName)"
24+
}
2425

2526
$Show = if ($HideSuccess) {
2627
"Fails"
2728
} else {
2829
"All"
2930
}
3031

31-
Remove-Module (Split-Path $ModuleName -Leaf) -ErrorAction Ignore -Force
32-
$ModuleUnderTest = Import-Module $FullModulePath -PassThru -Force -DisableNameChecking -Verbose:$false
32+
Remove-Module $ModuleName -ErrorAction Ignore -Force
33+
$ModuleUnderTest = Import-Module $FoundModule.FullName -PassThru -Force -DisableNameChecking -Verbose:$false
3334
Write-Host "Invoke-Pester for Module $($ModuleUnderTest) version $($ModuleUnderTest.Version)"
3435

3536
if (-not $SkipCodeCoverage) {

0 commit comments

Comments
 (0)