| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- # =============================================================================
- # 一键跑完全部测试:Python 引擎/接口 + BFF 单元与端到端 + 前端单测 + 全链路联调
- #
- # pwsh -File scripts/run_tests.ps1 # 全部
- # pwsh -File scripts/run_tests.ps1 -SkipE2E # 跳过需要真实服务的联调
- # pwsh -File scripts/run_tests.ps1 -Only python # 只跑某一组
- # =============================================================================
- param(
- [ValidateSet('all', 'python', 'bff', 'web', 'e2e', 'ui')]
- [string]$Only = 'all',
- [switch]$SkipE2E
- )
- $ErrorActionPreference = 'Continue'
- $root = Split-Path -Parent $PSScriptRoot
- $env:PYTHONIOENCODING = 'utf-8'
- $results = @()
- function Write-Section([string]$text) {
- Write-Host ''
- Write-Host ("=" * 68) -ForegroundColor DarkGray
- Write-Host " $text" -ForegroundColor Cyan
- Write-Host ("=" * 68) -ForegroundColor DarkGray
- }
- function Invoke-Suite([string]$name, [string]$workdir, [string]$command, [string[]]$arguments) {
- Write-Section $name
- Push-Location $workdir
- try {
- & $command @arguments
- $code = $LASTEXITCODE
- } catch {
- Write-Host "执行失败:$_" -ForegroundColor Red
- $code = 1
- } finally {
- Pop-Location
- }
- $script:results += [pscustomobject]@{ Suite = $name; ExitCode = $code }
- if ($code -eq 0) {
- Write-Host "✓ $name 通过" -ForegroundColor Green
- } else {
- Write-Host "✗ $name 失败(exit $code)" -ForegroundColor Red
- }
- }
- # ------------------------------------------------------------------ Python
- if ($Only -in @('all', 'python')) {
- Invoke-Suite 'Python 引擎与接口测试(pytest)' "$root\tools-service" 'python' @('-m', 'pytest', 'tests/', '-q')
- }
- # ------------------------------------------------------------------ BFF
- if ($Only -in @('all', 'bff')) {
- Push-Location "$root\bff"
- Write-Section 'BFF 类型检查与构建'
- & npx tsc -p tsconfig.json
- Pop-Location
- Invoke-Suite 'BFF 单元与接口测试(node:test)' "$root\bff" 'node' @('--test', 'dist/test/*.test.js')
- }
- # ------------------------------------------------------------------ Web
- if ($Only -in @('all', 'web')) {
- Invoke-Suite '前端类型检查(tsc)' "$root\web" 'npx' @('tsc', '--noEmit')
- Invoke-Suite '前端单元测试(vitest)' "$root\web" 'npx' @('vitest', 'run')
- Invoke-Suite '前端生产构建(vite build)' "$root\web" 'npx' @('vite', 'build')
- }
- # ------------------------------------------------------------------ E2E
- if (($Only -in @('all', 'e2e')) -and (-not $SkipE2E)) {
- Invoke-Suite '端到端联调(真实服务 + 真实模型)' $root 'node' @('scripts/e2e.mjs')
- }
- # ------------------------------------------------------------------ 浏览器交互
- if ($Only -in @('all', 'ui')) {
- Invoke-Suite '真实浏览器交互探针(CDP)' $root 'node' @('scripts/ui_probe.mjs')
- }
- # ------------------------------------------------------------------ 汇总
- Write-Section '测试汇总'
- $results | ForEach-Object {
- $mark = if ($_.ExitCode -eq 0) { '✓' } else { '✗' }
- $color = if ($_.ExitCode -eq 0) { 'Green' } else { 'Red' }
- Write-Host (" $mark {0,-46} exit={1}" -f $_.Suite, $_.ExitCode) -ForegroundColor $color
- }
- $failed = ($results | Where-Object { $_.ExitCode -ne 0 }).Count
- Write-Host ''
- if ($failed -eq 0) {
- Write-Host "全部 $($results.Count) 组测试通过" -ForegroundColor Green
- exit 0
- } else {
- Write-Host "$failed / $($results.Count) 组测试失败" -ForegroundColor Red
- exit 1
- }
|