Skip to content

Instantly share code, notes, and snippets.

@sameera
Created October 20, 2020 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sameera/610a10d7c365f63a477139913678b9e4 to your computer and use it in GitHub Desktop.
Save sameera/610a10d7c365f63a477139913678b9e4 to your computer and use it in GitHub Desktop.
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