move-obsolete-tests.ps1•1.87 kB
$filesToKeep = @(
"integration\api-integration.test.ts",
"api\news-routes-reliable.test.ts",
"api\cache.routes.test.ts",
"controllers\reliable-controller.test.ts",
"server.test.ts",
"cache.test.ts"
)
$testsDir = "src/__tests__"
$obsoleteDir = "src/__tests__/obsolete"
# Make sure the obsolete directory exists
if (-not (Test-Path $obsoleteDir)) {
New-Item -ItemType Directory -Path $obsoleteDir | Out-Null
New-Item -ItemType Directory -Path "$obsoleteDir/api" | Out-Null
New-Item -ItemType Directory -Path "$obsoleteDir/controllers" | Out-Null
New-Item -ItemType Directory -Path "$obsoleteDir/routes" | Out-Null
New-Item -ItemType Directory -Path "$obsoleteDir/mocks" | Out-Null
}
# Get all test files (excluding the obsolete directory itself)
$allTestFiles = Get-ChildItem -Path $testsDir -Filter "*.ts" -Recurse |
Where-Object { $_.FullName -notlike "*\obsolete\*" } |
ForEach-Object { $_.FullName -replace [regex]::Escape((Resolve-Path $testsDir).Path + "\"), "" }
# Identify files to move
$filesToMove = $allTestFiles | Where-Object {
$file = $_
$keepFile = $false
foreach ($keep in $filesToKeep) {
if ($file -like $keep) {
$keepFile = $true
break
}
}
-not $keepFile
}
# Move files to obsolete directory
foreach ($file in $filesToMove) {
$sourcePath = Join-Path $testsDir $file
$targetDir = Split-Path -Parent (Join-Path $obsoleteDir $file)
# Make sure the target directory exists
if (-not (Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir | Out-Null
}
$targetPath = Join-Path $obsoleteDir $file
Write-Host "Moving $sourcePath to $targetPath"
Move-Item -Path $sourcePath -Destination $targetPath -Force
}
Write-Host "Finished moving obsolete test files."