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

@n1k1t/unit-generator

v1.0.5

Published

Coverage based unit tests AI generator

Readme

License npm version Dynamic XML Badge

Install

npm i -D @n1k1t/unit-generator

How it works?

It automatically prompts with AI models to generate new (or fix falling) unit tests. For more efficiency it uses actual cobertura coverage

First steps

  1. Get access to API key on the OpenAI platform
  2. Allow access to model gpt-5-mini or another one
  3. Make .env file in the root of project that contents:
# AI platform key (required)
UNIT_GENERATOR_API_KEY="API_KEY"
# AI platform/LiteLLM base url (optional)
UNIT_GENERATOR_API_URL="BASE_URL_TO_AI_PLATFORM"
# Command that will be used to generate unit tests (optional)
UNIT_GENERATOR_TEST_COMMAND="npx jest"
# AI model to use for unit tests generation (optional)
UNIT_GENERATOR_MODEL="gpt-5-mini"
  1. Setup project with Jest
{
  // Cobertura reporter is required
  "coverageReporters": ["cobertura"],
  // Recommend
  "collectCoverageFrom": ["<rootDir>/src/**/*.ts"],
  // Recommend
  "passWithNoTests": true,
}
  1. Install the @n1k1t/unit-generator
  2. Run npx unit calculate command
$ npx unit calculate

┌─────────┬───────┬────────────────────────┐
│ (index) │ rate  │ updated                │
├─────────┼───────┼────────────────────────┤
│ 0       │ 0.689 │ '20.03.2025, 19:48:31' │
└─────────┴───────┴────────────────────────┘
  1. Done! Now try to use generate command

API

General

$ npx unit -h

Usage: cli [options] [command]

It generates unit-tests by Jest coverage

Options:
  -h, --help                    display help for command

Commands:
  summary [options]             Returns an overall coverage in the project
  calculate                     Calculates a coverage of the whole project and returns summary
  analyze [options] [pattern]   Returns a table of low covered project files
  generate [options] [pattern]  Generates unit tests
  fix [options] [pattern]       Fixes falling unit tests
  help [command]                display help for command

Command summary

$ npx unit summary -h

Usage: cli summary [options]

Returns an overall coverage in the project

Options:
  -f --format [table|number]  Output format (default: "table")
  -h, --help                  display help for command

Examples

$ npx unit summary

┌─────────┬───────┬────────────────────────┐
│ (index) │ rate  │ updated                │
├─────────┼───────┼────────────────────────┤
│ 0       │ 0.689 │ '20.03.2025, 19:48:31' │
└─────────┴───────┴────────────────────────┘
$ npx unit summary -f number

0.689

Command calculate

$ npx unit calculate -h

Usage: cli calculate [options]

Calculates a coverage of the whole project and returns summary

Options:
  -h, --help  display help for command

Examples

$ npx unit calculate

┌─────────┬───────┬────────────────────────┐
│ (index) │ rate  │ updated                │
├─────────┼───────┼────────────────────────┤
│ 0       │ 0.689 │ '20.03.2025, 20:11:16' │
└─────────┴───────┴────────────────────────┘

Command analyze

$ npx unit analyze -h

Usage: cli analyze [options] [pattern]

Returns a table of low covered project files

Options:
  -t, --target [value]  Desired coverage target of an each file (default: "0.8")
  -l --limit [value]    Files limit (default: "5")
  -a --all              Takes all paths provided by pattern (default: false)
  -h, --help            display help for command

Examples

$ npx unit analyze -l 3 src/utils

┌─────────┬────────────────────────────────────────────────────────┬───────┐
│ (index) │ file                                                   │ rate  │
├─────────┼────────────────────────────────────────────────────────┼───────┤
│ 0       │ 'src/utils/streams/text-transform.ts'                  │ 0.107 │
│ 1       │ 'src/utils/streams/sse.ts'                             │ 0.316 │
│ 2       │ 'src/utils/dto/validators/has-dates-diff.validator.ts' │ 0.421 │
└─────────┴────────────────────────────────────────────────────────┴───────┘

