Tests/PSGalleryDemo.Tests.ps1
$module = "PSGalleryDemo" $moduleRoot = Split-Path -Parent $PSScriptRoot $repository = "PSGallery" Describe "$module Module Structure" -Tag ModuleFormat { Context "Module File Exists" { It "Has a root module $module.psm1" { "$moduleRoot\$module.psm1" | Should -Exist } It "Has a manifest file of $module.psd1" { "$moduleRoot\$module.psd1" | Should -Exist "$moduleRoot\$module.psd1" | Should -FileContentMatch "$module.psm1" } } Context "Test Manifest Results" { $stagedModule = Test-ModuleManifest -Path "$moduleroot\$module.psd1" #publishedModule = Find-Module -Name $module -Repository $repository It "Has a module manifest that matches expected module name" { $stagedModule.Name | Should -Be $module } It "Has at least 1 exported command" { $stagedModule.ExportedCommands.Count | Should -BeGreaterThan 0 } It "Has a formatted semver version" { $stagedModule.Version | Should -Match "(^(([0-9]+)\.([0-9]+)\.([0-9]+)?)$)" -Because "version format should match semver guidelines of Major.Minor.Patch, e.g. 1.5.12" } # It "Has a version greater than published" { # $stagedModule.Version | Should -BeGreaterThan $publishedModule.Version # } } } Import-Module $moduleRoot\$module.psm1 -Force Describe "Get-Something" { It "Should return 'Got something'" { Get-Something | Should -Be 'Got something' } It "Should be a string" { Get-Something | Should -BeOfType System.String } } Describe "Set-Something" { It "Should return 'Set something'" { Set-Something | Should -Be 'Set something' } It "Should be a tring" { Set-Something | Should -BeOfType System.String } } Describe "Test-Something" { It "Should return 'Tested something" { Test-Something | Should -Be 'Tested something' } It "Should be a string" { Test-Something | Should -BeOfType System.String } } Describe "Get-Hello" { It "Should have a parameter Name" { Get-Command -Name Get-Hello | Should -HaveParameter "Name" -Type String -DefaultValue "World" } It "Should return 'Hello, World'" { Get-Hello | Should -Match 'Hello, World' } It "Should return 'Hello, ' and string parameter" { Get-Hello -Name Jeff | Should -Match 'Hello, Jeff' } } |