-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ps1
More file actions
50 lines (42 loc) · 1.34 KB
/
test.ps1
File metadata and controls
50 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<#
.SYNOPSIS
Run tests
.DESCRIPTION
Run the unit test of the actual module
.NOTES
Using TestingHelper this script will search for a Test module and run the tests
This script will be referenced from launch.json to run the tests on VSCode
.LINK
https://raw.githubusercontent.com/rulasg/DemoPsModule/main/test.ps1
.EXAMPLE
> ./test.ps1
#>
[CmdletBinding()]
param (
#Switch ShowTestErrors
[Parameter()][switch]$ShowTestErrors
)
function Import-TestingHelper{
[CmdletBinding()]
param (
[Parameter()][string]$Version,
[Parameter()][switch]$AllowPrerelease,
[Parameter()][switch]$PassThru
)
if ($Version) {
$V = $Version.Split('-')
$semVer = $V[0]
$AllowPrerelease = ($AllowPrerelease -or ($null -ne $V[1]))
}
$module = Import-Module TestingHelper -PassThru -ErrorAction SilentlyContinue -RequiredVersion:$semVer
if ($null -eq $module) {
$installed = Install-Module -Name TestingHelper -Force -AllowPrerelease:$AllowPrerelease -passThru -RequiredVersion:$Version
$module = Import-Module -Name $installed.Name -RequiredVersion ($installed.Version.Split('-')[0]) -Force -PassThru
}
if ($PassThru) {
$module
}
}
Import-TestingHelper -AllowPrerelease
# Run test by PSD1 file
Invoke-TestingHelper -ShowTestErrors:$ShowTestErrors