Tests/Manifest.Tests.ps1


# Write-Host "
# ModulePath: $ModulePath
# ModuleName: $ModuleName
# ManifestPath: $ManifestPath
# $(Get-childitem $ManifestPath)
# "

# test the module manifest - exports the right functions, processes the right formats, and is generally correct
Describe "Manifest" {
    $ModulePath = Split-Path -Parent $MyInvocation.MyCommand.Path
    $ModuleName = "PSModuleBuilder"

    $ManifestPath = (Get-ChildItem "$ModulePath\..\$ModuleName.psd1").FullName

    $ManifestHash = Invoke-Expression (Get-Content $ManifestPath -Raw)
    Write-Host $ManifestPath
    
    It "has a valid manifest" {
        Test-ModuleManifest (Get-ChildItem "$ModulePath\..\$ModuleName.psd1").FullName -ErrorAction Stop -WarningAction SilentlyContinue | Should -Be "Good"
    }
    
    It "has a valid root module" {
        $ManifestHash.RootModule | Should -Be "$ModuleName.psm1"
    }

    It "has a valid Description" {
        $ManifestHash.Description | Should -Not -BeNullOrEmpty
    }

    It "has a valid guid" {
        $ManifestHash.Guid | Should -Be 'ce7c4a02-ccd4-4b8b-8cbe-821308e3ac81'
    }

    It "has a valid prefix" {
        $ManifestHash.DefaultCommandPrefix | Should -Not -BeNullOrEmpty
    }

    It "has a valid copyright" {
        $ManifestHash.CopyRight | Should -Not -BeNullOrEmpty
    }

    It "exports all public functions" {
        $ExFunctions = $ManifestHash.FunctionsToExport
        $FunctionFiles = Get-ChildItem "$ModulePath\Public" -Filter *.ps1 -Exclude *.Tests.ps1 | Select-Object -ExpandProperty BaseName
        $FunctionNames = $FunctionFiles
        foreach ($FunctionName in $FunctionNames)
        {
            $ExFunctions -contains $FunctionName | Should -Be $true
        }
    }
}