mirror of
https://github.com/kucherenko/jscpd.git
synced 2026-09-19 08:11:03 +08:00
64e471e2b0
Adds 92 new tests (178 → 270 total) with zero source-file modifications: - packages/finder: 13 new test files covering all reporters, subscribers, validators, hooks, utils, options, cloneFound, getFilesToDetect, and InFilesDetector; shared buildClone() factory helper - apps/jscpd: 3 new test files (options-unit, print, store) plus extensions to formats, modes, and options integration tests - vitest.config.ts added to both packages to restrict coverage.include to src/** only, eliminating bin/ and prism.js noise - Fixes 3 tokenizer bugs (trailing space in format lookup, tokenization edge cases) uncovered by the new format fixture suite - Adds fixture files for 40+ language formats to support formats.test.ts
50 lines
1.2 KiB
PowerShell
50 lines
1.2 KiB
PowerShell
# Common PowerShell utility functions
|
|
|
|
function Invoke-WithRetry {
|
|
param(
|
|
[scriptblock] $Action,
|
|
[int] $MaxAttempts = 3,
|
|
[int] $DelaySeconds = 2
|
|
)
|
|
$attempt = 0
|
|
while ($attempt -lt $MaxAttempts) {
|
|
try {
|
|
return & $Action
|
|
}
|
|
catch {
|
|
$attempt++
|
|
if ($attempt -ge $MaxAttempts) { throw }
|
|
Start-Sleep -Seconds $DelaySeconds
|
|
Write-Warning "Retry $attempt of $MaxAttempts..."
|
|
}
|
|
}
|
|
}
|
|
|
|
function Test-ValidInput {
|
|
param([string] $Value)
|
|
if ([string]::IsNullOrWhiteSpace($Value)) {
|
|
return $false
|
|
}
|
|
if ($Value.Length -gt 255) {
|
|
return $false
|
|
}
|
|
return $true
|
|
}
|
|
|
|
function Write-LogMessage {
|
|
param(
|
|
[string] $Level = 'INFO',
|
|
[string] $Message
|
|
)
|
|
$ts = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
|
|
Write-Host "[$ts] [$Level] $Message"
|
|
}
|
|
|
|
# File-specific: start application service
|
|
function Start-AppService {
|
|
param([string] $ServiceName)
|
|
Write-LogMessage -Message "Starting $ServiceName"
|
|
Start-Service -Name $ServiceName
|
|
Write-LogMessage -Message "$ServiceName started"
|
|
}
|