Skip to main content
Version: 2.0.0

Keploy Integration with Jest

Pre-requisites

  1. Node.js
  2. nyc
  3. Keploy SDK
  4. Jest

Installation

Get Keploy jest sdk

Install the latest release of the Keploy Jest SDK

npm i @keploy/sdk nyc jest

Update package file

Update the package.json file that runs the application:

  "scripts": {
//other 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"
//other scripts
}

Usage

For the code coverage for the keploy API tests using the jest integration, you need to add the following test to your Jest test file. It can be called as keploy.test.js.

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
);

Now let's run jest tests along keploy using command: -

npm test

To get Combined coverage with keploy test coverage: -

npm run coverage

Hope this helps you out, if you still have any questions, reach out to us .

Contact Us

If you have any questions or need help, please feel free to reach out to us at hello@keploy.io or reach out us on Slack or open a discussion on GitHub Discussion