DefaultTests.json

{
    "DefaultTests":[{
        "Module": {
            "Content": "#region variables\r\n$ModuleName = ($MyInvocation.MyCommand.Name).Substring(0, ($MyInvocation.MyCommand.Name).IndexOf(\".tests.ps1\"))\r\n\r\n$TestsFolderPath = Split-Path $MyInvocation.MyCommand.path\r\n\r\nSet-Location $TestsFolderPath\r\nSet-Location \u0027..\\\u0027\r\n\r\n#Params for Module file\r\n$ModuleFileName = \"$ModuleName.psm1\"\r\n$ModuleFileParams = @{\r\n name = $ModuleFileName\r\n path = \".\\$ModuleFileName\"\r\n}\r\n\r\n#Params for Manifest file\r\n$ManifestFileName = \"$ModuleName.psd1\"\r\n$manifestFileParams = @{\r\n name = $ManifestFileName\r\n path = \".\\$ManifestFileName\"\r\n}\r\n\r\n#Params for test file\r\n$TestFileName = \"$ModuleName.tests.ps1\"\r\n$TestFileParams = @{\r\n name = $TestFileName\r\n path = \".\\Tests\\$TestFileName\"\r\n}\r\n\r\n#endregion\r\n\r\n\u003c#\r\n.Synopsis\r\n Test a script with PowerShellScriptAnalyzer and Pester\r\n.DESCRIPTION\r\n Takes a name and path as parameters and does standard PowerShellScriptAnalyzer tests with Pester\r\n.EXAMPLE\r\n Test-SciptAnalyzer -Name PowerShellScript.ps1 -Path .\\PowerShellScript.ps1\r\n.FUNCTIONALITY\r\n Pester PowerShellScriptAnalyzer\r\n#\u003e\r\nFunction Test-SciptAnalyzer {\r\n param(\r\n [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][String]$Name,\r\n [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][String]$Path\r\n )\r\n\r\n $analysis = Invoke-ScriptAnalyzer -Path $Path\r\n $scriptAnalyzerRules = Get-ScriptAnalyzerRule\r\n\r\n forEach ($rule in $scriptAnalyzerRules) {\r\n It \"Should pass $rule\" {\r\n If ($analysis.RuleName -contains $rule) {\r\n $analysis | Where-Object RuleName -EQ $rule -outvariable failures | Out-Default\r\n $failures.Count | Should Be 0\r\n }\r\n }\r\n }\r\n}\r\n\r\nDescribe \"Verify $ModuleName Files\" {\r\n\r\n Context \"Verify minimum version of Pester\" {\r\n It \"Should be at least 4\" {\r\n ((Get-Module -Name Pester).Version.Major -ge 4)| Should be $true\r\n }\r\n }\r\n \r\n Context \"Testing $ModuleFileName against PowerShellScriptAnalyzer rules\" {\r\n Test-SciptAnalyzer @ModuleFileParams\r\n }\r\n\r\n Context \"Testing $ManifestFileName against PowerShellScriptAnalyzer rules\" {\r\n Test-SciptAnalyzer @manifestFileParams\r\n } \r\n \r\n Context \"Testing $TestFileName against PowerShellScriptAnalyzer rules\" {\r\n Test-SciptAnalyzer @TestFileParams\r\n }\r\n\r\n Context \"PowerShell Manifest tests\" {\r\n \r\n $ModuleManifestPath = \".\\$ManifestFileName\"\r\n $Manifest = Import-PowerShellDataFile -Path $ModuleManifestPath \r\n \r\n it \"Must have the root module fullfilled\" {\r\n $Manifest.rootmodule | should not benullorempty\r\n }\r\n\r\n it \"Must have the author key fullfilled\" {\r\n $Manifest.Author | should not benullorempty\r\n }\r\n\r\n it \"Must have the description key fullfilled\" {\r\n $Manifest.Description | should not benullorempty\r\n }\r\n\r\n it \"Must have the company name key fullfilled\" {\r\n $Manifest.CompanyName | should not benullorempty\r\n }\r\n\r\n it \"Must have version key fullfilled\" {\r\n $Manifest.ModuleVersion | should not benullorempty\r\n }\r\n\r\n it \u0027Must pass the Test-ModuleManifest Validation\u0027 {\r\n Test-ModuleManifest -Path $ModuleManifestPath | should be $true\r\n }\r\n\r\n }\r\n}"
        },
        "Script":{
            "Content": "$ScriptName = ($MyInvocation.MyCommand.Name).Substring(0, ($MyInvocation.MyCommand.Name).IndexOf(\".tests.ps1\"))\r\n\r\n$TestsFolderPath = Split-Path $MyInvocation.MyCommand.path\r\n\r\nSet-Location $TestsFolderPath\r\n\r\n#Params for Module file\r\n$ScriptFileName = \"$ScriptName.ps1\"\r\n$ScriptFileParams = @{\r\nname = $ScriptFileName\r\npath = \".\\$ScriptFileName\"\r\n}\r\n\r\n#Params for test file\r\n$TestFileName = \"$ScriptName.tests.ps1\"\r\n$TestFileParams = @{\r\nname = $TestFileName\r\npath = \".\\$TestFileName\"\r\n}\r\n\r\n#endregion\r\n\r\n\u003c#\r\n.Synopsis\r\n Test a script with PowerShellScriptAnalyzer and Pester\r\n.DESCRIPTION\r\n Takes a name and path as parameters and does standard PowerShellScriptAnalyzer tests with Pester\r\n.EXAMPLE\r\n Test-SciptAnalyzer -Name PowerShellScript.ps1 -Path .\\PowerShellScript.ps1\r\n.FUNCTIONALITY\r\n Pester PowerShellScriptAnalyzer\r\n#\u003e\r\nFunction Test-SciptAnalyzer {\r\nparam(\r\n [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][String]$Name,\r\n [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][String]$Path\r\n)\r\n\r\nDescribe \"Verify $Name Files\" {\r\n\r\nContext \"Verify minimum version of Pester\" {\r\n It \"Should be at least 4\" {\r\n ((Get-Module -Name Pester).Version.Major -ge 4)| Should be $true\r\n }\r\n }\r\n \r\n Context \u0027PowerShellScriptAnalyzer Standard Rules\u0027 {\r\n\r\n $analysis = Invoke-ScriptAnalyzer -Path $Path\r\n $scriptAnalyzerRules = Get-ScriptAnalyzerRule\r\n\r\n forEach ($rule in $scriptAnalyzerRules) {\r\n It \"Should pass $rule\" {\r\n If ($analysis.RuleName -contains $rule) {\r\n $analysis | Where-Object RuleName -EQ $rule -outvariable failures | Out-Default\r\n $failures.Count | Should Be 0\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n}\r\n\r\nTest-SciptAnalyzer @ScriptFileParams\r\nTest-SciptAnalyzer @TestFileParams"
        }
    }]
}