|
| 1 | +# Sample app with Bun.js and MongoDb |
| 2 | + |
| 3 | +This is a sample app to test Keploy integration capabilities using [Bun.js](https://bun.sh) and MongoDb. |
| 4 | + |
| 5 | +## Pre-requsite |
| 6 | +We first need to install bun.js. |
| 7 | +```zsh |
| 8 | +# Bun.js is supported on macOS, Linux, and WSL |
| 9 | +curl -fsSL https://bun.sh/install | bash |
| 10 | +``` |
| 11 | +## Setup app |
| 12 | + |
| 13 | +Now that we have bun installed, we will setup our application |
| 14 | +```zsh |
| 15 | +git clone https://github.com/keploy/samples-typescript && cd samples-typescript/bun-mongo |
| 16 | + |
| 17 | +# Install the dependencies |
| 18 | +bun install |
| 19 | +``` |
| 20 | + |
| 21 | +# Using Keploy : |
| 22 | + |
| 23 | +There are two ways to use Keploy:- |
| 24 | + |
| 25 | +1. [Natively on Linux/WSL](#natively-on-ubuntuwsl) |
| 26 | +2. [Using Docker](#running-sample-app-using-docker) |
| 27 | + |
| 28 | +## Natively on Ubuntu/WSL |
| 29 | + |
| 30 | +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:- |
| 31 | + |
| 32 | +#### Linux |
| 33 | +1. AMD Architecture |
| 34 | +```zsh |
| 35 | +curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp |
| 36 | + |
| 37 | +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy |
| 38 | +``` |
| 39 | + |
| 40 | +<details> |
| 41 | +<Summary> 2. ARM Architecture </Summary> |
| 42 | + |
| 43 | + |
| 44 | +```zsh |
| 45 | +curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz -C /tmp |
| 46 | + |
| 47 | +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy |
| 48 | +``` |
| 49 | +</details> |
| 50 | + |
| 51 | +#### Windows Subsystem for Linux (WSL) |
| 52 | + |
| 53 | +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. |
| 54 | + |
| 55 | +```bash |
| 56 | +wsl --install |
| 57 | +``` |
| 58 | +Once installed download and Install "Keploy Binary" : |
| 59 | + |
| 60 | +```bash |
| 61 | +curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp |
| 62 | + |
| 63 | +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy |
| 64 | +``` |
| 65 | + |
| 66 | +### Let's start the MongoDB Instance |
| 67 | +```zsh |
| 68 | +docker-compose up -d |
| 69 | +``` |
| 70 | + |
| 71 | +> **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`.** |
| 72 | +
|
| 73 | +### Capture the testcases |
| 74 | + |
| 75 | +```bash |
| 76 | +sudo -E env PATH=$PATH Keploy record -c 'bun run supabun.ts' |
| 77 | +``` |
| 78 | + |
| 79 | +Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. |
| 80 | + |
| 81 | +1. Generate the testcases |
| 82 | +```bash |
| 83 | +curl --request POST localhost:420/save |
| 84 | +``` |
| 85 | + |
| 86 | +we will get the output: |
| 87 | + |
| 88 | +``` |
| 89 | +{"succes":true} |
| 90 | +``` |
| 91 | +2. Fetch the data |
| 92 | +```bash |
| 93 | +curl --request GET localhost:420/fetch |
| 94 | +``` |
| 95 | + |
| 96 | +this will provide us with the output:- |
| 97 | +``` |
| 98 | +{"succes":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}} |
| 99 | +``` |
| 100 | +We will get the following output in our terminal |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +# Running sample app using docker |
| 107 | + |
| 108 | +Keploy can be used on Linux & Windows through Docker, and on MacOS by the help of [Colima](). |
| 109 | + |
| 110 | +## Create Keploy Alias |
| 111 | +We need create an alias for Keploy: |
| 112 | +```bash |
| 113 | +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' |
| 114 | +``` |
| 115 | + |
| 116 | +## Let's start the MongoDB Instance |
| 117 | +```bash |
| 118 | +docker-compose up -d |
| 119 | +``` |
| 120 | + |
| 121 | +## Capture the testcases |
| 122 | +1. We first need to build dockerimage of our application:- |
| 123 | +```bash |
| 124 | +docker build -t bun-app:1.0 . |
| 125 | +``` |
| 126 | + |
| 127 | +2. Now we will run the keploy in record mode:- |
| 128 | +```bash |
| 129 | +keploy record -c "docker run -p 420:420 --name bunMongoApp --network keploy-network bun-app:1.0" |
| 130 | +``` |
| 131 | + |
| 132 | +### Let's generate the testcases. |
| 133 | +Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. |
| 134 | +```bash |
| 135 | +curl --request POST localhost:420/save |
| 136 | +``` |
| 137 | + |
| 138 | +we will get the output: |
| 139 | + |
| 140 | +``` |
| 141 | +{"succes":true} |
| 142 | +``` |
| 143 | +2. Fetch the data |
| 144 | +```bash |
| 145 | +curl --request GET localhost:420/fetch |
| 146 | +``` |
| 147 | + |
| 148 | +this will provide us with the output:- |
| 149 | +``` |
| 150 | +{"succes":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}} |
| 151 | +``` |
| 152 | +We will get the following output in our terminal |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +# Running the testcases |
| 157 | + |
| 158 | +This is WIP and depended upon the issue by oven/bun & elysia:- https://github.com/elysiajs/elysia/issues/231 |
0 commit comments