Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions TestingHelperTest/public/NewModule_operations.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
48 changes: 48 additions & 0 deletions private/templates/template.v2.test.ps1
Original file line number Diff line number Diff line change
@@ -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
)


Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace

Line has trailing whitespace
if ($Version) {
$V = $Version.Split('-')
$semVer = $V[0]
$AllowPrerelease = ($AllowPrerelease -or ($null -ne $V[1]))
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace

Line has trailing whitespace
$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
2 changes: 1 addition & 1 deletion public/New-ModuleV2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down