Command generate

$ npx unit generate -h

Usage: cli generate [options] [pattern]

Generates unit tests

Options:
  -t, --target [value]      Desired coverage target of an each file (default: "0.8")
  -m, --model [value]       AI model to use for unit tests generation (default: "gpt-4o-mini")
  -i, --iterations [value]  Iterations maximum of unit tests generation (default: "5")
  -l --limit [value]        Files limit (default: "5")
  -a --all                  Takes all paths provided by pattern (default: false)
  -h, --help                display help for command

Examples

$ npx unit generate src/models/assistant/strategies

┌─────────┬──────────────────────────────────────────┬──────┬────────┬───────────┬──────────┬─────────────┬─────────┐
│ (index) │ file                                     │ rate │ target │ iteration │ strategy │ status      │ spent   │
├─────────┼──────────────────────────────────────────┼──────┼────────┼───────────┼──────────┼─────────────┼─────────┤
│ 0       │ 'src/models/assistant/strategies/add.ts' │ 0.79 │ 1      │ 5         │ 'ADD'    │ 'COMPLETED' │ 103.012 │
└─────────┴──────────────────────────────────────────┴──────┴────────┴───────────┴──────────┴─────────────┴─────────┘

Command fix

$ npx unit fix -h

Usage: cli fix [options] [pattern]

Fixes falling unit tests

Options:
  -m, --model [value]       AI model to use for unit tests generation (default: "gemini-flash-latest")
  -i, --iterations [value]  Iterations maximum of unit tests generation (default: "5")
  -l --limit [value]        Files limit (default: "5")
  -a --all                  Takes all paths provided by pattern (default: false)
  -h, --help                display help for command

Examples

$ npx unit fix src/utils

┌─────────┬──────────────────────────────┬──────┬────────┬───────────┬──────────┬─────────────┬─────────┐
│ (index) │ file                         │ rate │ target │ iteration │ strategy │ status      │ spent   │
├─────────┼──────────────────────────────┼──────┼────────┼───────────┼──────────┼─────────────┼─────────┤
│ 0       │ 'src/utils/streams/sse.ts'   │ 0.31 │ 1      │ 1         │ 'FIX'    │ 'COMPLETED' │ 15.421  │
└─────────┴──────────────────────────────┴──────┴────────┴───────────┴──────────┴─────────────┴─────────┘

Additional

ENV

# AI platform key
export UNIT_GENERATOR_API_KEY="..."

# Desired coverage target of an each file (optional)
export UNIT_GENERATOR_COVERAGE_TARGET="0.8"
# Path to the cobertura-coverage.xml file generated (optional)
export UNIT_GENERATOR_COBERTURA_PATH="coverage/cobertura-coverage.xml"
# Iterations maximum of unit tests generation (optional)
export UNIT_GENERATOR_MAX_ITERATIONS="5"
# Command that will be used to generate unit tests (optional)
export UNIT_GENERATOR_TEST_COMMAND="npm test"
# AI platform base url (optional)
export UNIT_GENERATOR_API_URL="..."
# AI model to use for unit tests generation (optional)
export UNIT_GENERATOR_MODEL="gemini-flash-latest"
# AI provider (optional)
export UNIT_GENERATOR_PROVIDER="google"
# Marker to identify generated tests (optional)
export UNIT_GENERATOR_MARKER="/* Generated by @n1k1t/unit-generator */"
# Enable parallel generation (optional)
export UNIT_GENERATOR_PARALLEL="true"
# Enable debug mode and telemetry (optional)
export UNIT_GENERATOR_DEBUG="false"

Ignore file

The unit-generator package supports .unitignore file that can contain path matches using minimatch expressions

Examples

src/**/*.module.ts
src/**/index.ts
lib/**