Repository navigation
Expand file tree
/
Copy pathrun-e2e.ps1
More file actions
82 lines (73 loc) · 2.99 KB
/
Copy pathrun-e2e.ps1
File metadata and controls
82 lines (73 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
param(
# Filtre optionnel passé à Playwright (ex: "leave-guard clear-search").
[string]$Filter = ''
)
$root = Split-Path $PSScriptRoot -Parent
Set-Location $root
Write-Host "==> Arrêt d'un éventuel back sur :5172..." -ForegroundColor Cyan
$existing = Get-NetTCPConnection -LocalPort 5172 -State Listen -ErrorAction SilentlyContinue
if ($existing) {
Stop-Process -Id $existing.OwningProcess -Force -ErrorAction SilentlyContinue
Start-Sleep 1
}
Write-Host "==> Reset Docker..." -ForegroundColor Cyan
docker compose down -v
docker compose up -d
Write-Host " PostgreSQL OK" -ForegroundColor Green
Write-Host "==> Création de la DB e2e..." -ForegroundColor Cyan
docker compose exec -T database psql -U inseconds -c "DROP DATABASE IF EXISTS inseconds_e2e;" 2>$null
docker compose exec -T database psql -U inseconds -c "CREATE DATABASE inseconds_e2e;"
Write-Host " DB inseconds_e2e OK" -ForegroundColor Green
# Charge le mot de passe depuis .env (jamais commité)
$envFile = Join-Path $root ".env"
if (Test-Path $envFile) {
Get-Content $envFile | Where-Object { $_ -match '^\s*([^#][^=]*)=(.*)$' } | ForEach-Object {
$name, $value = $Matches[1].Trim(), $Matches[2].Trim()
[System.Environment]::SetEnvironmentVariable($name, $value, 'Process')
}
}
$dbPassword = $env:DB_PASSWORD
if (-not $dbPassword) { Write-Error "DB_PASSWORD manquant dans .env"; exit 1 }
$connStr = "Host=localhost;Port=5432;Database=inseconds_e2e;Username=inseconds;Password=$dbPassword"
Write-Host "==> Démarrage du back Testing (port 5172)..." -ForegroundColor Cyan
$backJob = Start-Job -ScriptBlock {
param($apiDir, $connStr)
Set-Location $apiDir
$env:ASPNETCORE_ENVIRONMENT = 'Testing'
$env:ConnectionStrings__DefaultConnection = $connStr
$env:E2E_FRONT_PORT = '5174'
dotnet run --no-launch-profile --urls http://localhost:5172
} -ArgumentList "$root\src\back\InSeconds.Api", $connStr
Write-Host "==> Attente du back..." -ForegroundColor Cyan
$tries = 0
while ($tries -lt 30) {
try {
$null = Invoke-WebRequest http://localhost:5172/health -UseBasicParsing -TimeoutSec 2 -ErrorAction Stop
break
} catch {
$tries++
Start-Sleep 2
}
}
if ($tries -eq 30) {
Write-Host "==> Output du job back :" -ForegroundColor Yellow
Receive-Job $backJob
Stop-Job $backJob; Remove-Job $backJob
Write-Error "Back non disponible sur :5172"
exit 1
}
Write-Host " Back OK" -ForegroundColor Green
Write-Host "==> Lancement des tests E2E..." -ForegroundColor Cyan
Set-Location "$root\src\front\InSeconds.Client"
if ($Filter) {
npx playwright test $Filter.Split(' ')
} else {
npm run e2e
}
$e2eExit = $LASTEXITCODE
Write-Host "==> Arrêt du back..." -ForegroundColor Cyan
$port = Get-NetTCPConnection -LocalPort 5172 -State Listen -ErrorAction SilentlyContinue
if ($port) { Stop-Process -Id $port.OwningProcess -Force -ErrorAction SilentlyContinue }
Stop-Job $backJob -ErrorAction SilentlyContinue
Remove-Job $backJob -ErrorAction SilentlyContinue
exit $e2eExit