From 24f990a12d12814ae499cd4d5ba9f1691d707f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Adem=20I=C5=9EIKLI?= Date: Sun, 10 Mar 2024 17:27:05 +0100 Subject: [PATCH] Fixed integration tests --- .github/workflows/tests.yml | 26 +++++++++++++++++++++++--- tests/app.test.js | 20 ++------------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 177e1a9..6ab1163 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,6 +17,26 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - run: npm ci - - run: cp .env.example .env - - run: npm run test + + - name: Build the app + run: | + npm ci + cp .env.example .env + npm run build + + - name: Start the application + run: npm run start & + + - name: Wait for the server to start + run: sleep 5 + + - name: Test API endpoint + run: | + response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/docs) + if [ $response == "200" ]; then + echo "API endpoint is reachable." + exit 0 + else + echo "API endpoint is not reachable." + exit 1 + fi diff --git a/tests/app.test.js b/tests/app.test.js index bf63120..8fef91f 100644 --- a/tests/app.test.js +++ b/tests/app.test.js @@ -1,19 +1,3 @@ -const apiUrl = "http://127.0.0.1:3000/docs"; -const spawn = require("child_process").spawn; - -jest.setTimeout(10000); - -beforeAll(async () => { - const server = spawn("npm", ["run", "start:dev"], { detached: true }); - await new Promise((resolve) => setTimeout(resolve, 5000)); - global.server = server; -}); - -afterAll(async () => { - process.kill(-global.server.pid); -}); - -test("API should be running and return status 200", async () => { - const response = await fetch(apiUrl); - expect(response.status).toBe(200); +test("Example testing", async () => { + expect(true).toBe(true); });