Skip to content

Commit

Permalink
refr: Refactor test files
Browse files Browse the repository at this point in the history
Remove warnings when importing the PesteExtensions module
  • Loading branch information
petru committed Jul 27, 2022
1 parent 5b65653 commit ffc0af6
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/PesterExtensions/Public/Mock-EnvironmentVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Mock-EnvironmentVariable {

[Parameter(Mandatory = $false)]
[System.EnvironmentVariableTarget]
$Target = [System.EnvironmentVariableTarget]::Process,
$Targets = [EnvironmentVariableTarget]::Process,

[Parameter(Mandatory = $true, Position = 1)]
[ScriptBlock]
Expand Down Expand Up @@ -59,7 +59,7 @@ function Mock-EnvironmentVariable {
.PARAMETER Fixture
The code to be executed.
.PARAMETER Target
.PARAMETER Targets
Specifies that user environment variable should also be managed.
#>
}
6 changes: 3 additions & 3 deletions tests/PesterExtensions/PesterExtensions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ param(
)

BeforeAll {
Import-Module -Name PesterExtensions
Import-Module -Name PesterExtensions -DisableNameChecking
$ModulePath = "$(Get-ScriptPath -Path $PSCommandPath -Extension Manifest)"
Remove-Module -Name PesterExtensions

$script:ModuleInfo = Test-ModuleManifest -Path $ModulePath

Import-Module $ModulePath
Import-Module $ModulePath -DisableNameChecking
$script:ImportedModule = Get-Module 'PesterExtensions'
}

Expand Down Expand Up @@ -73,7 +73,7 @@ Describe 'Check functions' -ForEach @(
Parameters = @(
@{ Parameter = 'Variable'; Mandatory = $true }
@{ Parameter = 'Value'; Mandatory = $false }
@{ Parameter = 'Target'; Mandatory = $false }
@{ Parameter = 'Targets'; Mandatory = $false }
@{ Parameter = 'Fixture'; Mandatory = $true }
)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PesterExtensions/Private/PathUtilities.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BeforeAll {
Import-Module -Name PesterExtensions
Import-Module -Name PesterExtensions -DisableNameChecking
. "$(Get-ScriptPath -Path $PSCommandPath -Extension Script)"
Remove-Module -Name PesterExtensions
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PesterExtensions/Public/Get-ProjectRoot.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BeforeAll {
Import-Module -Name PesterExtensions
Import-Module -Name PesterExtensions -DisableNameChecking
. "$(Get-ScriptPath -Path $PSCommandPath -Extension Script)"
Remove-Module -Name PesterExtensions
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PesterExtensions/Public/Get-ScriptPath.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BeforeAll {
Import-Module -Name PesterExtensions
Import-Module -Name PesterExtensions -DisableNameChecking
. "$(Get-ScriptPath -Path $PSCommandPath -Extension Script)"
Remove-Module -Name PesterExtensions
}
Expand Down
79 changes: 78 additions & 1 deletion tests/PesterExtensions/Public/Mock-EnvironmentVariable.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BeforeAll {
Import-Module -Name PesterExtensions
Import-Module -Name PesterExtensions -DisableNameChecking
. "$(Get-ScriptPath -Path $PSCommandPath)"
Remove-Module -Name PesterExtensions
}
Expand Down Expand Up @@ -96,6 +96,83 @@ Describe 'Check env mocking' -ForEach @(
}
}

# Describe 'Check env mocking' -ForEach @(
# @{
# InitialValue = 'Initial Value';
# MockedValue = 'Mocked Value';
# ValueInsideTheScript = 'Mocked Value';
# TargetsToSet = @([EnvironmentVariableTarget]::Process)
# TargetNotToSet = ''
# Script = { }
# }
# @{
# InitialValue = $null;
# MockedValue = 'Mocked Value';
# ValueInsideTheScript = 'Mocked Value';
# Script = { }
# }
# @{
# InitialValue = 'Initial Value';
# MockedValue = $null;
# ValueInsideTheScript = 'Initial Value';
# Script = { }
# }
# @{
# Script = { }
# }
# @{
# InitialValue = 'Initial Value';
# MockedValue = 'Mocked Value';
# ValueInsideTheScript = 'Mocked Value';
# Script = {
# [Environment]::SetEnvironmentVariable($args[0], 'Some updated value')
# }
# }
# @{
# InitialValue = 'Initial Value';
# MockedValue = $null;
# ValueInsideTheScript = 'Initial Value';
# Script = {
# [Environment]::SetEnvironmentVariable($args[0], 'Some updated value')
# }
# }
# @{
# InitialValue = $null;
# MockedValue = 'Mocked Value';
# ValueInsideTheScript = 'Mocked Value';
# Script = {
# [Environment]::SetEnvironmentVariable($args[0], 'Some updated value')
# }
# }
# @{
# InitialValue = $null;
# MockedValue = $null;
# ValueInsideTheScript = $null;
# Script = {
# [Environment]::SetEnvironmentVariable($args[0], 'Some updated value')
# }
# }
# ) {
# BeforeAll {
# $environmentVariableName = "test_$(New-Guid)"
# [Environment]::SetEnvironmentVariable($environmentVariableName, $InitialValue)
# }
# It 'Test' {
# Mock-EnvironmentVariable `
# -Variable $environmentVariableName `
# -Value $MockedValue {
# [Environment]::GetEnvironmentVariable($environmentVariableName) | Should -Be $ValueInsideTheScript
# Invoke-Command -ScriptBlock $script -ArgumentList $environmentVariableName
# }
# [Environment]::GetEnvironmentVariable($environmentVariableName) | Should -Be $InitialValue
# }
# AfterAll {
# [Environment]::SetEnvironmentVariable($environmentVariableName, $null)
# }
# }



Describe 'Should throw' -ForEach @(
@{
InitialValue = 'Initial Value';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BeforeAll {
Import-Module -Name PesterExtensions
Import-Module -Name PesterExtensions -DisableNameChecking
. "$(Get-ScriptPath -Path $PSCommandPath -Extension Script)"
Remove-Module -Name PesterExtensions
}
Expand Down Expand Up @@ -56,7 +56,7 @@ Describe 'Returns true' {
@{Current = '1.1.1'; Next = '1.2.0' }
@{Current = '1.1.1'; Next = '2.0.0' }
) {
Test-SemanticVersionUpdate -Current $Current -Next $Next | Should -BeTrue
Test-SemanticVersionUpdate -current $Current -Next $Next | Should -BeTrue
}
}

Expand Down Expand Up @@ -1392,6 +1392,6 @@ Describe 'Returns false' {
@{ Current = '5.5.5'; Next = '10.10.10' }

) {
Test-SemanticVersionUpdate -Current $Current -Next $Next | Should -BeFalse
Test-SemanticVersionUpdate -current $Current -Next $Next | Should -BeFalse
}
}

0 comments on commit ffc0af6

Please sign in to comment.