-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
Description
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.ps1scripts/tests/extension/Package-Extension.Tests.ps1scripts/tests/extension/Prepare-Extension.Tests.ps1scripts/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
- [Issue]: Add Pester test infrastructure (config, directories, shared mocks) #193 (infrastructure) for test directory structure
Estimated Effort
2-3 hours
Additional Context
Target Scripts
scripts/dev-tools/Generate-PrReference.ps1scripts/extension/Package-Extension.ps1scripts/extension/Prepare-Extension.ps1scripts/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
- Depends on: [Issue]: Add Pester test infrastructure (config, directories, shared mocks) #193 (infrastructure)
- Parent: [Issue]: Add Pester unit testing framework for PowerShell scripts #190