From 0b5c0a8ab10249d6a4b6fb3de911d4df96d00725 Mon Sep 17 00:00:00 2001 From: Nageshwaran Manikumar Date: Thu, 22 Oct 2026 20:48:38 -0400 Subject: [PATCH 1/4] Add Jenkins CI pipeline and Node.js automated tests --- Jenkinsfile | 49 +++++++++++++++++++++++++++++++++++++++++ app/package.json | 9 ++++++++ app/src/health.js | 8 +++++++ app/test/health.test.js | 17 ++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 Jenkinsfile create mode 100644 app/package.json create mode 100644 app/src/health.js create mode 100644 app/test/health.test.js diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..6c0219b --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,49 @@ +pipeline { + agent any + + options { + disableConcurrentBuilds() + timeout(time: 5, unit: 'MINUTES') + buildDiscarder(logRotator(numToKeepStr: '5')) + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Verify Node.js') { + steps { + sh 'node --version' + sh 'npm --version' + } + } + + stage('Syntax Check') { + steps { + dir('app') { + sh 'npm run check' + } + } + } + + stage('Automated Tests') { + steps { + dir('app') { + sh 'npm test' + } + } + } + } + + post { + success { + echo 'CI PASSED: All checks completed successfully.' + } + failure { + echo 'CI FAILED: Review the Jenkins console output.' + } + } +} diff --git a/app/package.json b/app/package.json new file mode 100644 index 0000000..bdedf8b --- /dev/null +++ b/app/package.json @@ -0,0 +1,9 @@ +{ + "name": "startup-product", + "version": "1.0.0", + "private": true, + "scripts": { + "test": "node --test", + "check": "node --check src/health.js" + } +} diff --git a/app/src/health.js b/app/src/health.js new file mode 100644 index 0000000..b716c60 --- /dev/null +++ b/app/src/health.js @@ -0,0 +1,8 @@ +function getHealthStatus(databaseConnected) { + return { + status: databaseConnected ? "healthy" : "unhealthy", + database: databaseConnected ? "connected" : "disconnected" + }; +} + +module.exports = { getHealthStatus }; diff --git a/app/test/health.test.js b/app/test/health.test.js new file mode 100644 index 0000000..2757eef --- /dev/null +++ b/app/test/health.test.js @@ -0,0 +1,17 @@ +const test = require("node:test"); +const assert = require("node:assert/strict"); +const { getHealthStatus } = require("../src/health"); + +test("reports healthy when database is connected", () => { + assert.deepEqual(getHealthStatus(true), { + status: "healthy", + database: "connected" + }); +}); + +test("reports unhealthy when database is disconnected", () => { + assert.deepEqual(getHealthStatus(false), { + status: "unhealthy", + database: "disconnected" + }); +}); From cb7a62a2a5d061f4b5ca3cb8320f1774da36957c Mon Sep 17 00:00:00 2001 From: Nageshwaran Manikumar Date: Thu, 22 Oct 2026 22:38:43 -0400 Subject: [PATCH 2/4] Test automatic Jenkins webhook trigger --- ci-webhook-test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 ci-webhook-test.txt diff --git a/ci-webhook-test.txt b/ci-webhook-test.txt new file mode 100644 index 0000000..283299c --- /dev/null +++ b/ci-webhook-test.txt @@ -0,0 +1 @@ +Jenkins webhook automatic build test From e1d900755c8cdee7d12c1fba0017daef3fce8c15 Mon Sep 17 00:00:00 2001 From: Nageshwaran Manikumar Date: Fri, 23 Oct 2026 02:41:40 -0400 Subject: [PATCH 3/4] Demonstrate Jenkins CI failure with intentional test mismatch --- app/test/health.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/health.test.js b/app/test/health.test.js index 2757eef..bffc9d4 100644 --- a/app/test/health.test.js +++ b/app/test/health.test.js @@ -3,7 +3,7 @@ const assert = require("node:assert/strict"); const { getHealthStatus } = require("../src/health"); test("reports healthy when database is connected", () => { - assert.deepEqual(getHealthStatus(true), { + assert.deepEqual(getHealthStatus(false), { status: "healthy", database: "connected" }); From e00142ae090056c02af9ba14cd5153c5f8734392 Mon Sep 17 00:00:00 2001 From: Nageshwaran Manikumar Date: Fri, 23 Oct 2026 02:55:58 -0400 Subject: [PATCH 4/4] Fix failing health check test and restore CI --- app/test/health.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/health.test.js b/app/test/health.test.js index bffc9d4..2757eef 100644 --- a/app/test/health.test.js +++ b/app/test/health.test.js @@ -3,7 +3,7 @@ const assert = require("node:assert/strict"); const { getHealthStatus } = require("../src/health"); test("reports healthy when database is connected", () => { - assert.deepEqual(getHealthStatus(false), { + assert.deepEqual(getHealthStatus(true), { status: "healthy", database: "connected" });