Templates / Automatic jest test generation for GitHub PRs with dual AI review

Automatic jest test generation for GitHub PRs with dual AI review

Needs changes

by Varritech ✓ · 639 views · created 2025-05-13 · Engineering, Multimodal AI

Needs changes. This template uses 1 thing(s) that n8n 3.0 removes: AI Agent v1 (old agent modes). 1 breaking item(s) found. Static check, last run 2026-10-19.

What to replace before upgrading

Removed in 3.0Replace with
AI Agent v1 (old agent modes)
Test Maker (v1.8), Code Reviewer (v1.8)
Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent.

Nodes used (9)

GitHubStructured Output ParserAI AgentOpenAI Chat Model

What it does

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 mermaid flowchart LR AWebhook: /github/pr-events --> BGitHub: Get PR B --> CFunction: Parse diffurl + owner/repo C --> DHTTP Request: GET diffurl D --> EFunction: Split on "diff --git" E --> FFilter: /\.tsx$/ F --> GGitHub: Get File Contents G --> HTest Maker Agent H --> ICode Reviewer Agent I --> JFunction: Build Comment Payload J --> KHTTP Request: POST to PR Comments Webhook: GitHub PR Events - Type: HTTP Webhook (/webhook/github/pr-events) - Subscribed Events: pullrequest.opened, pullrequest.synchronize GitHub: Get PR - Node: GitHub - Action: "Get Pull Request" - Inputs: owner, repo, pullnumber Function: Parse diffurl + owner/repo - Extracts: - diffurl (e.g. …/pulls/123.diff) - owner, repo, mergecommitsha HTTP Request: GET diffurl - Fetches unified-diff text for the PR. Function: Split on "diff --git" - Splits the diff into file-specific segments. Filter: /.tsx$/ - Keeps only segments where the file path ends with .tsx. GitHub: Get File Contents - For each .tsx file, fetches the latest blob via GitHub API. Test Maker Agent - Prompt: - "Generate Jest unit tests covering only the behaviors changed in these diff hunks." - Output: Raw Jest test code. Code Reviewer Agent - Reads file + generated tests - Prompt: - "Review and improve these tests for readability, edge-cases, and naming conventions." - Output: Polished test suite. Function: Build Comment Payload - Wraps tests in TypeScript fences: ts // generated tests… - Constructs JSON: json { "body": "<tests>" } HTTP Request: POST to PR Comments - URL: https://api.github.com/repos/{owner}/{repo}/issues/{pullnumber}/comments - Body: Contains the suggested tests. 🔍 Design Rationale & Best Practices Focused Diff Analysis - Targets only .tsx files to cover UI logic. Two-Stage AI - Separate "generate" + "review" steps mimic TDD + code review. Stateless Functions - Pure JS for parsing & transformation, easy to test. Non-Blocking PR Comments - Asynchronous suggestions—developers aren't blocked. Scoped Permissions - GitHub token limited to reading PRs & posting comments.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.