diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml new file mode 100644 index 00000000..0dcf94ad --- /dev/null +++ b/.github/workflows/backend-tests.yml @@ -0,0 +1,69 @@ +name: Backend Tests + +on: + push: + branches: + - main + - master + paths: + - 'py/**' + - 'standalone.py' + - 'tests/**' + - 'requirements.txt' + - 'requirements-dev.txt' + - 'pyproject.toml' + - 'pytest.ini' + - '.github/workflows/backend-tests.yml' + pull_request: + paths: + - 'py/**' + - 'standalone.py' + - 'tests/**' + - 'requirements.txt' + - 'requirements-dev.txt' + - 'pyproject.toml' + - 'pytest.ini' + - '.github/workflows/backend-tests.yml' + +jobs: + pytest: + name: Run pytest with coverage + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: '3.11' + cache: 'pip' + cache-dependency-path: | + requirements.txt + requirements-dev.txt + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + + - name: Run pytest with coverage + env: + COVERAGE_FILE: coverage/backend/.coverage + run: | + mkdir -p coverage/backend + python -m pytest \ + --cov=py \ + --cov=standalone \ + --cov-report=term-missing \ + --cov-report=xml:coverage/backend/coverage.xml \ + --cov-report=html:coverage/backend/html \ + --cov-report=json:coverage/backend/coverage.json + + - name: Upload coverage artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: backend-coverage + path: coverage/backend + if-no-files-found: warn diff --git a/.github/workflows/frontend-tests.yml b/.github/workflows/frontend-tests.yml index 362a8b67..5ae42eb5 100644 --- a/.github/workflows/frontend-tests.yml +++ b/.github/workflows/frontend-tests.yml @@ -11,6 +11,7 @@ on: - 'vitest.config.js' - 'tests/frontend/**' - 'static/js/**' + - 'scripts/run_frontend_coverage.js' - '.github/workflows/frontend-tests.yml' pull_request: paths: @@ -19,6 +20,7 @@ on: - 'vitest.config.js' - 'tests/frontend/**' - 'static/js/**' + - 'scripts/run_frontend_coverage.js' - '.github/workflows/frontend-tests.yml' jobs: diff --git a/.gitignore b/.gitignore index bae77cab..9b05d66a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ cache/ civitai/ node_modules/ coverage/ +.coverage diff --git a/README.md b/README.md index 7e932acc..87ba168f 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,33 @@ You can now run LoRA Manager independently from ComfyUI: This standalone mode provides a lightweight option for managing your model and recipe collection without needing to run the full ComfyUI environment, making it useful even for users who primarily use other stable diffusion interfaces. +## Testing & Coverage + +### Backend + +Install the development dependencies and run pytest with coverage reports: + +```bash +pip install -r requirements-dev.txt +COVERAGE_FILE=coverage/backend/.coverage pytest \ + --cov=py \ + --cov=standalone \ + --cov-report=term-missing \ + --cov-report=html:coverage/backend/html \ + --cov-report=xml:coverage/backend/coverage.xml \ + --cov-report=json:coverage/backend/coverage.json +``` + +HTML, XML, and JSON artifacts are stored under `coverage/backend/` so you can inspect hot spots locally or from CI artifacts. + +### Frontend + +Run the Vitest coverage suite to analyze widget hot spots: + +```bash +npm run test:coverage +``` + --- ## Contributing diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..19e0b92f --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +-r requirements.txt +pytest>=7.4 +pytest-cov>=4.1