Skip to content

[Issue]: Add Pester tests for LintingHelpers.psm1 module #196

@WilliamBerryiii

Description

@WilliamBerryiii

Summary

Create comprehensive unit tests for LintingHelpers.psm1, the shared module containing helper functions used by multiple linting scripts.

Parent Issue: #190

Requirements

  • Create scripts/tests/Modules/LintingHelpers.Tests.ps1
  • Test all exported functions from LintingHelpers.psm1
  • Use Pester 5.x syntax with Describe/Context/It blocks
  • Mock filesystem and external dependencies
  • Achieve minimum 80% code coverage for the module

Implementation Details

Target Functions

Based on research analysis, LintingHelpers.psm1 likely exports:

  • Path resolution helpers
  • Result formatting functions
  • Common validation utilities
  • JSON/output serialization helpers

Test Structure

BeforeAll {
    # Import module under test
    $ModulePath = Join-Path $PSScriptRoot '../../linting/Modules/LintingHelpers.psm1'
    Import-Module $ModulePath -Force
}

Describe 'LintingHelpers Module' {
    Context 'Module Structure' {
        It 'Should export expected functions' {
            $module = Get-Module LintingHelpers
            $module.ExportedFunctions.Keys | Should -Contain 'Get-ExpectedFunction'
        }
    }

    Context 'Function-Name' {
        It 'Should handle valid input' {
            # Arrange
            $input = 'test-value'
            
            # Act
            $result = Get-FunctionName -Input $input
            
            # Assert
            $result | Should -Be 'expected-output'
        }

        It 'Should handle edge cases' {
            # Test empty input, null, special characters, etc.
        }
    }
}

AfterAll {
    Remove-Module LintingHelpers -ErrorAction SilentlyContinue
}

Mocking Patterns

BeforeEach {
    # Mock filesystem operations
    Mock Test-Path { return $true }
    Mock Get-Content { return '{"key": "value"}' }
    
    # Mock external commands if needed
    Mock Invoke-ExternalTool { return @{ Success = $true } }
}

Acceptance Criteria

  • Test file exists at scripts/tests/Modules/LintingHelpers.Tests.ps1
  • All exported functions have corresponding test coverage
  • Tests use proper Pester 5.x syntax
  • Mocks isolate tests from filesystem/external dependencies
  • Tests pass in CI environment (ubuntu-latest)
  • Code coverage >= 80% for module

Dependencies

Estimated Effort

2-3 hours


Additional Context

Target File

  • scripts/linting/Modules/LintingHelpers.psm1 - Module under test

Why Module Tests First

Testing the shared module first:

  1. Establishes mocking patterns for dependent scripts
  2. Validates test infrastructure with simpler target
  3. Provides reusable test helpers for script tests

Related Issues

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions