Getting Started with itdoc
itdoc is a lightweight library that helps automatically generate test code based on Jest, Mocha.js, as well as OAS documentation, Markdown, and Redocli-HTML documents using its own interface. It's ideal for developers who want to naturally create API documentation while practicing Test-Driven Development (TDD).
Installation
- You need Node.js 20 installed.
- pnpm
- yarn
- npm
pnpm install itdoc --save-dev
yarn add -D itdoc
npm install itdoc --save-dev
Test Writing Example
- JavaScript
- TypeScript
describeAPI(
HttpMethod.POST,
"/signup",
{
summary: "User Registration API",
tag: "Auth",
description: "Registers a new user with username and password.",
},
targetApp,
(apiDoc) => {
itDoc("Successful registration", () => {
return apiDoc
.test()
.req()
.body({
username: field("username", "penekhun"),
password: field("password", "P@ssw0rd123!@#"),
})
.res()
.status(HttpStatus.CREATED)
})
},
)
import { describeAPI, itdoc, field, HttpMethod, HttpStatus } from 'itdoc';
describeAPI(
HttpMethod.POST,
"/signup",
{
summary: "User Registration API",
tag: "Auth",
description: "Registers a new user with username and password.",
},
targetApp as Express, // Assuming targetApp is of type Express
(apiDoc) => {
itdoc("Successful registration", () => {
return apiDoc
.test()
.req()
.body({
username: field("Username", "penekhun"),
password: field("Password", "P@ssw0rd123!@#"),
})
.res()
.status(HttpStatus.CREATED)
})
},
);
Overview
itdoc is a library designed for test automation and API documentation generation. Key features include:
- Domain-Specific Language (DSL): Provides an interface for declaratively describing test cases and API behavior.
- Builder Pattern: Offers various builder classes like
RootBuilder
,RequestBuilder
, andResponseBuilder
for test case composition. - Multiple Test Framework Support: Includes adapters (
MochaAdapter
,JestAdapter
) to accommodate different test frameworks such as Mocha and Jest. - HTTP-Related Constants: Provides enumerations (
HttpMethod
,HttpStatus
) for managing HTTP methods and status codes.
For more detailed examples, check out the examples in the GitHub repository.