npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ci-testgen

v0.0.7

Published

Integrates into your CI/CD pipeline to generate test cases for your codebase.

Downloads

40

Readme

CI TestGen

This project is designed to automate the generation, showing, and applying of tests for your GitHub and GitLab projects.

Prerequisites

  • Node.js (version 20 or higher)
  • GitHub or GitLab account with appropriate permissions

How to Use

This tool is available via npx but is meant to be used in the CI/CD pipeline. Once you have finished setting up the tool with GitHub / GitLab, the workflow is as follows:

  1. Create or Update a Pull/Merge Request: When a developer creates or updates a pull/merge request, the generate-tests command will automatically run in the CI/CD pipeline. This will generate tests based on the changes and post them as comments in the pull/merge request.

  2. Review Generated Tests: The developer will see the generated tests as comments in the pull/merge request. They can review these tests and decide which ones to approve.

  3. Approve Tests: To approve a test, the developer should react with a 👍 emoji to the comment containing the test they want to approve.

  4. Trigger Test Application: After approving the desired tests, the developer should type "testgen" into a new comment in the pull/merge request. This will trigger the apply-tests command in the CI/CD pipeline.

  5. Apply Approved Tests: The apply-tests command will apply the approved tests and push the changes to the branch associated with the pull/merge request.

Setting up with GitHub

Adding generate-tests workflow

Create .github/workflows/generate-tests.yml with the following content:

name: Generate Tests

on:
  pull_request:
    branches:
      - master
      - main

jobs:
  generate_tests:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 1
      - name: Generate and post tests
        run: npx ci-testgen generate-tests --gitRemote=github --token=${{ secrets.GITHUB_TOKEN }} --repoDir=$GITHUB_WORKSPACE --owner=${{ github.repository_owner }} --repo=${{ github.event.repository.name }} --pullRequestId=${{ github.event.number }}

Adding apply-tests workflow

Create .github/workflows/apply-tests.yml with the following content:

name: Apply Tests

on:
  issue_comment:
    types:
      - created
      - edited

jobs:
  apply-test:
    if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, 'testgen') }}
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 1
      - name: Apply approved tests
        run: npx ci-testgen apply-tests --gitRemote=github --token=${{ secrets.GITHUB_TOKEN }} --repoDir='.' --owner=${{ github.repository_owner }} --repo=${{ github.event.repository.name }} --pullRequestId=${{ github.event.issue.number }} --triggerCommentId=${{ github.event.comment.id }} --triggerCommentBody=${{ github.event.comment.body }}

Done! You have completed the setup with GitHub.

Setting up with GitLab

Adding generate-tests workflow

Modify the .gitlab-ci.yml of the repo to add the new stage and job.

stages:
# ...existing stages...
  - generate_tests

# ...existing jobs...

generate_tests_job:
  stage: generate_tests
  needs: []
  image: node:20
  variables:
    GIT_DEPTH: 1
  script:
    - npx ci-testgen generate-tests --gitRemote=gitlab --token=$ACCESS_TOKEN --repoDir=$CI_PROJECT_DIR --projectId=$CI_PROJECT_ID --apiUrl=$CI_API_V4_URL --mergeRequestId=$CI_MERGE_REQUEST_IID
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
      when: always

Adding apply-tests workflow

Since GitLab doesn't allow specific triggering of jobs, the following .gitlab-ci.yml should live inside an orphaned branch to ensure it only runs when explicitly triggered and doesn't interfere with other pipelines.

stages:
  - api_stage

api_only_job:
  stage: api_stage
  image: node:20
  rules:
    - if: $CI_PIPELINE_SOURCE == "trigger"
  variables:
    GIT_DEPTH: 1
  script:
    - npx ci-testgen apply-tests --gitRemote=gitlab --token=$ACCESS_TOKEN --repoDir=$CI_PROJECT_DIR --projectId=$CI_PROJECT_ID --apiUrl=$CI_API_V4_URL --triggerPayloadPath=$TRIGGER_PAYLOAD

To create an Orphaned Branch:

  1. Create the branch
git checkout --orphan ci-testgen-apply-test-workflow
git rm -rf . # Clear the staging area
  1. Add the above .gitlab-ci.yml file to the branch.
git add .gitlab-ci.yml
  1. Commit and Push the Branch:
git commit -m "Add apply-tests workflow in orphaned branch"
git push origin ci-testgen-apply-test-workflow

Webhook Setup for GitLab

  1. Provision a Pipeline Trigger Token:

    • Go to Settings > CI/CD > Pipeline Trigger Tokens.
    • Add a new token and call it Testgen Token.
  2. Add a Webhook:

    • Go to Settings > Webhooks and click "Add new webhook".
    • For the URL, use: https://gitlab.com/api/v4/projects/<project-id>/ref/ci-testgen-apply-test-workflow/trigger/pipeline?token=<pipeline-trigger-token>. Replace <project-id> with your GitLab project ID.
    • Under 'Trigger' section, check "Comments".
    • Under 'Name', use: 'Apply Testgen Test' (optional)

CI/CD Variables Setup for GitLab

  1. Provision an Access Token:

    • Go to Settings > Access Token and click "Add new token".
    • Use "Testgen" as the token name.
    • Select role to be developer and give the following scopes: api, read_api, read_repository, write_repository.
    • Set an appropriate expiration date for the token
  2. Store the Access Token:

    • Go to Settings > CI/CD > Variables and store the token with the key as ACCESS_TOKEN.
    • Either choose "masked" or "masked and hidden".
    • Untick the "Protect variable" option.

Contributing

Check out our guide at CONTRIBUTING.md

Additional Resources

For more information, refer to the official GitHub and GitLab documentation.