diff --git a/versioned_docs/version-2.0.0/quickstart/express-mongodb.md b/versioned_docs/version-2.0.0/quickstart/express-mongodb.md new file mode 100644 index 000000000..bdcd5814b --- /dev/null +++ b/versioned_docs/version-2.0.0/quickstart/express-mongodb.md @@ -0,0 +1,145 @@ +--- +id: expressjs-mongodb +title: Expressjs Sample Application +sidebar_label: Express + MongoDb +description: The following sample app showcases how to use NodeJS framework and the Keploy Platform. +tags: + - javascript + - quickstart + - samples + - examples + - tutorial +keyword: + - NodeJS Framework + - MongoDB + - NodeJS + - API Test generator + - Auto Testcase generation +--- + +## Introduction + +A simple sample CRUD application and see how seamlessly Keploy integrates with [Express](https://expressjs.com/) and [MongoDB](https://www.mongodb.com/). Buckle up, it's gonna be a fun ride! 🎢 + +import InstallationGuide from '../concepts/installation.md' + + + +## Get Started! 🎬 + +Clone the repository and move to express-mongoose folder + +```bash +git clone https://github.com/keploy/samples-typescript && cd samples-typescript/express-mongo-priyank + +# Install the dependencies +npm install +``` + +## Installation 📥 + +Let's get started by setting up the Keploy with this command: +``` +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 +``` + +### Lights, Camera, Record! 🎥 + +#### Capturing Testcases + + +``` +keploy record -c "npm start" +``` + +#### Let's generate the testcases. + +Make API Calls using [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. + +🎉 Woohoo! With a simple API call, you've crafted a test case with a mock! Dive into the Keploy directory and feast your eyes on the newly minted `test-1.yml` and `mocks.yml` + +_Time to perform more API magic!_ +Follow the breadcrumbs... or Make more API Calls + +```bash +curl --request GET \ +--url http://localhost:3001/api/products +``` + +Or simply wander over to your browser and visit ` http://localhost:3001/api/products`. + +Did you spot the new test and mock scrolls in your project library? Awesome! 👏 + +### Run the following command to execute Keploy tests for the application +``` +keploy test -c "npm run" --delay 10 +``` + +### Keploy Js SDK +``` +npm i @keploy/sdk +``` +### Update json file +``` +"scripts": { + "test": "jest --coverage --collectCoverageFrom='src/**/*.{js,jsx}'", + "coverage": "nyc npm test && npm run coverage:merge && npm run coverage:report", + "coverage:merge": "mkdir -p ./coverage && nyc merge ./coverage .nyc_output/out.json", + "coverage:report": "nyc report --reporter=lcov --reporter=text" + }, +``` +### usages +create a file under `test` folder & rename the file to `Keploy.test.js` & paste the code +``` +const { expect } = require("@jest/globals"); +const keploy = require("@keploy/sdk"); +const timeOut = 300000; + +describe( + "Keploy Server Tests", + () => { + test( + "TestKeploy", + (done) => { + const cmd = "npm start"; + const options = {}; + keploy.Test(cmd, options, (err, res) => { + if (err) { + done(err); + } else { + expect(res).toBeTruthy(); // Assert the test result + done(); + } + }); + }, + timeOut + ); + }, + timeOut +); + +``` + +### Run test + +``` +npm run test +``` + +### Check Coverage +``` +npm run coverage +``` + + + + +### Wrapping it up 🎉 + +Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible.😊🚀 + + + +Happy coding! ✨👩‍💻👨‍💻✨ diff --git a/versioned_sidebars/version-2.0.0-sidebars.json b/versioned_sidebars/version-2.0.0-sidebars.json index aa3809149..9c65da338 100644 --- a/versioned_sidebars/version-2.0.0-sidebars.json +++ b/versioned_sidebars/version-2.0.0-sidebars.json @@ -34,7 +34,12 @@ "label": "Test Coverage Integration", "collapsible": true, "collapsed": true, - "items": ["server/sdk-installation/go", "server/sdk-installation/java", "server/sdk-installation/typescript", "server/sdk-installation/python"] + "items": [ + "server/sdk-installation/go", + "server/sdk-installation/java", + "server/sdk-installation/typescript", + "server/sdk-installation/python" + ] }, { "type": "category", @@ -87,7 +92,8 @@ "quickstart/samples-bunjs", "quickstart/samples-nextjs", "quickstart/samples-nodejs", - "quickstart/samples-node-jwt" + "quickstart/samples-node-jwt", + "quickstart/express-mongodb" ] }, { @@ -95,7 +101,9 @@ "label": "Rust", "collapsible": true, "collapsed": true, - "items": ["quickstart/samples-rust"] + "items": [ + "quickstart/samples-rust" + ] }, { "type": "category", @@ -113,17 +121,24 @@ "label": "Keploy-Cloud ☁️", "collapsible": true, "collapsed": true, - "items": ["keploy-cloud/cloud-installation", "keploy-cloud/application-settings", "keploy-cloud/time-freezing"] + "items": [ + "keploy-cloud/cloud-installation", + "keploy-cloud/application-settings", + "keploy-cloud/time-freezing" + ] }, { "type": "category", "label": "Resources", "collapsible": true, "collapsed": true, - "items": ["dependencies/mongo","keploy-explained/faq","concepts/general-glossary"] + "items": [ + "dependencies/mongo", + "keploy-explained/faq", + "concepts/general-glossary" + ] } ], - "sidebarContributionGuide": [ { "type": "category", @@ -136,4 +151,4 @@ ] } ] -} +} \ No newline at end of file