| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- $ErrorActionPreference = "Stop"
- $projectRoot = Resolve-Path "$PSScriptRoot\..\.."
- $backendRoot = Join-Path $projectRoot "project\backend"
- $reportDir = Join-Path $PSScriptRoot "reports"
- $logFile = Join-Path $reportDir "api_test_log.txt"
- $summaryFile = Join-Path $reportDir "api_test_summary.txt"
- New-Item -ItemType Directory -Path $reportDir -Force | Out-Null
- Push-Location $backendRoot
- try {
- $env:NO_COLOR = "1"
- $oldErrorActionPreference = $ErrorActionPreference
- $ErrorActionPreference = "Continue"
- $output = & cmd.exe /d /s /c "npm.cmd test -- tests/health.spec.ts tests/api-contract.spec.ts 2>&1"
- $exitCode = $LASTEXITCODE
- $ErrorActionPreference = $oldErrorActionPreference
- } finally {
- $ErrorActionPreference = "Stop"
- Pop-Location
- }
- $ansiPattern = "$([char]27)\[[0-9;]*m"
- $textOutput = $output | ForEach-Object { $_.ToString() -replace $ansiPattern, "" }
- $textOutput | Set-Content -Path $logFile -Encoding UTF8
- $textOutput | ForEach-Object { Write-Host $_ }
- $result = "PASS"
- if ($exitCode -ne 0) {
- $result = "FAIL"
- }
- @(
- "ServicePilot 接口测试执行记录",
- "执行时间:$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')",
- "测试对象:project/backend/tests/health.spec.ts、project/backend/tests/api-contract.spec.ts",
- "测试范围:健康检查、Parse 前端配置、敏感字段保护、404 契约",
- "预期标准:HTTP 状态码、响应结构和错误信息符合接口契约",
- "执行结果:$result",
- "详细日志:$logFile"
- ) | Set-Content -Path $summaryFile -Encoding UTF8
- Write-Host "接口测试日志已生成:$logFile"
- Write-Host "接口测试摘要已生成:$summaryFile"
- if ($exitCode -ne 0) {
- exit $exitCode
- }
|