Skip to content

Commit c497ace

Browse files
🩹 [Patch]: Move module import test to general tests (#51)
## Description - Move module import test to general tests, can now be removed from module code. - Remove 'Script filename and function/filter name should match' from common, as its basically a source code test. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 0c1a863 commit c497ace

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

scripts/tests/PSModule/Common.Tests.ps1

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,6 @@ Param(
1111
# These tests are for the whole module and its parts. The scope of these tests are on the src folder and the specific module folder within it.
1212
Describe 'Script files' {
1313
Context 'Module design tests' {
14-
It 'Script filename and function/filter name should match' {
15-
$scriptFiles = @()
16-
17-
Get-ChildItem -Path $Path -Filter '*.ps1' -Recurse -File | ForEach-Object {
18-
$fileContent = Get-Content -Path $_.FullName -Raw
19-
if ($fileContent -match '^(?:function|filter)\s+([a-zA-Z][a-zA-Z0-9-]*)') {
20-
$functionName = $matches[1]
21-
$fileName = $_.BaseName
22-
$relativePath = $_.FullName.Replace($Path, '').Trim('\').Trim('/')
23-
$scriptFiles += @{
24-
fileName = $fileName
25-
filePath = $relativePath
26-
functionName = $functionName
27-
}
28-
}
29-
}
30-
31-
$issues = @('')
32-
$issues += $scriptFiles | Where-Object { $_.filename -ne $_.functionName } | ForEach-Object {
33-
" - $($_.filePath): Function/filter name [$($_.functionName)]. Change file name or function/filter name so they match."
34-
}
35-
$issues -join [Environment]::NewLine |
36-
Should -BeNullOrEmpty -Because 'the script files should be called the same as the function they contain'
37-
}
38-
3914
# It 'Script file should only contain one function or filter' {}
4015
# It 'All script files have tests' {} # Look for the folder name in tests called the same as section/folder name of functions
4116
}

scripts/tests/PSModule/Module.Tests.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ BeforeAll {
1717
}
1818

1919
Describe 'PSModule - Module tests' {
20+
Context 'Module' {
21+
It 'The module should be available' {
22+
Get-Module -Name $moduleName -ListAvailable | Should -Not -BeNullOrEmpty
23+
Write-Verbose (Get-Module -Name $moduleName -ListAvailable | Out-String) -Verbose
24+
}
25+
It 'The module should be importable' {
26+
{ Import-Module -Name $moduleName -Verbose -RequiredVersion 999.0.0 -Force } | Should -Not -Throw
27+
}
28+
}
29+
2030
Context "Module Manifest" {
2131
BeforeAll {
2232
$moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1"
@@ -37,7 +47,4 @@ Describe 'PSModule - Module tests' {
3747
# It 'has a valid icon URL' {}
3848
# It 'has a valid help URL' {}
3949
}
40-
# Context "Root module file" {
41-
# It 'has a root module file' {}
42-
# }
4350
}

scripts/tests/PSModule/SourceCode.Tests.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ BeforeAll {
1717
}
1818

1919
Describe 'PSModule - SourceCode tests' {
20-
2120
Context 'function/filter' {
2221
It 'Script filename and function/filter name should match' {
23-
2422
$scriptFiles = @()
25-
2623
Get-ChildItem -Path $Path -Filter '*.ps1' -Recurse -File | ForEach-Object {
2724
$fileContent = Get-Content -Path $_.FullName -Raw
2825
if ($fileContent -match '^(?:function|filter)\s+([a-zA-Z][a-zA-Z0-9-]*)') {

0 commit comments

Comments
 (0)