Compare commits
5 Commits
d9b1459611
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2132babc51 | ||
|
|
6838b2754c | ||
|
|
dbda40e864 | ||
|
|
2bc20ca994 | ||
|
|
aa335f76bf |
@@ -1,4 +1,20 @@
|
||||
name: CI
|
||||
# name: CI
|
||||
|
||||
# on:
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
|
||||
# jobs:
|
||||
# build:
|
||||
# runs-on: ubuntu-latest
|
||||
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
# - run: echo "Hello from Gitea Actions"
|
||||
|
||||
|
||||
name: Node API Test
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -6,9 +22,19 @@ on:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: echo "Hello from Gitea Actions"
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Run tests
|
||||
run: npm test
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules/
|
||||
28
index.js
Normal file
28
index.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.json({
|
||||
status: "OK",
|
||||
message: "Home Route Working"
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/health", (req, res) => {
|
||||
res.json({
|
||||
status: "OK",
|
||||
message: "Server is healthy"
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
// only start server if not testing
|
||||
// It ensures the server starts only when the file is run directly, not when it is imported for testing.
|
||||
if (require.main === module) {
|
||||
app.listen(3000, () => {
|
||||
console.log("Server running on port 3000");
|
||||
});
|
||||
}
|
||||
5025
package-lock.json
generated
Normal file
5025
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
package.json
Normal file
22
package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "test-parinaam",
|
||||
"version": "1.0.0",
|
||||
"description": "do somethig",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.parinaam.in/bunty/node-code.git"
|
||||
},
|
||||
"license": "ISC",
|
||||
"author": "",
|
||||
"type": "commonjs",
|
||||
"main": "test.js",
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^5.2.1",
|
||||
"jest": "^30.3.0",
|
||||
"supertest": "^7.2.2"
|
||||
}
|
||||
}
|
||||
26
test.js
Normal file
26
test.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// console.log("Running CI test...");
|
||||
|
||||
// if (1 + 1 === 2) {
|
||||
// console.log("✅ TEST PASSED");
|
||||
// process.exit(0);
|
||||
// } else {
|
||||
// console.log("❌ TEST FAILED");
|
||||
// process.exit(1);
|
||||
// }
|
||||
|
||||
const request = require("supertest");
|
||||
const app = require("./index");
|
||||
|
||||
describe("API Testing", () => {
|
||||
|
||||
test("GET / should return status ok", async () => {
|
||||
const res = await request(app).get("/");
|
||||
expect(res.body.status).toBe("ok");
|
||||
});
|
||||
|
||||
test("GET /health should return status OK", async () => {
|
||||
const res = await request(app).get("/health");
|
||||
expect(res.body.status).toBe("OK");
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user