Compare commits
7 Commits
d9b1459611
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e39dfe6f2b | |||
| 79008d0c7c | |||
| 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:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -6,9 +22,19 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- 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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
app.get("/", (req, res) => {
|
||||||
|
res.json({
|
||||||
|
status: "OK",
|
||||||
|
message: "Home Route"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
}
|
||||||
Generated
+5025
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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