Skip to content

Commit 404d1d1

Browse files
authored
feat: add bun sample app
feat: updated bun-mongoose readme && added new sample-app
2 parents 24d4723 + 5dd6d49 commit 404d1d1

48 files changed

Lines changed: 529 additions & 6126 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

8 KB
Binary file not shown.

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
<h1 align="center"> Keploy Typescript SDK Samples </h1>
1+
<h1 align="center"> Keploy TypeScript/JavaScript Samples </h1>
22
<p align="center">
33

44
<a href="CODE_OF_CONDUCT.md" alt="Contributions welcome">
5-
<img src="https://img.shields.io/badge/Contributions-Welcome-brightgreen?logo=github" /></a>
5+
<img src="https://img.shields.io/badge/Contributions-Welcome-brightgreen?logo=github" />
6+
</a>
7+
</p>
68

7-
<a href="https://join.slack.com/t/keploy/shared_invite/zt-12rfbvc01-o54cOG0X1G6eVJTuI_orSA" alt="Slack">
8-
<img src=".github/slack.svg" /></a>
9-
10-
<a href="https://opensource.org/licenses/Apache-2.0" alt="License">
11-
<img src=".github/License-Apache_2.0-blue.svg" /></a>
129

13-
This repo contains the sample for [Keploy's](https://keploy.io) Go SDK. Please feel free to contribute if you'd like submit a sample for another use-case or library.
10+
This repo contains the sample for [Keploy's](https://keploy.io) JS Application. Please feel free to contribute if you'd like submit a sample for another use-case or library.
1411

15-
**Note** :- Issue Creation is disabled on this Repository, please visit [here](https://github.com/keploy/keploy/issues/new/choose) to submit Issue.
12+
>**Note** :- Issue Creation is disabled on this Repository, please visit [here](https://github.com/keploy/keploy/issues/new/choose) to submit Issue.
1613
1714

18-
## Sample Apps with Keploy Typescript SDK
15+
## Sample Apps with Keploy
1916

20-
1. [Node-Fetch](https://github.com/keploy/samples-typescript/tree/main/node-fetch)
17+
1. [Bun-Mongo](https://github.com/keploy/samples-typescript/tree/main/supabun)
2118

19+
2. [Node-Mongo](https://github.com/keploy/samples-typescript/tree/main/node-mongo)
2220
## Community Support ❤️
2321

2422
We'd love to collaborate with you to make Keploy great. To get started:

bun-mongo/.DS_Store

6 KB
Binary file not shown.

bun-mongo/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM oven/bun:latest
2+
3+
# Create app directory
4+
RUN apt-get update && \
5+
apt-get install -y --no-install-recommends ca-certificates && \
6+
rm -rf /var/lib/apt/lists/*
7+
8+
WORKDIR /usr/src/app
9+
10+
# Install app dependencies
11+
# A wildcard is used to ensure both package.json AND package-lock.json are copied
12+
# where available (npm@5+)
13+
RUN curl -fsSL https://bun.sh/install | bash
14+
15+
COPY package*.json ./
16+
17+
RUN bun install
18+
# If you are building your code for production
19+
# RUN npm ci --omit=dev
20+
21+
# Bundle app source
22+
COPY . .
23+
24+
EXPOSE 420
25+
CMD [ "bun", "start" ]

bun-mongo/README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
![Testcase](./img/testcase-bun.png)
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+
![Testcase](./img/testcase-bun.png)
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

bun-mongo/controller/fetch.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Animal } from './../database/database.type';
2+
3+
export default class MongoIntegration {
4+
async Save() {
5+
const cow = new Animal({
6+
name: 'Cow',
7+
sound: 'Moo',
8+
});
9+
await cow.save();
10+
return {"succes":true};
11+
}
12+
async Fetch() {
13+
const animal = await Animal.findOne({"name":"Cow"});
14+
return {"succes":animal};
15+
}
16+
async Put() {
17+
const query = { name: 'name' };
18+
const update = {
19+
$set: {
20+
name: "cows",
21+
},
22+
};
23+
let animal = await Animal.updateMany(query,update);
24+
return {"succes":animal};
25+
}
26+
async Delete() {
27+
const animal = await Animal.deleteMany({"name":'Cow'});
28+
return {"succes":animal};
29+
}
30+
}

bun-mongo/controller/hello.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default class HelloController {
2+
sayHello() {
3+
return "Well this is working";
4+
}
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as mongoose from 'mongoose';
2+
3+
const animalSchema = new mongoose.Schema(
4+
{
5+
name: {type: String, required: true},
6+
sound: {type: String, required: true},
7+
},
8+
{
9+
methods: {
10+
speak() {
11+
console.log(`${this.sound}!`);
12+
},
13+
},
14+
}
15+
);
16+
17+
export type Animal = mongoose.InferSchemaType<typeof animalSchema>;
18+
export const Animal = mongoose.model('Animal', animalSchema);

bun-mongo/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.9'
2+
services:
3+
mongo:
4+
image: mongo
5+
container_name: mongoDb-bun
6+
ports:
7+
- 27017:27017
8+
networks:
9+
- keploy-network
10+
11+
networks:
12+
keploy-network:
13+
external: true

bun-mongo/img/testcase-bun.png

91.9 KB
Loading

0 commit comments

Comments
 (0)