File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Pester Tests
2+
3+ on :
4+ pull_request :
5+ branches : [ main ]
6+ paths :
7+ - ' src/**'
8+ - ' .github/workflows/pester-tests.yml'
9+ push :
10+ branches : [ main ]
11+ paths :
12+ - ' src/**'
13+ - ' .github/workflows/pester-tests.yml'
14+
15+ jobs :
16+ test :
17+ runs-on : windows-latest
18+
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+
23+ - name : Install Pester
24+ shell : pwsh
25+ run : |
26+ Set-PSRepository PSGallery -InstallationPolicy Trusted
27+ Install-Module -Name Pester -Force -SkipPublisherCheck
28+
29+ - name : Run Pester Tests
30+ shell : pwsh
31+ run : |
32+ # Import the module
33+ Import-Module ./src/PSBlogger.psd1 -Force
34+
35+ # Configure Pester
36+ $PesterConfig = @{
37+ Run = @{
38+ Path = './src/tests'
39+ }
40+ Output = @{
41+ Verbosity = 'Detailed'
42+ }
43+ TestResult = @{
44+ Enabled = $true
45+ OutputPath = 'TestResults.xml'
46+ OutputFormat = 'NUnitXml'
47+ }
48+ CodeCoverage = @{
49+ Enabled = $true
50+ Path = './src/*.ps*1'
51+ OutputPath = 'coverage.xml'
52+ OutputFormat = 'JaCoCo'
53+ }
54+ }
55+
56+ # Run tests
57+ $Results = Invoke-Pester -Configuration $PesterConfig
58+
59+ # Exit with error code if tests failed
60+ if ($Results.FailedCount -gt 0) {
61+ Write-Error "Tests failed: $($Results.FailedCount) failed out of $($Results.TotalCount) total tests"
62+ exit 1
63+ }
64+
65+ Write-Host "All tests passed: $($Results.PassedCount) out of $($Results.TotalCount) tests"
66+
67+ # - name: Publish Test Results
68+ # uses: dorny/test-reporter@v1
69+ # if: always()
70+ # with:
71+ # name: Pester Tests
72+ # path: TestResults.xml
73+ # reporter: java-junit
74+ # fail-on-error: true
75+
76+ # - name: Upload Test Results
77+ # uses: actions/upload-artifact@v4
78+ # if: always()
79+ # with:
80+ # name: test-results
81+ # path: |
82+ # TestResults.xml
83+ # coverage.xml
84+ # retention-days: 7
You can’t perform that action at this time.
0 commit comments