⚒️ Automatic jest test generation for GitHub PRs with dual AI review

612 views · ⚒️ Engineering

Description

Workflow: Automatic Unit Test Creator from GitHub

🏗️ Architecture Overview

This workflow listens for GitHub pull-request events, analyzes changed React/TypeScript files, auto-generates Jest tests via AI, has them reviewed by a second AI pass, and posts suggestions back as PR comments:

  1. GitHub Webhook → PR opened or updated
  2. Fetch & Diff → Retrieve raw diff of changed files
  3. Filter & Split → Isolate .tsx files & their diffs
  4. Fetch File Contents → Provide full context for tests
  5. Test Maker Agent → Generate Jest tests for diff hunks
  6. Code Reviewer Agent → Refine tests for style & edge-cases
  7. Post PR Comment → Sends suggested tests back to GitHub

📦 Node-by-Node Breakdown

flowchart LR
  A[Webhook: /github/pr-events] --> B[GitHub: Get PR]
  B --> C[Function: Parse diff_url + owner/repo]
  C --> D[HTTP Request: GET diff_url]
  D --> E[Function: Split on "diff --git"]
  E --> F[Filter: /\.tsx$/]
  F --> G[GitHub: Get File Contents]
  G --> H[Test Maker Agent]
  H --> I[Code Reviewer Agent]
  I --> J[Function: Build Comment Payload]
  J --> K[HTTP Request: POST to PR Comments]

Webhook: GitHub PR Events

GitHub: Get PR

Function: Parse diff_url + owner/repo

HTTP Request: GET diff_url

Function: Split on “diff —git”

Filter: /.tsx$/

GitHub: Get File Contents

Test Maker Agent

Code Reviewer Agent

Function: Build Comment Payload

// generated tests…
{ "body": "<tests>" }

HTTP Request: POST to PR Comments

🔍 Design Rationale & Best Practices

Focused Diff Analysis

Two-Stage AI

Stateless Functions

Non-Blocking PR Comments

Scoped Permissions

🔗 Nodes Used

GitHub, HTTP Request, Webhook, AI Agent, OpenAI Chat Model, Structured Output Parser

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup