Skip to content

[Issue]: Add Pester tests for dev-tools and extension scripts (4 scripts) #200

@WilliamBerryiii

Description

@WilliamBerryiii

Summary

Create unit tests for the developer tools and extension packaging PowerShell scripts.

Parent Issue: #190

Requirements

Create test files:

  • scripts/tests/dev-tools/Generate-PrReference.Tests.ps1
  • scripts/tests/extension/Package-Extension.Tests.ps1
  • scripts/tests/extension/Prepare-Extension.Tests.ps1
  • scripts/tests/lib/Get-VerifiedDownload.Tests.ps1

Implementation Details

Scripts Under Test

Script Purpose Key Testing Areas
Generate-PrReference.ps1 PR reference generation Git command mocking, output formatting
Package-Extension.ps1 Extension packaging VSCE invocation, file validation
Prepare-Extension.ps1 Extension preparation Dependency resolution, file copying
Get-VerifiedDownload.ps1 Verified file downloads HTTP mocking, checksum validation

Test Pattern for Dev Tools

Describe 'Generate-PrReference.ps1' {
    BeforeAll {
        . $PSScriptRoot/../../dev-tools/Generate-PrReference.ps1
    }

    Context 'Git Integration' {
        BeforeEach {
            Mock git {
                switch ($args[0]) {
                    'log' { return 'abc123 feat: add feature' }
                    'branch' { return '* main' }
                    'remote' { return 'origin' }
                }
            }
        }

        It 'Should generate PR reference from commits' {
            $result = New-PrReference -Branch 'feature/test'
            $result | Should -Not -BeNullOrEmpty
        }
    }
}

Test Pattern for Extension Scripts

Describe 'Package-Extension.ps1' {
    Context 'VSCE Integration' {
        BeforeEach {
            Mock Test-Path { return $true }
            Mock vsce { return 'Packaged: extension-1.0.0.vsix' }
        }

        It 'Should invoke vsce package command' {
            Invoke-PackageExtension -OutputPath './dist'
            Should -Invoke vsce -Times 1
        }
    }

    Context 'Validation' {
        It 'Should fail if package.json missing' {
            Mock Test-Path { return $false } -ParameterFilter { 
                $Path -match 'package.json' 
            }
            { Invoke-PackageExtension } | Should -Throw '*package.json*'
        }
    }
}

Test Pattern for Verified Downloads

Describe 'Get-VerifiedDownload.ps1' {
    Context 'Checksum Validation' {
        BeforeEach {
            Mock Invoke-WebRequest {
                return @{ Content = [byte[]]@(1,2,3,4) }
            }
            Mock Get-FileHash {
                return @{ Hash = 'ABC123' }
            }
        }

        It 'Should verify downloaded file hash' {
            $result = Get-VerifiedDownload -Url 'https://example.com/file' `
                -ExpectedHash 'ABC123'
            $result.Verified | Should -BeTrue
        }

        It 'Should fail on hash mismatch' {
            $result = Get-VerifiedDownload -Url 'https://example.com/file' `
                -ExpectedHash 'WRONG'
            $result.Verified | Should -BeFalse
        }
    }
}

Acceptance Criteria

  • Test file exists for each of the 4 scripts
  • Git command mocking tests for PR reference
  • VSCE integration tests for packaging
  • HTTP request mocking for downloads
  • Checksum validation tests
  • Error handling for missing dependencies

Dependencies

Estimated Effort

2-3 hours


Additional Context

Target Scripts

  • scripts/dev-tools/Generate-PrReference.ps1
  • scripts/extension/Package-Extension.ps1
  • scripts/extension/Prepare-Extension.ps1
  • scripts/lib/Get-VerifiedDownload.ps1

External Dependencies

These scripts may depend on:

  • Git CLI
  • VSCE (VS Code Extension CLI)
  • Network access

All external dependencies should be mocked in 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