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

nuktatestify

v1.0.2

Published

Generate comprehensive, production-ready Jest test cases for Express.js APIs with MongoDB support

Downloads

25

Readme

nuktatestify

npm version MIT License

🚀 Generate comprehensive, production-ready Jest test cases for Express.js APIs with MongoDB support!


Table of Contents


Features

🎯 Core Features

  • 🔍 Intelligent route scanning with middleware detection
  • 📝 Comprehensive test generation for all HTTP methods
  • Multiple test types: Unit, Integration, Authentication, Validation, Error Handling, Performance
  • 🗂️ Modular test structure mirroring your codebase
  • 🔒 Security-focused testing with authentication and authorization
  • Performance testing with load and stress tests

🛠️ Advanced Features

  • 🗄️ MongoDB integration with in-memory database for testing
  • 🔐 JWT authentication testing with token management
  • 📊 Test coverage reporting with configurable thresholds
  • 🎭 Mock data generation with realistic test data
  • 🧪 Test fixtures and helpers for reusable test utilities
  • 📈 Performance benchmarking with response time validation
  • 🛡️ Security testing for common vulnerabilities

🎨 Developer Experience

  • 🎯 Smart route analysis with middleware detection
  • 📋 Detailed logging with verbose mode
  • 🔍 Dry-run capability to preview generated tests
  • 📝 Comprehensive documentation and examples
  • 🚀 Zero-config setup with sensible defaults

Installation

Global Installation (Recommended)

npm install -g nuktatestify

Local Installation

npm install --save-dev nuktatestify

Quick Start

Navigate to your Express.js project root and run:

# Basic usage
nuktatestify

# With verbose logging
nuktatestify --verbose

# Modular structure with all test types
nuktatestify --modular --auth-tests --validation-tests --error-tests --integration-tests --verbose

Advanced Usage

Command Line Options

| Option | Description | Default | | ---------------------- | ------------------------------------------------ | --------- | | --src, -s | Source directory to scan | src | | --out, -o | Output directory for test files | tests | | --ext, -e | Test file extension (test.js or spec.js) | test.js | | --modular, -m | Generate modular test structure | false | | --auth-tests | Include authentication tests | true | | --validation-tests | Include validation tests | true | | --error-tests | Include error handling tests | true | | --integration-tests | Include integration tests | true | | --performance-tests | Include performance tests | false | | --database-type | Database type (mongodb, postgresql, mysql) | mongodb | | --generate-fixtures | Generate test fixtures | true | | --generate-helpers | Generate test helper utilities | true | | --coverage-threshold | Minimum test coverage (0-100) | 80 | | --dry-run | Preview without writing files | false | | --verbose | Enable verbose logging | false |

Example Commands

# Generate comprehensive tests for MongoDB project
nuktatestify \
  --src src/app \
  --out tests \
  --modular \
  --auth-tests \
  --validation-tests \
  --error-tests \
  --integration-tests \
  --performance-tests \
  --database-type mongodb \
  --generate-fixtures \
  --generate-helpers \
  --coverage-threshold 85 \
  --verbose

# Generate tests for specific modules only
nuktatestify \
  --src src/app/modules/auth \
  --out tests/auth \
  --modular \
  --auth-tests \
  --verbose

# Dry run to preview generated tests
nuktatestify \
  --src src/app \
  --out tests \
  --modular \
  --dry-run \
  --verbose

Test Types

1. Basic Functionality Tests

  • HTTP method validation
  • Response status code checks
  • Response structure validation
  • Content-Type verification

2. Authentication Tests

  • JWT token validation
  • Authentication middleware testing
  • Unauthorized access prevention
  • Token refresh functionality

3. Validation Tests

  • Required field validation
  • Data type validation
  • Input sanitization
  • Custom validation rules

4. Error Handling Tests

  • 404 Not Found scenarios
  • 400 Bad Request handling
  • 500 Internal Server Error
  • Graceful error responses

5. Integration Tests

  • Complete CRUD operations
  • Database interactions
  • External service integration
  • End-to-end workflows

6. Performance Tests

  • Response time validation
  • Concurrent request handling
  • Memory usage monitoring
  • Load testing scenarios

Configuration

Jest Configuration

The tool generates a comprehensive Jest configuration:

// jest.config.js
module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  roots: ["<rootDir>/tests"],
  testMatch: ["**/__tests__/**/*.ts", "**/?(*.)+(spec|test).ts"],
  transform: {
    "^.+\\.ts$": "ts-jest",
  },
  collectCoverageFrom: [
    "src/**/*.ts",
    "!src/**/*.d.ts",
    "!src/server.ts",
    "!src/app.ts",
  ],
  coverageThreshold: {
    global: {
      branches: 80,
      functions: 80,
      lines: 80,
      statements: 80,
    },
  },
  setupFilesAfterEnv: ["<rootDir>/tests/setup.ts"],
  testTimeout: 10000,
  verbose: true,
  forceExit: true,
  clearMocks: true,
  resetMocks: true,
  restoreMocks: true,
};

Test Setup

Generated test setup with MongoDB in-memory server:

// tests/setup.ts
import { MongoMemoryServer } from "mongodb-memory-server";
import mongoose from "mongoose";

let mongoServer: MongoMemoryServer;

