sc-site-sync/test/run.sh
2026-10-19 01:25:16 -05:00

34 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Reproducible, SELF-CONTAINED in-process test for site-sync.
# Spins up a throwaway SQLite DB in a mktemp state dir OUTSIDE the plugin tree, runs
# Saltcorn migrations, then drives the real plugin modules + route handlers via
# test/e2e.js. Touches no other instance and no shared plugins folder (see
# isolate_saltcorn_dirs in testEnv.sh).
#
# ./test/run.sh # runs test/e2e.js
# ./test/run.sh <file.js> # runs test/<file.js>
#
# @saltcorn/* are host-provided (this plugin declares no deps, per the
# dev-deploy/idp/theme-builder convention), so the harness gets them via NODE_PATH
# pointing at the upstream checkout's node_modules.
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
PLUGIN="$(dirname "$HERE")"
REPO="$(dirname "$PLUGIN")"
SC_BIN="$REPO/saltcorn/packages/saltcorn-cli/bin/saltcorn"
TESTFILE="${1:-e2e.js}"
# shellcheck source=testEnv.sh
. "$HERE/testEnv.sh"
STATE="$(make_state_dir site-sync-test)"
trap 'rm -rf "$STATE"' EXIT
isolate_saltcorn_dirs "$STATE"
mkdir -p "$STATE/files"
export SQLITE_FILEPATH="$STATE/test.sqlite"
export SALTCORN_FILE_STORE="$STATE/files"
export SALTCORN_SESSION_SECRET="site-sync-integration-test-secret"
export SALTCORN_NWORKERS=1
export NODE_PATH="$REPO/saltcorn/node_modules"
node "$SC_BIN" reset-schema --force >/dev/null
node "$HERE/$TESTFILE"