test(infra): add postgres and frontend test tooling

Add repeatable PostgreSQL integration tests and configure Vitest, Testing Library, and ESLint.

Refs #11

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 19:54:28 +01:00
parent a4d63015d4
commit 9970b49746
8 changed files with 1865 additions and 26 deletions

View File

@ -1,4 +1,7 @@
.PHONY: up down build logs deps .PHONY: up down build logs deps test-postgres
test-postgres:
./backend/scripts/test-postgres.sh
# Démarrer tous les services # Démarrer tous les services
up: up:

View File

@ -0,0 +1,21 @@
package api_test
import (
"os"
"testing"
)
// postgresTestURL allows ordinary unit-test runs to skip integration cases,
// while making an explicitly requested PostgreSQL run fail if its harness did
// not provide a database URL.
func postgresTestURL(t *testing.T) string {
t.Helper()
if dsn := os.Getenv("TEST_DATABASE_URL"); dsn != "" {
return dsn
}
if os.Getenv("TEST_DATABASE_REQUIRED") == "1" {
t.Fatal("TEST_DATABASE_REQUIRED=1 but TEST_DATABASE_URL is empty")
}
t.Skip("TEST_DATABASE_URL absent: isolated PostgreSQL required")
return ""
}

View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail
backend_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
managed_tmp="${TMPDIR:-${IDEA_MANAGED_TMP:-}}"
if [[ -z "$managed_tmp" ]]; then
echo "TMPDIR or IDEA_MANAGED_TMP must point to a writable managed temp directory" >&2
exit 2
fi
postgres_home="$managed_tmp/tradarr-embedded-postgres"
cli="$postgres_home/bin/embedded-postgres"
export GOCACHE="${GOCACHE:-$managed_tmp/go-build}"
export GOMODCACHE="${GOMODCACHE:-$managed_tmp/gomodcache}"
mkdir -p "$postgres_home/bin" "$postgres_home/cache" "$postgres_home/work"
if [[ ! -x "$cli" ]]; then
installer="$postgres_home/install-v2.0.1.sh"
curl -fsSL https://raw.githubusercontent.com/fergusstrange/embedded-postgres/v2.0.1/install/install.sh -o "$installer"
EP_VERSION=v2.0.1 EP_INSTALL_DIR="$postgres_home/bin" bash "$installer"
rm -f "$installer"
fi
version_json="$("$cli" version)"
if [[ "$version_json" != *'"version":"v2.0.1"'* ]]; then
echo "Unexpected embedded-postgres CLI version: $version_json" >&2
exit 2
fi
cd "$backend_dir"
if [[ -n "${TEST_DATABASE_URL:-}" ]]; then
TEST_DATABASE_REQUIRED=1 go test ./... -count=1 -v
exit $?
fi
"$cli" exec \
--postgres-version 16.15.1 \
--cache-dir "$postgres_home/cache" \
--work-dir "$postgres_home/work" \
-- sh -c 'set -eu
: "${DATABASE_URL:?embedded-postgres did not set DATABASE_URL}"
export TEST_DATABASE_REQUIRED=1
export TEST_DATABASE_URL="$DATABASE_URL"
unset DATABASE_URL PGHOST PGPORT PGUSER PGPASSWORD PGDATABASE PGSSLMODE
exec go test ./... -count=1 -v'

33
frontend/eslint.config.js Normal file
View File

@ -0,0 +1,33 @@
import js from "@eslint/js";
import react from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import globals from "globals";
import tseslint from "typescript-eslint";
export default tseslint.config(
{ ignores: ["dist/**", "node_modules/**", "coverage/**"] },
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ["**/*.{js,mjs,cjs,ts,tsx}"],
languageOptions: {
globals: { ...globals.browser, ...globals.node },
},
},
{
files: ["**/*.{ts,tsx}"],
plugins: {
react,
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
},
settings: { react: { version: "detect" } },
rules: {
...react.configs.recommended.rules,
...react.configs["jsx-runtime"].rules,
...reactHooks.configs.flat.recommended.rules,
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
},
},
);

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,8 @@
"dev": "vite", "dev": "vite",
"build": "tsc -b && vite build", "build": "tsc -b && vite build",
"preview": "vite preview", "preview": "vite preview",
"lint": "eslint ." "lint": "eslint .",
"test": "vitest run"
}, },
"dependencies": { "dependencies": {
"@radix-ui/react-avatar": "^1.1.3", "@radix-ui/react-avatar": "^1.1.3",
@ -30,15 +31,26 @@
"tailwind-merge": "^2.6.0" "tailwind-merge": "^2.6.0"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.39.5",
"@testing-library/jest-dom": "^8.0.0",
"@testing-library/react": "^16.3.3",
"@testing-library/user-event": "^14.6.13",
"@types/react": "^18.3.18", "@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5", "@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^4.3.4", "@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.20",
"eslint": "^9.19.0", "eslint": "^9.19.0",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.8",
"globals": "^17.14.0",
"jsdom": "^31.0.1",
"postcss": "^8.5.2", "postcss": "^8.5.2",
"tailwindcss": "^3.4.17", "tailwindcss": "^3.4.17",
"typescript": "^5.7.3", "typescript": "^5.7.3",
"typescript-eslint": "^8.73.0",
"vite": "^6.1.0", "vite": "^6.1.0",
"vite-plugin-pwa": "^0.21.1" "vite-plugin-pwa": "^0.21.1",
"vitest": "^5.1.1"
} }
} }

13
frontend/vitest.config.ts Normal file
View File

@ -0,0 +1,13 @@
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import path from 'node:path'
export default defineConfig({
plugins: [react()],
resolve: { alias: { '@': path.resolve(__dirname, 'src') } },
test: {
environment: 'jsdom',
setupFiles: ['./vitest.setup.ts'],
clearMocks: true,
},
})

1
frontend/vitest.setup.ts Normal file
View File

@ -0,0 +1 @@
import '@testing-library/jest-dom/vitest'