Skip to content

Commit b0c8fee

Browse files
committed
feat(vscode, tests): ✨ Add new PowerShell debug configurations and enhance psake file
* Introduced two new launch configurations for debugging PowerShell scripts in VSCode. * Updated `psakeFile.ps1` to correct property casing and added functionality to control documentation overwrite behavior. * Enhanced tests to verify the documentation overwrite feature.
1 parent 2fba489 commit b0c8fee

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

.vscode/launch.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,35 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Run Build and Debug (Temp Console)",
9+
"type": "PowerShell",
10+
"request": "launch",
11+
"script": "${cwd}/build.ps1",
12+
"args": [
13+
"-Task Test",
14+
"-Verbose"
15+
],
16+
"cwd": "${workspaceFolder}",
17+
"createTemporaryIntegratedConsole": true
18+
},
19+
{
20+
"name": "Run Build and Debug",
21+
"type": "PowerShell",
22+
"request": "launch",
23+
"script": "${cwd}/build.ps1",
24+
"args": [
25+
"-Task Test",
26+
"-Verbose"
27+
],
28+
"cwd": "${workspaceFolder}",
29+
"createTemporaryIntegratedConsole": true
30+
},
731
{
832
"name": "PowerShell: Interactive Session",
933
"type": "PowerShell",
1034
"request": "launch",
1135
"cwd": ""
1236
}
1337
]
14-
}
38+
}

tests/TestModule/psakeFile.ps1

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Import-Module ../../Output/PowerShellBuild -Force
22

3-
properties {
3+
Properties {
44
# Pester can build the module using both scenarios
55
if (Test-Path -Path 'Variable:\PSBuildCompile') {
66
$PSBPreference.Build.CompileModule = $global:PSBuildCompile
@@ -15,21 +15,26 @@ properties {
1515
$PSBPreference.Build.Exclude = ('excludeme.txt', 'excludemealso*', 'dontcopy')
1616

1717
# If compiling, insert headers/footers for entire PSM1 and for each inserted function
18-
$PSBPreference.Build.CompileHeader = '# Module Header' + [Environment]::NewLine
19-
$PSBPreference.Build.CompileFooter = '# Module Footer'
18+
$PSBPreference.Build.CompileHeader = '# Module Header' + [Environment]::NewLine
19+
$PSBPreference.Build.CompileFooter = '# Module Footer'
2020
$PSBPreference.Build.CompileScriptHeader = '# Function header'
2121
$PSBPreference.Build.CompileScriptFooter = '# Function footer' + [Environment]::NewLine
2222

2323
# So Pester InModuleScope works
24-
$PSBPreference.Test.ImportModule = $true
25-
$PSBPreference.Test.CodeCoverage.Enabled = $true
24+
$PSBPreference.Test.ImportModule = $true
25+
$PSBPreference.Test.CodeCoverage.Enabled = $true
2626
$PSBPreference.Test.CodeCoverage.Threshold = 0.0
2727
$PSBPreference.Test.CodeCoverage.OutputFile = 'cc.xml'
2828

2929
# Override the default output directory
3030
$PSBPreference.Build.OutDir = 'Output'
31+
32+
# Don't overwrite the docs
33+
$PSBPreference.Docs.Overwrite = $false
3134
}
3235

33-
task default -depends Build
36+
Task default -depends Build
37+
38+
Task Build -FromModule PowerShellBuild -minimumVersion 0.5.0
39+
3440

35-
task Build -FromModule PowerShellBuild -minimumVersion 0.5.0

tests/build.tests.ps1

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Describe 'Build' {
1919
Write-Host "OutputPath: $script:testModuleOutputPath"
2020

2121
# build is PS job so psake doesn't freak out because it's nested
22-
Start-Job -ScriptBlock {
22+
Start-Job -Scriptblock {
2323
Set-Location $using:PSScriptRoot/TestModule
2424
$global:PSBuildCompile = $true
2525
./build.ps1 -Task Build
@@ -66,12 +66,38 @@ Describe 'Build' {
6666
It 'Has MAML help XML' {
6767
"$script:testModuleOutputPath/en-US/TestModule-help.xml" | Should -Exist
6868
}
69+
70+
It 'Can Overwrite the Docs' {
71+
# Replace with a different string to test the overwrite
72+
$docPath = "$PSScriptRoot/TestModule/docs/en-US/Get-HelloWorld.md"
73+
$original = Get-Content $docPath -Raw
74+
$new = $original -replace 'Hello World', 'Hello Universe'
75+
Set-Content $docPath -Value $new -Force
76+
# Test that the file was updated
77+
Get-Content $docPath -Raw | Should -BeExactly $new
78+
79+
# Update the psake file
80+
$psakeFile = "$PSScriptRoot/TestModule/psakeFile.ps1"
81+
$psakeFileContent = Get-Content $psakeFile -Raw
82+
$psakeFileContent = $psakeFileContent -replace '\$PSBPreference.Docs.Overwrite = \$false', '$PSBPreference.Docs.Overwrite = $true'
83+
Set-Content $psakeFile -Value $psakeFileContent -Force
84+
85+
# build is PS job so psake doesn't freak out because it's nested
86+
Start-Job -ScriptBlock {
87+
Set-Location $using:PSScriptRoot/TestModule
88+
$global:PSBuildCompile = $true
89+
./build.ps1 -Task Build
90+
} | Wait-Job
91+
92+
# Test that the file reset as expected
93+
Get-Content $docPath -Raw | Should -BeExactly $original
94+
}
6995
}
7096

7197
Context 'Dot-sourced module' {
7298
BeforeAll {
7399
# build is PS job so psake doesn't freak out because it's nested
74-
Start-Job -ScriptBlock {
100+
Start-Job -Scriptblock {
75101
Set-Location $using:PSScriptRoot/TestModule
76102
$global:PSBuildCompile = $false
77103
./build.ps1 -Task Build

0 commit comments

Comments
 (0)