Skip to main content

Automatic jest test generation for GitHub PRs with dual AI review

Workflow preview

Workflow preview
100%
Automatic jest test generation for GitHub PRs with dual AI review preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

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 ...

Best for

  • Engineering automation workflows
  • Multimodal AI automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.github, n8n-nodes-base.httprequest, n8n-nodes-base.code, n8n-nodes-base.githubtool, @n8n/n8n-nodes-langchain.outputparserstructured, n8n-nodes-base.merge, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.lmchatopenai

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Varritech.

Original n8n.io source

1.1 Workflow description

Title
Automatic jest test generation for GitHub PRs with dual AI review
Workflow name
Automatic jest test generation for GitHub PRs with dual AI review

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

  • 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:
// generated tests…
  • Constructs 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.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - GH - Get PR

Type / Role
n8n-nodes-base.github - github
Config choices
Version 1

Block 2 - GET .diff file

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 3 - Splits text into array

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 4 - FIlter for components

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 5 - Extrat API URL, owner and repo

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 6 - Get File name

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 7 - Get Files

Type / Role
n8n-nodes-base.githubTool - githubTool
Config choices
Version 1

Block 8 - Structured Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.2

Block 9 - Merge info needed

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.1

Block 10 - Test Maker

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.8

Block 11 - Get Repo

Type / Role
n8n-nodes-base.githubTool - githubTool
Config choices
Version 1

Block 12 - Code Reviewer

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.8

Block 13 - o3-mini

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 14 - gpt4.1-mini

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 15 - Merge

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.1

Block 16 - Prepare for POST

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 17 - POST Comments

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 18 - Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 2

Block 19 - 2nd Node for Testing

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 20 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 21 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 22 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 23 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 24 - Structured Output Parser1

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.2

3. Summary Table

Workflow Automatic jest test generation for GitHub PRs with dual AI review
Complexity advanced
Nodes 24
Categories Engineering, Multimodal AI
Author Varritech
Published 13 May 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/4013/4013.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Automatic jest test generation for GitHub PRs with dual AI review do?

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 ...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, Multimodal AI use case.