Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/WORKFLOW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# CI/CD Workflow Documentation

## GitHub Actions Workflow Overview

The `publish.yml` workflow now has two distinct jobs that run based on different triggers:

### 🧪 **Test Job**

**Triggers:**

- Push to any branch targeting main
- Pull requests to main branch

**What it does:**

- ✅ Runs on every push and PR
- ✅ Installs dependencies
- ✅ Executes test suite (`npm run test`)
- ✅ Validates Bruno variable functionality
- ✅ Ensures all assertions pass
- ✅ Provides feedback on test results

### 📦 **Version & Publish Job**

**Triggers:**

- Only on pushes to main branch (after tests pass)
- Never runs on PRs or other branches

**What it does:**

- ✅ Waits for test job to complete successfully (`needs: test`)
- ✅ Bumps package version (patch)
- ✅ Publishes to npm
- ✅ Commits version bump back to repository

## Workflow Behavior Examples

### ✅ **Pull Request Scenario**

```
PR created → Test job runs → ✅ Tests pass → PR can be merged
PR created → Test job runs → ❌ Tests fail → PR blocked
```

### ✅ **Push to Main Scenario**

```
Push to main → Test job runs → ✅ Tests pass → Publish job runs → 📦 New version published
Push to main → Test job runs → ❌ Tests fail → Publish job skipped → ❌ No publish
```

### ✅ **Feature Branch Scenario**

```
Push to feature-branch → Test job runs → ✅ Tests pass → No publish (safe)
Push to feature-branch → Test job runs → ❌ Tests fail → Developer gets feedback
```

## Benefits

1. **🛡️ Protection**: No broken code reaches npm
2. **🔄 Continuous Feedback**: Tests run on every change
3. **🚀 Automated Releases**: Successful main branch pushes auto-publish
4. **👥 Team Safety**: PRs are validated before merge
5. **📊 Quality Gates**: Clear pass/fail indicators

## Test Exit Codes

- **Exit 0**: All tests passed ✅
- **Exit 1**: One or more tests failed ❌

## Commands

- `npm run test` - Run full test suite locally
- `npm run test:ci` - Same as above (for CI clarity)
- `npm run mock-server` - Start mock server manually
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,33 @@ on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org/"

- name: Install dependencies
run: yarn install --immutable

- name: Run tests
run: npm run test

version-and-publish:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Chappie is a test runner for Bruno collections. The Bruno CLI runner doesn't all
- Image comparison
- JSON schema validation
- Bruno response tests
- **Bruno variable support** - Use `{{variable}}` syntax and `bru.setVar()` / `bru.getVar()`

## Usage

Expand Down Expand Up @@ -39,6 +40,7 @@ chappie.run({
actualImagesFolder: './actual-images', // where to store the image results
baseImagesFolder'./base-images', // where to store the base images
diffImagesFolder'./diff-images', // where to store the diff images (if they exist),
allowCodeExecution: false, // set to true if the collection is trusted
onTestError: error => {
console.log("on test error: ", error.message);
},
Expand All @@ -54,6 +56,48 @@ chappie.run({
});
```

### Bruno Variables

Chappie supports Bruno's variable system, allowing you to:

1. **Set variables in tests** using `bru.setVar(key, value)`
2. **Use variables in URLs, headers, and request bodies** with `{{variableName}}` syntax
3. **Access variables in tests** using `bru.getVar(key)`

**Example Bruno Collection with Variables:**

```json
{
"name": "Variable Example",
"items": [
{
"name": "Set ID Variable",
"seq": 1,
"request": {
"url": "https://jsonplaceholder.typicode.com/todos",
"method": "GET",
"tests": "const response = res.getBody();\nif (Array.isArray(response) && response.length > 0) {\n bru.setVar('ID', response[0].id);\n}"
}
},
{
"name": "Use ID Variable",
"seq": 2,
"request": {
"url": "https://jsonplaceholder.typicode.com/todos/{{ID}}",
"method": "GET",
"tests": "test('Should get specific todo', function() {\n expect(res.getStatus()).to.equal(200);\n expect(res.getBody().id).to.equal(bru.getVar('ID'));\n});"
}
}
]
}
```

**Variable Features:**

- Variables are **automatically interpolated** in URLs, headers, and request body values
- Variables are **scoped per iteration** - they reset between iterations
- **Security note:** Variable interpolation respects the `allowCodeExecution` setting

### Reports

Chappie also supports JUNIT tests.
Expand All @@ -73,4 +117,5 @@ chappie.run({

- ✅ Image comparison
- ✅ JSON validation
- ✅ Bruno variables and interpolation
- ⬜️ Auth and token support
59 changes: 59 additions & 0 deletions mock-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Mock Data Setup

This directory contains JSON files that are served by the mock server for local testing.

## File Structure

- `todos.json` - Array of all todos (served at `/todos`)
- `todo-{id}.json` - Individual todo items (served at `/todos/{id}`)

## Usage

### 1. Start the mock server manually:

```bash
npm run mock-server
```

### 2. Run tests with the mock server:

```bash
npm run test
```

The test script automatically starts and stops the mock server.

## Available Endpoints

- `GET /todos` - Returns all todos from `todos.json`
- `GET /todos/:id` - Returns specific todo from `todo-{id}.json`

## Customizing Responses

### Adding new todos:

1. Add the todo to the `todos.json` array
2. Create a new `todo-{id}.json` file with the individual todo data

### Modifying existing responses:

1. Edit the appropriate JSON file
2. Restart the server (if running manually)

## Example Files

- `todo-1.json` - Basic todo item
- `todo-2.json` - Another basic todo item
- `todo-3.json` - Incomplete todo
- `todo-4.json` - Completed todo

## Testing Different Scenarios

You can create JSON files for different test scenarios:

- Error responses
- Edge cases
- Different data structures
- Empty responses

Just create the appropriate JSON file and the mock server will serve it automatically.
6 changes: 6 additions & 0 deletions mock-data/todo-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
6 changes: 6 additions & 0 deletions mock-data/todo-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"userId": 1,
"id": 2,
"title": "quis ut nam facilis et officia qui",
"completed": false
}
6 changes: 6 additions & 0 deletions mock-data/todo-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"userId": 1,
"id": 3,
"title": "fugiat veniam minus",
"completed": false
}
6 changes: 6 additions & 0 deletions mock-data/todo-4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"userId": 2,
"id": 4,
"title": "et porro tempora",
"completed": true
}
32 changes: 32 additions & 0 deletions mock-data/todos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
},
{
"userId": 1,
"id": 2,
"title": "quis ut nam facilis et officia qui",
"completed": false
},
{
"userId": 1,
"id": 3,
"title": "fugiat veniam minus",
"completed": false
},
{
"userId": 1,
"id": 4,
"title": "et porro tempora",
"completed": true
},
{
"userId": 1,
"id": 5,
"title": "laboriosam mollitia et enim quasi adipisci quia provident illum",
"completed": false
}
]
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
},
"scripts": {
"lint": "eslint ./src",
"prettier:fix": "npx prettier --write ./src"
"prettier:fix": "npx prettier --write ./src",
"test": "node test/test.js",
"mock-server": "node test/mock-server.js"
},
"files": [
"src/**/*.js",
Expand Down
Loading