aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/run_e2e_safe.sh
blob: a24455c70fb6a359a9fe1992d47b6edf8e35fdac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -e

# Cleanup first
scripts/clean_test_env.sh

echo "Building backend..."
go build -o neko_server ./cmd/neko

echo "Creating data directory..."
mkdir -p .data

echo "Starting mock feed server on port 9090..."
python3 -m http.server 9090 --directory scripts > mock_server.log 2>&1 &
MOCK_PID=$!
echo "Mock Server PID: $MOCK_PID"

# Verify mock server
sleep 2
if ! curl -s --head http://localhost:9090/mock_feed.xml > /dev/null; then
  echo "Mock server failed to start!"
  cat mock_server.log
  exit 1
fi
echo "Mock server is up."

echo "Starting backend on port 4994..."
./neko_server --verbose --allow-local --http=4994 --database=.data/test.db > backend.log 2>&1 &
SERVER_PID=$!

echo "Backend PID: $SERVER_PID"

# Wait for server to be ready
echo "Waiting for backend to start..."
for i in {1..30}; do
    if nc -z localhost 4994; then
        echo "Backend is up!"
        break
    fi
    echo "Waiting..."
    sleep 1
done

if ! nc -z localhost 4994; then
    echo "Backend failed to start. Check backend.log"
    cat backend.log
    kill $SERVER_PID || true
    exit 1
fi

echo "Running E2E tests..."
cd frontend
if npm run test:e2e; then
    echo "Tests passed!"
    EXIT_CODE=0
else
    echo "Tests failed!"
    echo "Backend Logs:"
    cat ../backend.log
    EXIT_CODE=1
fi
cd ..

echo "Cleaning up..."
kill $SERVER_PID || true
kill $MOCK_PID || true
scripts/clean_test_env.sh

exit $EXIT_CODE