From 649b6b78786d18fa9b4227a40ffbefe3f7571e4c Mon Sep 17 00:00:00 2001 From: QuiteAFancyEmerald <46467239+QuiteAFancyEmerald@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:52:41 -0700 Subject: [PATCH] test --- .github/workflows/ci.yml | 45 +++++++++++++++++++++++++++------------- package.json | 4 ++-- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b79734a5..a52ef03b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,22 +11,39 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v2 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '20.8.0' + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' - - name: Install dependencies + - name: Install dependencies run: npm install - - name: Build project - run: npm run build + - name: Check if server is already running + id: check-server + run: | + if lsof -Pi :8080 -sTCP:LISTEN -t >/dev/null ; then + echo "Server is already running" + exit 0 + else + echo "Server is not running" + exit 1 + fi - - name: Start server and run tests - run: | - npm run start-test-server - sleep 10 # Wait for the server to start - npm run test-400 \ No newline at end of file + - name: Start server if not already running + if: steps.check-server.outcome == 'failure' + run: npm run start-test-server + + - name: Wait for server to start + if: steps.check-server.outcome == 'failure' + run: sleep 30 + + - name: Test server response + run: npm run test-400 + + - name: Stop server after testing + if: steps.check-server.outcome == 'failure' + run: pkill node || true diff --git a/package.json b/package.json index 796f23e1..5dcc7792 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "main": "backend.js", "scripts": { "start": "node backend.js", - "build": "echo 'Building project...' && exit 0", - "test": "echo 'Running tests...' && exit 0", + "build": "npm run start", + "test": "npm run test-400", "start-test-server": "node backend.js &", "test-400": "curl -s -o /dev/null -w '%{http_code}' http://localhost:8080/ | grep 400" },