This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
# - run: echo "Hello from Gitea Actions"
|
||||
|
||||
|
||||
name: Node CI Test
|
||||
name: Node API Test
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -26,10 +26,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
24
index.js
24
index.js
@@ -0,0 +1,24 @@
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.send("🚀 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
|
||||
if (require.main === module) {
|
||||
app.listen(3000, () => {
|
||||
console.log("Server running on port 3000");
|
||||
});
|
||||
}
|
||||
4200
package-lock.json
generated
4200
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,10 +11,12 @@
|
||||
"type": "commonjs",
|
||||
"main": "test.js",
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
|
||||
"test": "jest",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^5.2.1"
|
||||
"express": "^5.2.1",
|
||||
"jest": "^30.3.0",
|
||||
"supertest": "^7.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
33
test.js
33
test.js
@@ -1,9 +1,26 @@
|
||||
console.log("Running CI test...");
|
||||
// console.log("Running CI test...");
|
||||
|
||||
if (1 + 1 === 2) {
|
||||
console.log("✅ TEST PASSED");
|
||||
process.exit(0);
|
||||
} else {
|
||||
console.log("❌ TEST FAILED");
|
||||
process.exit(1);
|
||||
}
|
||||
// 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 home message", async () => {
|
||||
const res = await request(app).get("/");
|
||||
expect(res.text).toBe("🚀 Home Route Working");
|
||||
});
|
||||
|
||||
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