nukta-test-gen
v1.1.1
Published
A CLI tool that auto-generates Jest test cases for Express.js APIs.
Maintainers
Readme
nukta-test-gen
🚀 Auto-generate Jest test cases for your Express.js APIs in seconds!
Table of Contents
Features
- 🔍 Scans your Express.js routes (
app.get,router.post, etc.) - 📝 Generates Jest test files for each route
- ✅ Status code and response shape checks
- 🧪 Supports
.test.jsor.spec.jsfile extensions - 🗂️ Outputs to a
tests/directory (customizable) - 🔒 Never executes code—parses only for security
- ⚡ Fast, developer-friendly, and extensible
Installation
Global (Recommended)
npm install -g nukta-test-genLocal (as a dev dependency)
npm install --save-dev nukta-test-genUsage
Navigate to your Express.js project root and run:
nukta-test-gen [options]Or, if installed locally:
npx nukta-test-gen [options]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 |
| --mock | Include mock data in tests | false |
| --dry-run | Show what would be generated, don’t write files | false |
| --verbose | Enable verbose logging | false |
How It Works
- Scans all
.jsand.tsfiles in your source directory (default:src/). - Finds Express route definitions (e.g.,
app.get('/api', ...),router.post(...)). - Generates Jest test files for each route in your output directory (default:
tests/). - Each test checks:
- Status codes (200, 201, 400, 404)
- Response shape (object/array)
- Optionally includes mock data
Example
nukta-test-gen --src api --out tests --ext spec.js --mock --verboseFAQ
Q: Does it scan all files?
- It scans all
.jsand.tsfiles in the directory you specify, but only generates tests for files with Express route definitions.
Q: Does it execute my code?
- No. It only parses files for route definitions—never executes or requires them.
Q: Can I use it with TypeScript projects?
- Yes! It supports both
.jsand.tsfiles.
Q: How do I run the generated tests?
- Use Jest:
npx jest
Contributing
- Fork this repo and clone it.
- Install dependencies:
npm install - Make your changes in
src/. - Build the project:
npm run build - Test your changes.
- Submit a pull request!
Publishing
- Make sure you are logged in to npm:
npm adduser - Build the project:
npm run build - Publish:
npm publish --access public
