Skip to main content
Version: 2.0.0

Sample app with Bun.js and MongoDb

This is a sample app to test Keploy integration capabilities using Bun.js and MongoDb.

Pre-requsite

We first need to install bun.js.

# Bun.js is supported on macOS, Linux, and WSL
curl -fsSL https://bun.sh/install | bash

Setup app

Now that we have bun installed, we will setup our application

git clone https://github.com/keploy/samples-typescript && cd samples-typescript/bun-mongo

# Install the dependencies
bun install

Using Keploy :

There are two ways to use Keploy:-

  1. Natively on Linux/WSL
  2. Using Docker

Natively on Ubuntu/WSL

Keploy can be installed on Linux directly and on Windows with the help of WSL. Based on your system architecture, install the keploy latest binary release from here:-

Linux

  1. AMD Architecture
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
2. ARM Architecture
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy

Windows Subsystem for Linux (WSL)

On Windows, WSL is required to run Keploy Binary. You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 to use the commands below.

wsl --install

Once installed download and Install "Keploy Binary" :

curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy

Let's start the MongoDB Instance

docker-compose up -d

Since we have setup our sample-app natively, we need to update the mongoDB host on line 41, in supabun.ts, from mongodb://mongoDb-bun:27017/keploy to mongodb://loacalhost:27017/keploy.

Capture the testcases

sudo -E env PATH=$PATH keploy record -c 'bun run supabun.ts'

Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.

  1. Generate the testcases
curl --request POST localhost:420/save

we will get the output:

{"succes":true}
  1. Fetch the data
curl --request GET localhost:420/fetch

this will provide us with the output:-

{"succes":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}}

We will get the following output in our terminal

Testcase


Running sample app using docker

Keploy can be used on Linux & Windows through Docker, and on MacOS by the help of Colima.

Create Keploy Alias

We need create an alias for Keploy:

alias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v "$(pwd)":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/keploy/keploy'

Let's start the MongoDB Instance

docker-compose up -d

Capture the testcases

  1. We first need to build dockerimage of our application:-
docker build -t bun-app:1.0 .
  1. Now we will run the keploy in record mode:-
keploy record -c "docker run -p 420:420 --name bunMongoApp --network keploy-network bun-app:1.0"

Let's generate the testcases.

Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.

curl --request POST localhost:420/save

we will get the output:

{"succes":true}
  1. Fetch the data
curl --request GET localhost:420/fetch

this will provide us with the output:-

{"succes":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}}

We will get the following output in our terminal

Testcase

Running the testcases

This is WIP and depended upon the issue by oven/bun & elysia:- https://github.com/elysiajs/elysia/issues/231