diff --git a/TestingHelperTest/public/NewModule_operations.Tests.ps1 b/TestingHelperTest/public/NewModule_operations.Tests.ps1 index 2fdd3c4..29d6105 100644 --- a/TestingHelperTest/public/NewModule_operations.Tests.ps1 +++ b/TestingHelperTest/public/NewModule_operations.Tests.ps1 @@ -51,19 +51,32 @@ function TestingHelperTest_Manual_Work_Testing{ # Run tests - $result = Invoke-TestingHelper -Path $modulePath + $result = Invoke-TT_TestingHelper -Path $modulePath Assert-AreEqual -Expected 2 -Presented $result.Tests Assert-AreEqual -Expected 2 -Presented $result.Pass } -function TestingHelperTest_Manual_Work_Testing{ +function TestingHelperTest_Manual_Work_Testing_2{ + + $moduleName = "modulename_{0}" -f (New-Guid).ToString().Substring(0,8) + + $result = New-TT_ModuleV3 -Name $moduleName -AddTesting + + $result = Invoke-TT_TestingHelper -Path $result + Assert-AreEqual -Expected 2 -Presented $result.Tests + Assert-AreEqual -Expected 2 -Presented $result.Pass +} + +function TestingHelperTest_Manual_Work_Testing_3{ $moduleName = "modulename_{0}" -f (New-Guid).ToString().Substring(0,8) $result = New-TT_ModuleV3 -Name $moduleName -AddTesting - $result = Invoke-TestingHelper -Path $result + $newName = rename-item -Path $result -NewName "NewName" -PassThru + + $result = Invoke-TT_TestingHelper -Path $newName Assert-AreEqual -Expected 2 -Presented $result.Tests Assert-AreEqual -Expected 2 -Presented $result.Pass } \ No newline at end of file diff --git a/private/templates/template.v2.test.ps1 b/private/templates/template.v2.test.ps1 new file mode 100644 index 0000000..c296ec0 --- /dev/null +++ b/private/templates/template.v2.test.ps1 @@ -0,0 +1,48 @@ +<# +.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 () + +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 -Version "3.0.10-preview" + +# Run test by PSD1 file +Test-ModulelocalPSD1 diff --git a/public/New-ModuleV2.ps1 b/public/New-ModuleV2.ps1 index 9179af6..5837185 100644 --- a/public/New-ModuleV2.ps1 +++ b/public/New-ModuleV2.ps1 @@ -103,7 +103,7 @@ function New-ModuleV2 { New-ModuleV2 @testingparams # test.ps1 - Import-Template -Path $modulePath -File "test.ps1" -Template "template.test.ps1" + Import-Template -Path $modulePath -File "test.ps1" -Template "template.v2.test.ps1" # launch.json Import-Template -Path ($modulePath | Join-Path -ChildPath '.vscode') -File 'launch.json' -Template "template.launch.json" diff --git a/test.ps1 b/test.ps1 index 811850f..2a9c955 100644 --- a/test.ps1 +++ b/test.ps1 @@ -91,7 +91,7 @@ function Import-RequiredModule{ $AllowPrerelease = ($AllowPrerelease -or ($null -ne $V[1])) } - $module = Import-Module $ModuleName -PassThru -ErrorAction SilentlyContinue -MinimumVersion:$semVer + $module = Import-Module $ModuleName -PassThru -ErrorAction SilentlyContinue -MinimumVersion:$semVer -MaximumVersion:$semVer if ($null -eq $module) { "Installing module Name[{0}] Version[{1}] AllowPrerelease[{2}]" -f $ModuleName, $ModuleVersion, $AllowPrerelease | Write-Host -ForegroundColor DarkGray @@ -132,7 +132,7 @@ function Get-RequiredModule{ # Install and load TestingHelper # Import-RequiredModule -Name TestingHelper -AllowPrerelease -Import-RequiredModule "TestingHelper" -AllowPrerelease +Import-RequiredModule "TestingHelper" -AllowPrerelease -ModuleVersion "3.0.10-preview" # Install and Load Module dependencies Get-RequiredModule | Import-RequiredModule -AllowPrerelease