Skip to content

♻️ refactor(vscode): improve Export-VSCodeProfiles robustness and add Pester tests - #32

Open
chriskyfung wants to merge 4 commits into
masterfrom
refactor/export-vscode-profiles-scripts
Open

♻️ refactor(vscode): improve Export-VSCodeProfiles robustness and add Pester tests#32
chriskyfung wants to merge 4 commits into
masterfrom
refactor/export-vscode-profiles-scripts

Conversation

@chriskyfung

Copy link
Copy Markdown
Owner

This PR refactors Export-VSCodeProfiles.ps1 to be more robust, configurable, and testable, and adds a Pester test suite covering the new behavior.

Changes

VSCode/Export-VSCodeProfiles.ps1

  • New parameters-OutputDirectory and -VSCodeUserDataPath allow customizing the export destination and VS Code user data location
  • Full -WhatIf support — every operation is wrapped in $PSCmdlet.ShouldProcess() via SupportsShouldProcess
  • Prerequisite validation — fails fast with clear, actionable messages when the user data directory, storage.json, or the code CLI is missing
  • RobustnessSet-StrictMode, $ErrorActionPreference = 'Stop', $LASTEXITCODE checks, per-profile error handling that warns and skips instead of aborting the whole export, and Join-Path/Get-Content -Raw throughout
  • Improved profile discovery — deduplicates the "Default" profile and warns when no additional profiles are found
  • Updated comment-based help — documents the new parameters and examples

Tests/VSCode/Export-VSCodeProfiles.Tests.ps1 (new)

  • Pester tests for parameter validation, prerequisite checks, profile discovery, and -WhatIf behavior
  • Uses isolated temp directories and Get-Command mocks so tests never touch real VS Code data

Testing

Invoke-Pester Tests/VSCode/Export-VSCodeProfiles.Tests.ps1

- Convert script to functional structure
- Add comprehensive error handling and validation
- Implement -WhatIf support for dry runs
- Improve logging with helper functions
- Standardize path handling using Join-Path
- Convert function-based flow to begin/process/end
- Implement native ShouldProcess for WhatIf support
- Add parameter validation for output and data paths
- Streamline profile discovery and extension export
- Improve error handling and logging consistency
- Replace script-scoped variables with locals
- Add explicit PowerShell version requirements
- Improve profile discovery and error handling
- Move validation logic into the process block
- Standardize error reporting and flow control
@chriskyfung chriskyfung self-assigned this Aug 2, 2026
@chriskyfung chriskyfung added the enhancement New feature or request label Aug 2, 2026
@chriskyfung chriskyfung moved this to 👀 In review in PowerShell projects Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

1 participant