@meistrari/bolt
v0.0.2
Published
Elegant load testing, via Bun
Downloads
14
Readme
installation
bun add @meistrari/bolt
usage
bolt allows you to easily set up and run performance tests.
import { createBoltRunner, defineImplementation } from '@meistrari/bolt'
// define your test implementation
defineImplementation(async ({ url }) => {
const res = await fetch(url)
if (!res.ok)
throw new Error(`http error! status: ${res.status}`)
return res.json()
})
// create and run your tests
const runner = createBoltRunner('your-test-file.ts')
await runner([
{
name: 'get posts',
iterations: 100,
concurrency: 10,
data: { url: 'https://api.example.com/posts' },
},
])
examples
http api test
test implementation (http-api-test.ts
):
import { defineImplementation } from '@meistrari/bolt'
defineImplementation(async ({ url }) => {
const res = await fetch(url)
if (!res.ok)
throw new Error(`http error! status: ${res.status}`)
return res.json()
})
running tests (http-api.ts
):
import { createBoltRunner } from '@meistrari/bolt'
const runner = createBoltRunner('http-api-test.ts')
await runner([
{
name: 'entity list',
iterations: 2,
concurrency: 2,
data: { url: 'https://jsonplaceholder.typicode.com/posts' },
},
{
name: 'single entity',
iterations: 10,
concurrency: 10,
data: { url: 'https://jsonplaceholder.typicode.com/posts/1' },
},
])
configuration
bolt tests are configured using scenario objects:
{
name: string // name of the test scenario
iterations: number // number of times to run the test
concurrency: number // number of concurrent requests
data: any // data to pass to the test implementation
}
for more advanced configuration options, please refer to the documentation.