An open API service indexing awesome lists of open source software.

https://github.com/yashpandey1405/github-actions-cicd-testing

A mini-project demonstrating CI/CD pipeline setup using GitHub Actions for a Node.js Express API, with automated testing via Jest and Supertest
https://github.com/yashpandey1405/github-actions-cicd-testing

cicd-pipeline github-actions testing

Last synced: 5 days ago
JSON representation

A mini-project demonstrating CI/CD pipeline setup using GitHub Actions for a Node.js Express API, with automated testing via Jest and Supertest

Awesome Lists containing this project

README

          

# โš™๏ธ CI/CD Pipeline with GitHub Actions & API Testing

A mini-project demonstrating **CI/CD pipeline implementation using GitHub Actions** and **automated API route testing** with **Jest** and **Supertest** for a Node.js Express application.

---

## ๐Ÿ“Œ What is CI/CD?

**CI/CD** stands for:

- **Continuous Integration (CI)** โ€“ Automatically test and build your app whenever you push code to the repository.
- **Continuous Deployment (CD)** โ€“ Automatically deploy the app when the tests pass, ensuring your latest code is always live.

These pipelines:

- Detect code changes (`git push`)
- Run test suites
- Deploy only on success
- Eliminate manual errors & reduce dev-ops overhead

---

## โš™๏ธ What are GitHub Actions?

**GitHub Actions** is an automation tool provided by GitHub. You can define custom workflows in `.yml` files to:

- Run tests
- Build and deploy code
- Trigger jobs based on events like commits or pull requests

This project uses a GitHub Action to:

1. Install dependencies
2. Run tests
3. Deploy via a Render deploy hook (only if all tests pass โœ…)

---

## ๐Ÿงช What is Unit Testing using Jest & Supertest?

### **Jest**:

A JavaScript testing framework by Facebook for writing unit tests. It supports:

- Assertions (`expect(...)`)
- Mocks and spies
- Test runners

### **Supertest**:

A high-level abstraction to test HTTP endpoints. It simulates requests and checks responses without needing to deploy the server externally.

### ๐Ÿ” Example:

```js
it("GET / returns Hello World", async () => {
const res = await request(app).get("/");
expect(res.statusCode).toBe(200);
expect(res.text).toBe("Hello World");
});
```

---

## ๐Ÿš€ Project Overview

This mini-project includes:

- A simple Express server with two routes:

- `/` โ†’ Returns `Hello World`
- `/:id` โ†’ Returns `Hello World `

- Test cases for both routes using **Jest** and **Supertest**
- A GitHub Actions workflow to automatically:

- Install dependencies
- Run tests
- Deploy to Render (if tests pass)

---

## โœ… Correct Test Results

When the routes are implemented correctly, **all test cases pass** successfully:

![Correct Tests](./asserts/Correct-Test-Results.png)

---

## โŒ Failed Test Results

If any route is broken or missing, **relevant test cases fail**, ensuring reliability:

## ![Wrong Tests](./asserts/Wrong-Test-Results.png)

---

## โœ… Automated Testing via GitHub Actions

Every code push triggers **automated testing on GitHub Actions**.
If any route fails, the pipeline halts โ€” ensuring only **fully tested, reliable code** gets deployed.

![GitHub Actions](./asserts/GitHub-Actions.png)

---

## ๐Ÿ“ Tech Stack

- **Node.js / Express**
- **Jest** for testing logic
- **Supertest** for endpoint testing
- **GitHub Actions** for CI/CD automation
- **Render** for deployment (via deploy hook)

---

## ๐Ÿง  Learning Outcomes

โœ… Understand CI/CD and GitHub Actions
โœ… Build & test Express routes
โœ… Automate testing and deployment pipeline
โœ… Visualize real test outcomes (pass vs fail)

---

## ๐Ÿง‘โ€๐ŸŽ“ Author

**Made with ๐Ÿ’ป, โ˜• and GitHub Actions** by [Yash Pandey](https://github.com/YashPandey-dev)