Automatic jest test generation for GitHub PRs with dual AI revie
Workflow: Automatic Unit Test Creator from GitHub 🏗️ Architecture Overview This workflow listens for GitHub pull-request events, analyzes changed React/Type...
🔌 Nodes & Integrations Used (6)
📖 Implementation & Setup Guide
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:
- GitHub Webhook → PR opened or updated
- Fetch & Diff → Retrieve raw diff of changed files
- Filter & Split → Isolate .tsx files & their diffs
- Fetch File Contents → Provide full context for tests
- Test Maker Agent → Generate Jest tests for diff hunks
- Code Reviewer Agent → Refine tests for style & edge-cases
- Post PR Comment → Sends suggested tests back to GitHub
📦 Node-by-Node Breakdown
```mermaid 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 - Type: HTTP Webhook (`/webhook/github/pr-events`) - Subscribed Events: `pull_request.opened`, `pull_request.synchronize`
GitHub: Get PR - Node: GitHub - Action: "Get Pull Request" - Inputs: owner, repo, pull_number
Function: Parse diff_url + owner/repo - Extracts: - diff_url (e.g. …/pulls/123.diff) - owner, repo, merge_commit_sha
HTTP Request: GET diff_url - 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/{pull_number}/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.
⚡ How to import this workflow into n8n:
- Click the Direct Download JSON button above to save
Automatic_jest_test_generation_for_GitHub_PRs_with_dual_AI_revie.json. - Log in to your n8n Cloud or self-hosted n8n instance.
- In your workflow canvas, click the menu in top-right and select Import from File (or paste the JSON directly).
- Configure your credentials (e.g. API keys, database URLs) in the corresponding node settings.
- Click Execute Workflow to test and switch to Active!
Related AI Agents Workflows
View All in AI Agents →5 ways to process images PDFs with Gemini AI in n8n
How it works Many users have asked in the support forum about different methods to analyze images and PDF documents with Google Gemini AI in n8n. This workfl...
7 AI Sales Assistant
Production-ready n8n automation template for 7 AI Sales Assistant built by AhiXLight. Seamlessly connects Airtop Tool, Slack, Airtop with 24 configured nodes.
AAVE portfolio professional AI agent Telegram Email GPT 4o
A next-generation AI-powered DeFi health monitor that tracks wallet positions across Aave V3 using GPT-4o and LangChain. It delivers human-readable reports v...
Access control for AI agents RBAC using Airtable and Telegram
Purpose This workflow allows granular control over the access to tools connected to AI Agents (including Multi-Agent setups) using Role Based Access Control....