microsoft/hve-core

Public

mirrored from https://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
feat/580-dt-start-project

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/tests/pester.config.ps1

95lines · modecode

1#!/usr/bin/env pwsh
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: MIT
4#
5# pester.config.ps1
6#
7# Purpose: Pester 5.x configuration for HVE-Core PowerShell testing
8# Author: HVE Core Team
9#
10
11[CmdletBinding()]
12param(
13 [Parameter()]
14 [switch]$CI,
15
16 [Parameter()]
17 [switch]$CodeCoverage,
18
19 [Parameter()]
20 [string[]]$TestPath = @("$PSScriptRoot")
21)
22
23$configuration = New-PesterConfiguration
24
25# Run configuration
26$configuration.Run.Path = @($TestPath)
27$configuration.Run.Exit = $CI.IsPresent
28$configuration.Run.PassThru = $true
29$configuration.Run.TestExtension = '.Tests.ps1'
30
31# Filter configuration
32$configuration.Filter.ExcludeTag = @('Integration', 'Slow')
33
34# Output configuration
35$configuration.Output.Verbosity = if ($CI.IsPresent) { 'Normal' } else { 'Detailed' }
36$configuration.Output.CIFormat = if ($CI.IsPresent) { 'GithubActions' } else { 'Auto' }
37$configuration.Output.CILogLevel = 'Error'
38
39# Test result configuration (NUnit XML for CI artifact upload)
40$configuration.TestResult.Enabled = $CI.IsPresent
41$configuration.TestResult.OutputFormat = 'NUnitXml'
42$configuration.TestResult.OutputPath = Join-Path $PSScriptRoot '../../logs/pester-results.xml'
43$configuration.TestResult.TestSuiteName = 'HVE-Core-PowerShell-Tests'
44
45# Code coverage configuration
46if ($CodeCoverage.IsPresent) {
47 $configuration.CodeCoverage.Enabled = $true
48 $configuration.CodeCoverage.OutputFormat = 'JaCoCo'
49 $configuration.CodeCoverage.OutputPath = Join-Path $PSScriptRoot '../../logs/coverage.xml'
50
51 # Resolve coverage paths explicitly - Join-Path with wildcards returns literal paths without file system expansion in Pester configuration
52 $scriptRoot = Split-Path $PSScriptRoot -Parent
53 $coverageDirs = @('linting', 'security', 'dev-tools', 'lib', 'extension', 'plugins')
54
55 $coveragePaths = $coverageDirs | ForEach-Object {
56 Get-ChildItem -Path (Join-Path $scriptRoot $_) -Include '*.ps1', '*.psm1' -Recurse -File -ErrorAction SilentlyContinue
57 } | Where-Object {
58 $_.FullName -notmatch '\.Tests\.ps1$'
59 } | Select-Object -ExpandProperty FullName
60
61 # Resolve skill script coverage paths from repo root
62 $repoRoot = Split-Path $scriptRoot -Parent
63 $skillsPath = Join-Path $repoRoot '.github/skills'
64 if (Test-Path $skillsPath) {
65 $skillCoveragePaths = Get-ChildItem -Path $skillsPath -Directory -ErrorAction SilentlyContinue | ForEach-Object {
66 $skillRoot = $_.FullName
67 $skillScripts = Join-Path $skillRoot 'scripts'
68 $paths = @()
69
70 $paths += Get-ChildItem -Path $skillRoot -Include '*.ps1', '*.psm1' -File -ErrorAction SilentlyContinue
71
72 if (Test-Path $skillScripts) {
73 $paths += Get-ChildItem -Path $skillScripts -Include '*.ps1', '*.psm1' -Recurse -File -ErrorAction SilentlyContinue
74 }
75
76 $paths
77 } | Where-Object { $_.FullName -notmatch '\.Tests\.ps1$' } |
78 Select-Object -ExpandProperty FullName
79 if ($skillCoveragePaths) {
80 $coveragePaths = @($coveragePaths) + @($skillCoveragePaths)
81 }
82 }
83
84 if ($coveragePaths.Count -gt 0) {
85 $configuration.CodeCoverage.Path = $coveragePaths
86 }
87
88 $configuration.CodeCoverage.ExcludeTests = $true
89 $configuration.CodeCoverage.CoveragePercentTarget = 80
90}
91
92# Should configuration
93$configuration.Should.ErrorAction = 'Stop'
94
95return $configuration
96