Skip to content

Commit 32db951

Browse files
author
=
committed
Added CI/CD tests
1 parent bfe6ff1 commit 32db951

File tree

5 files changed

+8702
-2346
lines changed

5 files changed

+8702
-2346
lines changed

.github/workflows/API-tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Server API tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test-server:
11+
name: Run server tests
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
node-version: [18.x]
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
26+
- name: Cache server node modules
27+
uses: actions/cache@v4
28+
with:
29+
path: server/node_modules
30+
key: ${{ runner.os }}-server-${{ hashFiles('server/package-lock.json') }}
31+
restore-keys: |
32+
${{ runner.os }}-server-
33+
34+
- name: Install server dependencies
35+
working-directory: ./server
36+
run: npm ci
37+
38+
- name: Run server tests
39+
working-directory: ./server
40+
run: npm test

server/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ const corsOptions = {
2424
},
2525
credentials: true,
2626
};
27-
//database connect
28-
database.connect();
27+
//database connect (skip in tests)
28+
if (process.env.NODE_ENV !== 'test') {
29+
database.connect();
30+
}
2931
//middlewares
3032
app.use(express.json());
3133
app.use(cookieParser());
@@ -38,8 +40,10 @@ app.use(
3840
tempFileDir:"/tmp",
3941
})
4042
)
41-
//cloudinary connection
42-
cloudinaryConnect();
43+
//cloudinary connection (skip in tests)
44+
if (process.env.NODE_ENV !== 'test') {
45+
cloudinaryConnect();
46+
}
4347

4448
//routes
4549
app.use("/api/v1/auth", userRoutes);
@@ -57,7 +61,11 @@ app.get("/", (req, res) => {
5761
});
5862
});
5963

60-
app.listen(PORT, () => {
61-
console.log(`App is running at ${PORT}`)
62-
})
64+
if (process.env.NODE_ENV !== 'test') {
65+
app.listen(PORT, () => {
66+
console.log(`App is running at ${PORT}`)
67+
})
68+
}
69+
70+
module.exports = app;
6371

0 commit comments

Comments
 (0)