Skip to content

Commit

Permalink
Fixed integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ozziest committed Mar 10, 2024
1 parent e088996 commit dd173ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
Binary file added .DS_Store
Binary file not shown.
29 changes: 26 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
branches:
- master
push:
branches:
- test

jobs:
units:
Expand All @@ -17,6 +20,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
20 changes: 2 additions & 18 deletions tests/app.test.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit dd173ad

Please sign in to comment.