Skip to content

Instantly share code, notes, and snippets.

@sameera

sameera/jestdbg.ps1

Created Oct 20, 2020
Embed
What would you like to do?
Generate VS Code launch.json file that debugs jest
param([string]$relativePath = "")
if ($relativePath -eq $null) {
Write-Error "Specify a file to debug."
exit 1
}
$file = Resolve-Path -Path $relativePath
$matches = $file | Select-String -Pattern "(?<root>.*\/)(apps|libs)\/(?<prj>.*?)\/src/.*"
if ($matches.Count -eq 0) {
Write-Error "Specified path did not match the expected pattern."
exit 1
}
$root = $matches.Matches[0].Groups["root"].Value
$prj = $matches.Matches[0].Groups["prj"].Value
$launchCode = @{
configurations = @(
@{
name = "debug-jest-lib"
type = "node"
request = "launch"
program = "`${workspaceFolder}/node_modules/@angular/cli/bin/ng"
args = @(
"test",
$prj,
"--codeCoverage=false",
"--testNamePattern=.*",
"--testFile=`${file}"
)
cwd = "`${workspaceFolder}"
console = "internalConsole"
}
)
} | ConvertTo-Json -Depth 3
$outpath = "$root/.vscode/launch.json"
[IO.File]::WriteAllText($outpath, $launchCode, [System.Text.Encoding]::UTF8)
Write-Host "Updated: $outpath"
Write-Host $launchCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.