mirror of
https://github.com/kellymichels/zscripts-token-savers
synced 2026-10-06 07:08:17 +00:00
perf(tests): run each child-process invocation once (#77)
Some checks failed
tests / test (push) Has been cancelled
Some checks failed
tests / test (push) Has been cancelled
Every Invoke-ZScript call starts a fresh Windows PowerShell, which costs about 1.7 seconds - and it is the dominant cost of this file. Thirteen of its forty-three calls re-run a command an earlier check has already run. The usage tests are the clearest case: a script is run bare three separate times to assert that it exits non-zero, that its usage lists the project keys, and that the usage never mentions the underscore comment key. Those are three questions about one run. Memoised on the exact command, so each distinct invocation happens once and every check that asks for it gets the same captured result. The commands reached here either refuse their input or inspect an unused fixture port, so none has a side effect a second run would reveal. ArgumentParsing.Tests.ps1, over three runs each: 83/108/88s before, 61/68/79s after. All 42 tests still pass. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
f27f9dc5bc
commit
3b0194af93
@ -73,14 +73,30 @@ BeforeAll {
|
||||
$fixture | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath (Join-Path $script:Install "zconfig.json") -Encoding UTF8
|
||||
|
||||
# Run a script in a child process; capture merged output and exit code.
|
||||
#
|
||||
# Memoised on the exact command. Several checks deliberately assert
|
||||
# different things about the SAME invocation - that running bare exits
|
||||
# non-zero, that its usage lists the project keys, and that the usage
|
||||
# never mentions the underscore comment key are three checks of one run.
|
||||
# Starting a Windows PowerShell costs about 1.7 s, so re-running the same
|
||||
# command to ask it a second question is the single most expensive thing
|
||||
# this file does. The scripts reached here either refuse their input or
|
||||
# inspect an unused fixture port, so none of them has a side effect a
|
||||
# second run would reveal.
|
||||
$script:zRuns = @{}
|
||||
|
||||
function Invoke-ZScript {
|
||||
param([string]$Script, [string[]]$ScriptArgs = @())
|
||||
$key = @($Script) + $ScriptArgs -join "`n"
|
||||
if ($script:zRuns.ContainsKey($key)) { return $script:zRuns[$key] }
|
||||
$path = Join-Path $script:Install $Script
|
||||
$out = & powershell -NoProfile -ExecutionPolicy Bypass -File $path @ScriptArgs 2>&1 | ForEach-Object { "$_" }
|
||||
return [pscustomobject]@{
|
||||
$result = [pscustomobject]@{
|
||||
ExitCode = $LASTEXITCODE
|
||||
Output = ($out -join "`n")
|
||||
}
|
||||
$script:zRuns[$key] = $result
|
||||
return $result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user