beforeAll(async () => {
  mongoServer = await MongoMemoryServer.create();
  const mongoUri = mongoServer.getUri();
  await mongoose.connect(mongoUri);
});

afterAll(async () => {
  await mongoose.disconnect();
  await mongoServer.stop();
});

beforeEach(async () => {
  const collections = mongoose.connection.collections;
  for (const key in collections) {
    await collections[key].deleteMany({});
  }
});

Best Practices

1. Test Organization

tests/
├── setup.ts                 # Global test setup
├── helpers/
│   ├── testHelper.js        # Test utilities
│   └── mockData.js          # Mock data generators
├── fixtures/
│   └── testData.js          # Test fixtures
├── auth/
│   ├── auth.test.js         # Authentication tests
│   └── auth.integration.js  # Integration tests
├── user/
│   ├── user.test.js         # User module tests
│   └── user.performance.js  # Performance tests
└── __mocks__/               # Jest mocks

2. Test Structure

describe("Module Name", () => {
  // Setup and teardown
  beforeAll(async () => {
    // Setup test environment
  });

  afterAll(async () => {
    // Cleanup
  });

  beforeEach(async () => {
    // Reset state before each test
  });

  // Test groups
  describe("Authentication", () => {
    // Auth-related tests
  });

  describe("Validation", () => {
    // Validation tests
  });

  describe("Error Handling", () => {
    // Error scenarios
  });
});

3. Mock Data Management

// Use realistic test data
const mockUser = {
  email: "[email protected]",
  password: "password123",
  name: "Test User",
  role: "user",
};

// Generate unique data for each test
const uniqueEmail = `test${Date.now()}@example.com`;

4. Database Testing

// Use in-memory database for tests
beforeAll(async () => {
  mongoServer = await MongoMemoryServer.create();
  await mongoose.connect(mongoServer.getUri());
});

// Clean up after each test
afterEach(async () => {
  await cleanupDatabase();
});

Examples

Generated Test Example

const request = require('supertest');
const mongoose = require('mongoose');
const { MongoMemoryServer } = require('mongodb-memory-server');

describe('Auth Module', () => {
  let mongoServer: MongoMemoryServer;
  let app: any;

  beforeAll(async () => {
    mongoServer = await MongoMemoryServer.create();
    const mongoUri = mongoServer.getUri();
    await mongoose.connect(mongoUri);
    app = require('../../src/app');
  });

  afterAll(async () => {
    await mongoose.disconnect();
    await mongoServer.stop();
  });

  beforeEach(async () => {
    const collections = mongoose.connection.collections;
    for (const key in collections) {
      await collections[key].deleteMany({});
    }
  });

  describe('POST /auth/login - Authentication', () => {
    let authToken: string;

    beforeAll(async () => {
      const loginResponse = await request(app)
        .post('/auth/login')
        .send({
          email: process.env.TEST_USER_EMAIL || '[email protected]',
          password: process.env.TEST_USER_PASSWORD || 'password123'
        });

      authToken = loginResponse.body.data.accessToken;
    });

    it('should require authentication', async () => {
      const response = await request(app)
        .post('/auth/login')
        .set('Content-Type', 'application/json');

      expect(response.status).toBe(401);
      expect(response.body).toHaveProperty('message');
    });

    it('should work with valid authentication', async () => {
      const response = await request(app)
        .post('/auth/login')
        .set('Authorization', `Bearer ${authToken}`)
        .set('Content-Type', 'application/json')
        .send({
          email: '[email protected]',
          password: 'password123'
        });

      expect(response.status).toBeOneOf([200, 201]);
      expect(response.body).toBeDefined();
    });
  });

  describe('POST /auth/login - Validation', () => {
    it('should validate required fields', async () => {
      const response = await request(app)
        .post('/auth/login')
        .set('Content-Type', 'application/json')
        .send({});

      expect(response.status).toBe(400);
      expect(response.body).toHaveProperty('message');
    });

    it('should validate field types', async () => {
      const invalidData = {
        email: 'invalid-email',
        password: 123
      };

      const response = await request(app)
        .post('/auth/login')
        .set('Content-Type', 'application/json')
        .send(invalidData);

      expect(response.status).toBe(400);
      expect(response.body).toHaveProperty('message');
    });
  });
});

FAQ

Q: Does it work with TypeScript projects?

  • Yes! It fully supports TypeScript with proper type definitions and ts-jest configuration.

Q: Can I customize the generated tests?

  • Absolutely! The generated tests are fully customizable. You can modify templates, add custom test cases, and extend functionality.

Q: Does it support other databases?

  • Currently optimized for MongoDB, but supports PostgreSQL and MySQL with basic configurations.

Q: How do I handle environment variables in tests?

  • The tool generates test setup that handles environment variables and provides fallbacks for testing.

Q: Can I run specific test types?

  • Yes! Use Jest's test patterns: npm run test:auth, npm run test:integration, etc.

Q: How do I add custom test utilities?

  • The tool generates a helpers/ directory where you can add custom test utilities and mock data.

Contributing

  1. Fork this repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Setup

git clone https://github.com/nuktadev/nuktatestify.git
cd nuktatestify
npm install
npm run build
npm link

License

This project is licensed under the MIT License - see the LICENSE file for details.


Support


Made with ❤️ by the Nukta Nur