Socket
Book a DemoInstallSign in
Socket

@endbug/jest-pr-reporter

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@endbug/jest-pr-reporter

An opinionated Jest reporter meant for GitHub Actions & PRs

1.0.3
latest
Source
npmnpm
Version published
Weekly downloads
10
-52.38%
Maintainers
1
Weekly downloads
 
Created
Source

Jest PR Reporter

An opinionated Jest reporter that creates GitHub PR comments with test results.

Jest PR Reporter Example

Features

  • ✅ Creates GitHub PR comments with test results
  • ✅ Updates existing comments automatically
  • ✅ Shows detailed test failure information
  • ✅ Configurable footers for success/failure cases

Installation

npm install @endbug/jest-pr-reporter
# or
yarn add @endbug/jest-pr-reporter

Configuration

Add the reporter to your Jest configuration:

// jest.config.js
module.exports = {
  reporters: [
    "default",
    [
      "@endbug/jest-pr-reporter",
      {
        githubToken: process.env.GITHUB_TOKEN,
        owner: process.env.GITHUB_REPOSITORY_OWNER,
        repo:
          process.env.GITHUB_REPOSITORY &&
          process.env.GITHUB_REPOSITORY.split("/")[1],
        prNumber: Number(process.env.PR_NUMBER), // Set this in your workflow or pass as env
        sha: process.env.GITHUB_SHA,
        workspace: process.env.GITHUB_WORKSPACE, // optional
        workflowRunId: process.env.GITHUB_RUN_ID,
        jobName: process.env.GITHUB_JOB,
        footerSuccess: "🎉 All tests passed!",
        footerFailed: "❌ Please fix the failing tests.",
        hideProjectTag: false, // optional, defaults to false
        failOnError: false, // optional, defaults to false
      },
    ],
  ],
};

Options

OptionTypeRequiredDescription
githubTokenstringGitHub personal access token or GitHub App token
ownerstringGitHub repository owner (username or organization)
repostringGitHub repository name
prNumbernumberPull request number
shastringCommit SHA for linking to specific files
workflowRunIdstringGitHub workflow run ID for linking to the specific run
jobNamestringGitHub job name (numeric ID is automatically extracted)
workspacestringWorkspace path for normalizing test file paths
footerSuccessstringCustom footer text when tests pass
footerFailedstringCustom footer text when tests fail
hideProjectTagbooleanWhether to hide the project attribution tag
failOnErrorbooleanWhether to fail the build if comment creation fails
headerstringCustom string to append to the HTML comment header

Usage Examples

Basic Usage

// jest.config.js
module.exports = {
  reporters: [
    "default",
    [
      "@endbug/jest-pr-reporter",
      {
        githubToken: process.env.GITHUB_TOKEN,
        owner: "EndBug",
        repo: "jest-pr-reporter",
        prNumber: 1,
        sha: process.env.GITHUB_SHA,
        workflowRunId: process.env.GITHUB_RUN_ID,
        jobName: process.env.GITHUB_JOB,
      },
    ],
  ],
};

With Custom Footers

// jest.config.js
module.exports = {
  reporters: [
    "default",
    [
      "@endbug/jest-pr-reporter",
      {
        githubToken: process.env.GITHUB_TOKEN,
        owner: "EndBug",
        repo: "jest-pr-reporter",
        prNumber: 1,
        sha: process.env.GITHUB_SHA,
        workflowRunId: process.env.GITHUB_RUN_ID,
        jobName: process.env.GITHUB_JOB,
        footerSuccess: "🎉 Tests are passing! You can merge this PR.",
        footerFailed:
          "❌ Please review and fix the failing tests before merging.",
      },
    ],
  ],
};

With Custom Header

// jest.config.js
module.exports = {
  reporters: [
    "default",
    [
      "@endbug/jest-pr-reporter",
      {
        githubToken: process.env.GITHUB_TOKEN,
        owner: "EndBug",
        repo: "jest-pr-reporter",
        prNumber: 1,
        sha: process.env.GITHUB_SHA,
        workflowRunId: process.env.GITHUB_RUN_ID,
        jobName: process.env.GITHUB_JOB,
        header: "my-tests", // Results in: <!-- Sticky Pull Request Comment jest-pr-reporter: my-tests -->
      },
    ],
  ],
};

Advanced Configuration with Environment Variables

For more complex setups, you can separate the reporter options and use environment variables:

// jest.config.js
/** @type {import('@endbug/jest-pr-reporter').ReporterOptions} */
const reporterOptions = {
  githubToken: process.env.GH_TOKEN,
  owner: process.env.GITHUB_REPOSITORY_OWNER,
  repo:
    process.env.GITHUB_REPOSITORY &&
    process.env.GITHUB_REPOSITORY.split("/")[1],
  prNumber: Number(process.env.PR_NUMBER),
  sha: process.env.GITHUB_SHA,
  workspace: process.env.GITHUB_WORKSPACE,
  workflowRunId: process.env.GITHUB_RUN_ID,
  jobName: process.env.GITHUB_JOB,
  header: "jest-tests",
  footerFailed: `## 🛠️ Next Steps

1. **Review** the failing tests above
2. **Fix** your files so that the tests pass
3. **Push changes** and ensure CI passes

> [!TIP]
> Need help? Check the [README](https://github.com/campus-experts/campus-experts.github.io#readme) or ask in the Discord.
`.trim(),
};

module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  reporters:
    process.env.CI === "true"
      ? [["@endbug/jest-pr-reporter", reporterOptions], "summary"]
      : ["default"],
};

In GitHub Actions

# .github/workflows/test.yml
name: Tests
on: [pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: "18"
      - run: npm ci
      - run: npm test
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PR_NUMBER: ${{ github.event.pull_request.number }}

Examples

Check the examples/ directory for more detailed examples:

How It Works

The reporter:

  • Runs after Jest completes all tests
  • Creates a detailed comment with test results
  • Shows passing/failing test counts and summaries
  • Links to specific test files and line numbers
  • Includes links to the specific workflow run for traceability
  • Updates existing comments automatically
  • Provides configurable footers for different scenarios
  • Uses HTML comments with customizable headers for comment identification

License

MIT

FAQs

Package last updated on 11 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.