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 🙏

© 2025 – Pkg Stats / Ryan Hefner

auto-generator-test

v1.1.5

Published

A CLI tool for auto-generating NestJS test files

Readme

Auto Generator Test

Auto Generator Test is a project designed to help automate the generation of unit and integration tests for NestJS services, modules, and more. The tool can analyze existing code and create boilerplate test files based on the structure and methods of your services and modules. This can save developers time and improve test coverage across the codebase.

Features

  • Automatic Test Generation: Generates boilerplate unit tests for NestJS services and modules.
  • Support for E2E Tests: Supports creating end-to-end tests for NestJS applications.
  • File Reader Utility: Includes helper functions to read files and check for file existence.
  • Customizable Test Templates: Allows for easy modifications to test templates and configurations.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js (version >= 14.x)
  • NestJS (latest version recommended)
  • TypeScript (configured in your project)
  • Jest (for testing)
  • npm or yarn (for managing dependencies)

Utility Functions

The following utility functions are provided in utils/file-reader.ts for interacting with files in your project:

Read File Content

  1. Reads the content of a text file.
import { FileReader } from 'auto-generator-test/utils/file-reader';

const content = FileReader.readFileContent('path/to/your/file.ts');
console.log(content);
  1. Check If File Exists Checks whether a file or directory exists.
import { FileReader } from 'auto-generator-test/utils/file-reader';

const exists = FileReader.checkIfFileExists('path/to/your/file.ts');
console.log(exists);  // true or false
  1. Get Files in Directory Returns a list of files in a given directory.
import { FileReader } from 'auto-generator-test/utils/file-reader';

const files = FileReader.getFilesInDirectory('path/to/your/directory');
console.log(files);  // Array of file names

DTOs

ScannerDTO

The ScannerDTO is used to represent data for scanning files.

Properties:

  • filePath: The path of the file to be scanned.
  • scanType: The type of scan (e.g., syntax check, file existence, etc.).
  • options: Optional configurations for the scan.

Example Usage:

import { ScannerDTO } from 'auto-generator-test/dto/scanner.dto';

const scannerRequest = new ScannerDTO('path/to/file.ts', 'syntax-check');
console.log(scannerRequest.filePath);  // path/to/file.ts
console.log(scannerRequest.scanType);  // syntax-check

Installation

To install the project, follow these steps:

  1. Clone the repository:
git clone https://github.com/ZaraSdt7/Auto-generator-test
  1. Install,dependencies: Navigate to the project directory and run the following command to install the required dependencies.

Using npm:

npm install

Using yarn:

yarn install
  1. Install the package into your NestJS project: To use the Auto Generator Test in your NestJS project, install it via npm or yarn.

Using npm:

npm install auto-generator-test

Usage

Run the CLI tool with the following command:

npx auto-generator-test generate  --controllers  or --services

Options:

🔋 --controllers: Generate tests for controllers.

🔋 --services: Generate tests for services.

Example Project

This package includes a simple example to demonstrate how it works.

Sample Controller

import { Controller, Get, Post, Body } from '@nestjs/common';
import { SampleService } from './sample.service';

@Controller('sample')
export class SampleController {
  constructor(private readonly sampleService: SampleService) {}

  @Get('/')
  getData() {
    return this.sampleService.getData();
  }

  @Post()
  createData(@Body() data: any) {
    return { ...data, message: "Sample data successfully created" };
  }
}

Sample Service

import { Injectable } from '@nestjs/common';

@Injectable()
export class SampleService {
  private data: any[] = [];

  getData() {
    return this.data;
  }

  createData(data: any) {
    this.data.push(data);
    return data;
  }
}
  1. Import the module and configure: After installation, import the AutoTestGeneratorModule into your NestJS application.
import { AutoTestGeneratorModule } from 'auto-test-generator';

@Module({
  imports: [AutoTestGeneratorModule],
})
export class AppModule {}
  1. Generate Tests: To automatically generate tests for your services and modules, you can call the relevant service from AutoTestGeneratorService in your project.

For example:

import { AutoTestGeneratorService } from 'auto-test-generator';

@Injectable()
export class SampleService {
  constructor(private readonly autoTestGenerator: AutoTestGeneratorService) {}

  generateTest() {
    this.autoTestGenerator.generateTestForService('SampleService');
  }
}
  1. Run Tests: Once your tests are generated, you can run them using Jest.

Using npm:

npm run test

Using yarn:

yarn test
  1. Optional: Configure Jest Make sure you have Jest configured properly in your project for running unit tests. You can customize the Jest setup in your jest.config.js file, including adding paths and test environments if necessary.

Usage

  • Automatic Test Generation: This tool will automatically generate unit tests for your services and modules based on their structure.
  • Customization: You can customize the generated tests by modifying the templates or adjusting settings in the configuration file.
  • E2E Test Generation: This tool also supports generating boilerplate end-to-end tests.