agmission/.gitea/workflows/run-tests.yaml
Devin Major ea46cbeb02
All checks were successful
Server Tests / Mocha – Unit & Utility Tests (push) Successful in 1m12s
Server Tests / Jest – Integration Tests (push) Successful in 1m35s
output mocha's test results and coverage report as artifacts
2026-04-29 13:41:28 -04:00

219 lines
7.8 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Gitea Actions Server Tests
#
# Two jobs run on every push to any branch:
# 1. jest-integration Jest integration tests using an in-memory MongoDB
# instance (mongodb-memory-server). No external database
# or repository secrets are required.
# 2. mocha-unit Existing Mocha/Chai unit tests in tests/ and tests/utils/
#
# Optional repository secret:
# TOKEN_SECRET JWT secret used by the server's auth helpers.
# A safe default is used automatically when absent.
name: Server Tests
on:
push:
branches:
- '**'
# ─────────────────────────────────────────────────────────────────────────────
jobs:
# ══════════════════════════════════════════════════════════════════════════
# Job 1: Jest integration tests (in-memory MongoDB via mongodb-memory-server)
# ══════════════════════════════════════════════════════════════════════════
jest-integration:
name: Jest Integration Tests
runs-on: self-hosted
defaults:
run:
working-directory: Development/server
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: Development/server/package-lock.json
- name: Prepare MongoDB runtime compatibility libraries
run: |
set -e
if command -v ldconfig >/dev/null 2>&1 && ldconfig -p | grep -q 'libcrypto.so.1.1'; then
echo "OpenSSL 1.1 compatibility already present"
exit 0
fi
LIBSSL_DIR="${RUNNER_TEMP:-/tmp}/libssl11"
DEB_PATH="${RUNNER_TEMP:-/tmp}/libssl1.1.deb"
mkdir -p "$LIBSSL_DIR"
if [ ! -f "$DEB_PATH" ]; then
curl -fsSL \
-o "$DEB_PATH" \
"http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.24_amd64.deb"
fi
dpkg-deb -x "$DEB_PATH" "$LIBSSL_DIR"
LIB_DIR="$LIBSSL_DIR/usr/lib/x86_64-linux-gnu"
if [ ! -f "$LIB_DIR/libcrypto.so.1.1" ]; then
echo "libcrypto.so.1.1 was not found after extracting $DEB_PATH"
exit 1
fi
echo "LD_LIBRARY_PATH=$LIB_DIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> "$GITHUB_ENV"
echo "Prepared OpenSSL 1.1 compatibility libraries in $LIB_DIR"
- name: Install dependencies
env:
NPM_CONFIG_CACHE: /tmp/npm-cache
run: npm ci --prefer-offline
- name: Write test environment file
run: |
cat > environment.test.env <<'EOF'
NODE_ENV=test
TOKEN_SECRET=${{ secrets.TOKEN_SECRET || 'ci-test-secret-not-for-production' }}
PRODUCTION=false
NO_EMAIL_MODE=true
ENABLE_SUBSCRIPTION=false
INV_IMG_VIR_DIR=/tmp/inv-img
INV_UPLOAD_DIR=/tmp/inv-upload
INV_MAX_UPLOAD_SIZE_MB=5
PAGINATION_DEFAULT_LIMIT=1000
PAGINATION_MAX_LIMIT=14000
STRIPE_SEC_KEY=sk_test_placeholder
STRIPE_API_VERSION=2022-11-15
EOF
- name: Enforce controller integration contract
env:
TEST_ENV_FILE: ./environment.test.env
NODE_ENV: test
MONGOMS_VERSION: 4.4.28
run: npm run test:integration:contract
- name: Run Jest integration tests
env:
TEST_ENV_FILE: ./environment.test.env
NODE_ENV: test
MONGOMS_VERSION: 4.4.28
run: |
set -o pipefail
npm run test:integration:jest -- --ci --coverage 2>&1 | tee jest-integration.log
- name: Upload Jest results
if: always()
uses: actions/upload-artifact@v3
with:
name: jest-integration-results
path: Development/server/jest-integration.log
- name: Upload Jest coverage
if: always()
uses: actions/upload-artifact@v3
with:
name: jest-integration-coverage
path: Development/server/coverage/integration
# ══════════════════════════════════════════════════════════════════════════
# Job 2: Mocha/Chai tests tests/ and tests/utils/
# These tests are self-contained unit tests that do not require MongoDB.
# ══════════════════════════════════════════════════════════════════════════
mocha-unit:
name: Mocha Unit & Utility Tests
runs-on: self-hosted
defaults:
run:
working-directory: Development/server
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
# Redirect the npm cache away from /root/.npm (root-owned on this runner)
# to a writable temp directory. Also clears any stale node_modules left
# by a previous run that the root-owned cache could not clean up.
- name: Fix npm cache permissions
run: |
mkdir -p /tmp/npm-cache
rm -rf node_modules || true
- name: Install dependencies
env:
NPM_CONFIG_CACHE: /tmp/npm-cache
run: npm ci
# Write a minimal env file so dotenv does not error on startup.
# These tests do not hit the database; DB_* values are placeholders.
- name: Write test environment file
run: |
cat > environment.env <<'EOF'
NODE_ENV=test
DB_HOSTS=127.0.0.1:27017
DB_NAME=agmission_test
DB_USR=
DB_PWD=
TOKEN_SECRET=${{ secrets.TOKEN_SECRET || 'ci-test-secret-not-for-production' }}
PRODUCTION=false
NO_EMAIL_MODE=true
ENABLE_SUBSCRIPTION=false
STRIPE_SEC_KEY=sk_test_placeholder
STRIPE_API_VERSION=2022-11-15
EOF
# Run all top-level test_*.js files (skips integration/ and satloc/ sub-dirs
# which are covered by the jest-integration job or need live connections).
# Coverage is aggregated across this run and tests/utils/.
- name: Run Mocha unit tests with coverage
run: |
set -o pipefail
rm -rf .nyc_output coverage/mocha mocha-unit.log
npx nyc \
--silent \
--temp-dir .nyc_output \
npx mocha --exit --timeout 120000 \
--require tests/setup.js \
'tests/test_*.js' 2>&1 | tee mocha-unit.log
npx nyc \
--silent \
--temp-dir .nyc_output \
--no-clean \
npm run test:utils 2>&1 | tee -a mocha-unit.log
npx nyc report \
--temp-dir .nyc_output \
--report-dir coverage/mocha \
--reporter=text \
--reporter=lcov \
--reporter=json-summary | tee -a mocha-unit.log
- name: Upload Mocha results
if: always()
uses: actions/upload-artifact@v3
with:
name: mocha-unit-results
path: Development/server/mocha-unit.log
- name: Upload Mocha coverage
if: always()
uses: actions/upload-artifact@v3
with:
name: mocha-unit-coverage
path: Development/server/coverage/mocha