Universal TypeScript-first HTTP testing library for Node applications.
Parasito attaches one request API to framework apps, Node servers, and fetch-style handlers. Use it to test Express, Fastify, H3, Hono, Koa, plain Node handlers, already-listening servers, or remote URLs with the same fluent assertions.
pnpm add -D parasitoimport request from 'parasito';
import express from 'express';
const app = express();
app.get('/account', (_request, response) => {
response.json({ ok: true });
});
await request(app).get('/account').expect(200).expect({ ok: true });- Express and connect-style handlers
- Fastify instances
- H3 apps
- Hono apps
- Koa apps
- Plain Node request handlers
- Node
http.Serverinstances - Fetch-style functions and objects with a
fetch(request)method - Remote HTTP URLs
await request(app)
.post('/account')
.set('authorization', 'Bearer token')
.query({ expand: 'team' })
.send({ name: 'Ada' })
.expect(201)
.expect('content-type', /json/)
.expect((response) => {
// Use your test runner's assertions here.
});Requests are promise-like, so you can await them directly. The resolved response includes:
statusandstatusCodeokheadersas WebHeadersheaderas a plain objecttextbodyraw
import { H3 } from 'h3';
import request from 'parasito';
const app = new H3();
app.get('/account', (event) => {
return {
authorization: event.req.headers.get('authorization'),
ok: true,
};
});
await request(app).get('/account').auth('token').expect(200).expect({
authorization: 'Bearer token',
ok: true,
});import { Hono } from 'hono';
import request from 'parasito';
const app = new Hono();
app.get('/account', (context) => {
return context.json({ ok: true });
});
await request(app).get('/account').expect(200).expect({ ok: true });import fastify from 'fastify';
import request from 'parasito';
const app = fastify();
app.post('/account', async (request) => {
return { body: request.body };
});
try {
await request(app)
.post('/account')
.send({ name: 'Ada' })
.expect(200)
.expect({ body: { name: 'Ada' } });
} finally {
await app.close();
}import Koa from 'koa';
import request from 'parasito';
const app = new Koa();
app.use((context) => {
context.body = { ok: true };
});
await request(app).get('/account').expect(200).expect({ ok: true });import request from 'parasito';
await request((_incoming, outgoing) => {
outgoing.setHeader('content-type', 'application/json');
outgoing.end(JSON.stringify({ ok: true }));
})
.get('/health')
.expect(200)
.expect({ ok: true });Use a string URL when the service is already running outside the current test process.
import request from 'parasito';
await request('https://api.example.com')
.get('/health')
.expect(200)
.expect({ ok: true });URL objects are supported too.
import request from 'parasito';
const api = new URL('https://api.example.com');
await request(api)
.post('/account')
.auth('token')
.send({ name: 'Ada' })
.expect(201);pnpm install
pnpm lint
pnpm typecheck
pnpm test
pnpm build