Skip to content

Commit d0ab88b

Browse files
Pradhyuman-sharmare-Tickrajatsharma
authored
feat(ts-sdk): added support for test coverage (#29)
* fix(express.ts): header and body issue * fix(express.ts): header and body issue * fix(express.ts): header and body issue * fix(express.ts): header and body issue * feat:changes for check method * adding * check method update * check method update * wip * fix: call create inside middleware * fix: adds calls for test and denoise methods during capturing the response a subsequent denoise call is made to identify the noise fields and test method is fixed to test the captured api responses * refactor: removes unfinished changes * style: fixes sethttpheaders * fix(simulate): adds request headers in simulate api call * fix: adds time delay before calling test function * fix(register): adds the properties of express object into wrapped object * fix: fixes borales/action-yarn version to 2.1.0 * fix(middleware): adds finish event callback to record the asynchronous responses from the handlers makes a call to capture the testcases before sending the response to the client and after res.send call by the handler. * docs: adds documentation for integration with ts/js server * feat(ts-sdk): added support for test coverage * docs(ts-sdk): adding example for testing framework * docs(ts-sdk): adding example for testing framework * docs(ts-sdk): adding example for testing framework * feat(ts-sdk): added support for test coverage * fix: merge conflicts * fix: merge conflicts * commiting * docs(ts-sdk): updating readme Signed-off-by: Pradhyuman-sharma <sharmapuru0642@gmail.com> Signed-off-by: Pradhyuman-sharma <sharmapuru0642@gmail.com> Co-authored-by: re-Tick <jain.ritik.1001@gmail.com> Co-authored-by: Rajat Sharma <lunasunkaiser@gmail.com>
1 parent 05717bf commit d0ab88b

File tree

6 files changed

+13433
-3084
lines changed

6 files changed

+13433
-3084
lines changed

README.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
[![License](.github/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
44

55
# Keploy Typescript-SDK
6-
[Keploy](https://keploy.io) is a no-code testing platform that generates tests from API calls. This is the Typescript client SDK for recording and replaying the API Calls. There are 2 modes:
6+
[Keploy](https://keploy.io) is a no-code testing platform that generates tests from API calls. This is the Typescript client SDK for recording and replaying the API Calls. There are 2 modes:
77
1. **Record mode**
88
1. Record requests, response and sends to Keploy server.
99
2. After keploy server removes duplicates, it then runs the request on the API again to identify noisy fields.
10-
3. Sends the noisy fields to the keploy server to be saved along with the testcase.
10+
3. Sends the noisy fields to the keploy server to be saved along with the testcase.
1111
2. **Test mode**
12-
1. Fetches testcases for the app from keploy server.
13-
2. Calls the API with same request payload in testcase.
14-
3. Validates the respones and uploads results to the keploy server.
12+
1. Fetches testcases for the app from keploy server.
13+
2. Calls the API with same request payload in testcase.
14+
3. Validates the respones and uploads results to the keploy server.
1515

1616
## Contents
1717
1. [Installation](#installation)
@@ -30,7 +30,6 @@ npm i https://github.com/keploy/typescript-sdk
3030
require("typescript-sdk/dist/integrations/express/register");
3131
```
3232
## Configure
33-
Keploy can be configured by environment varibales. Below is an example .env file
3433
```
3534
export KEPLOY_MODE="test"
3635
export KEPLOY_APP_NAME="my-app"
@@ -46,10 +45,10 @@ export KEPLOY_SERVER_URL="http://localhost:8081/api" # self hosted keploy runnin
4645
### KEPLOY_MODE
4746
There are 3 modes:
4847
- **Record**: Sets to record mode.
49-
- **Test**: Sets to test mode.
48+
- **Test**: Sets to test mode.
5049
- **Off**: Turns off all the functionality provided by the API
5150

52-
**Note:** `KEPLOY_MODE` value is case sensitive.
51+
**Note:** `KEPLOY_MODE` value is case sensitive.
5352

5453
## Supported Frameworks
5554
### 1. Express
@@ -87,6 +86,29 @@ npm i -g yarn
8786
yarn install
8887
```
8988

89+
### Integration with Mocha testing framework
90+
You just need to do some imports and call a built-in assert function in your code in your unit test file and that's it!!🔥🔥🔥
91+
```js
92+
const {runServer} = require('../server') //your server wrapper
93+
const {keploy} = require('typescript-sdk/dist/integrations/express/register')
94+
const {describe,test,before,after}= require('mocha')
95+
describe("test function", ()=>{
96+
before( (done)=>{
97+
keploy.setTestMode();
98+
runServer()
99+
done()
100+
})
101+
test("should be running", async ()=> {
102+
await keploy.assertTests();
103+
});
104+
after(()=>{
105+
process.exit(1); //exits the node server
106+
})
107+
})
108+
```
109+
Note:- To see code coverage please use nyc mocha and see how many lines are covered!!
110+
111+
90112
- Furthermore, to commit your changes use `yarn commit` instead of `git commit` for better commit experience.
91113

92114
- For VSCode setup, make sure these extensions are installed:

integrations/express/register.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import Keploy from "../../src/keploy";
55
import bodyParser from "body-parser";
66
import cors from "cors";
77
import mixin from "merge-descriptors";
8+
const keploy = new Keploy();
89

910
// @ts-ignore
1011
Hook(["express"], function (exports) {
1112
const expressApp = exports;
12-
1313
function keployWrappedExpress() {
1414
const keployApp = expressApp();
1515

16-
const keploy = new Keploy();
1716
keployApp.use(bodyParser.json());
1817
keployApp.use(cors());
1918
keployApp.use(expressMiddleware(keploy));
@@ -28,3 +27,4 @@ Hook(["express"], function (exports) {
2827
exports = keployWrappedExpress;
2928
return exports;
3029
});
30+
export { keploy };

0 commit comments

Comments
 (0)