#!/bin/bash
# Repo-local pre-commit extras, run last by the canonical hook.
#
# The JS suite. It is here rather than in the canonical hook because BB is the
# only repo that runs it separately: goingson's scripts/lint-frontend.sh runs its
# own suite internally, and BB's does not. If a second repo ever wants this, move
# it into the canonical hook behind a `[ -d <tests dir> ]` check rather than
# copying the file.
set -euo pipefail

ROOT="$(git rev-parse --show-toplevel)"
cd "$ROOT"

staged_js="$(git diff --cached --name-only --diff-filter=ACMR -- 'src-tauri/frontend/*')"
[ -n "$staged_js" ] || exit 0

echo "pre-commit: JS tests..."
if ! node --test 'src-tauri/frontend/js/tests/*.test.js'; then
    echo "pre-commit: JS tests failed, commit aborted (use --no-verify to bypass)."
    exit 1
fi
