tests/general/manifest.Tests.ps1

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
Describe "Validating the module manifest" {
    $moduleRoot = (Resolve-Path "$PSScriptRoot\..\..").Path
    $manifest = ((Get-Content "$moduleRoot\PSFramework.psd1") -join "`n") | Invoke-Expression
    [version]$moduleVersion = Get-Item "$moduleRoot\PSFramework.psm1" | Select-String -Pattern '\$script:PSModuleVersion = "(.*?)"' | ForEach-Object { $_.Matches[0].Groups[1].Value }
    Context "Basic resources validation" {
        It "Exports all functions in the public folder" {
            $files = Get-ChildItem "$moduleRoot\functions" -Recurse -File -Filter "*.ps1"
            $count = (Compare-Object -ReferenceObject $files.BaseName -DifferenceObject $manifest.FunctionsToExport).Count
            $count | Should be 0
        }
        
        It "Exports none of its internal functions" {
            $files = Get-ChildItem "$moduleRoot\internal\functions" -Recurse -File -Filter "*.ps1"
            $files | Where-Object BaseName -In $manifest.FunctionsToExport | Should Be $null
        }
        
        It "Has the same version as the psm1 file" {
            ([version]$manifest.ModuleVersion) | Should Be $moduleVersion
        }
    }
    
    Context "Individual file validation" {
        It "The root module file exists" {
            Test-Path "$moduleRoot\$($manifest.RootModule)" | Should Be $true
        }
        
        foreach ($format in $manifest.FormatsToProcess)
        {
            It "The file $format should exist" {
                Test-Path "$moduleRoot\$format" | Should Be $true
            }
        }
        
        foreach ($type in $manifest.TypesToProcess)
        {
            It "The file $type should exist" {
                Test-Path "$moduleRoot\$type" | Should Be $true
            }
        }
        
        foreach ($assembly in $manifest.RequiredAssemblies)
        {
            It "The file $assembly should exist" {
                Test-Path "$moduleRoot\$assembly" | Should Be $true
            }
        }
    }
}