npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jest-rest-preset

v0.0.4

Published

Run API tests using Jest, Axios and AJV

Readme

Jest-Rest 🎪

Jest Rest is a Rest API testing framework using Jest, Axios and Ajv.

Schema definition matching is done using AJV. (one of the fastest schema matcher).

Highlights

  • Debug 🕵️ - Pause the tests to see what's happening in real-time.
  • Logger 📝- log request and response to the terminal for more debugging capability.
  • Contract Tests 🤝 - Perform contract testing / schema validation testing.
  • Parallel tests 🧪🧪 - Run parallel tests to speed-up testing.

Installation

npm install -D jest jest-rest-preset

Requirements

  • Node.js >= 10.15.0
  • Jest >=25

Usage

Update your Jest configuration, either:

  • with package.json:
"jest": {
  "preset": "jest-rest-preset"
}
  • with jest.config.js:
module.exports = {
    preset: "jest-rest-preset",
    ...
}

NOTE: Be sure to remove any existing testEnvironment option from your Jest configuration. The jest-rest-preset preset needs to manage that option itself.

Use Jest-Rest in your tests:

  • with package.json
{
  "scripts": {
    "test": "jest"
  }
}
describe('Get test', () => {
  test('get', async () => {
    const get = await axios.get('https://httpbin.org/get', { headers: { token: 'sometoken' } });
    await jestRest.debug();
    expect(get.status).toBe(200);
  });
});

Configuration

You can specify a jest-rest.config.js or jest-rest.config.json at the root of the project. It should export a config object.

{

  /*
  * Define all global config for axios here
  *
  * More info at https://github.com/axios/axios#request-config
  */
  "axios": {},

  /*
  * Define all global config for ajv here
  *
  * More info at https://ajv.js.org/#options
  * default option added is {"allError": true}
  */
  "ajv": {}
}

Default jest timeout is 30 seconds

Put the tests in debug mode

Jest Rest exposes a method jestRest.debug() that suspends test execution and allows to see what's going on.

await jestRest.debug();

This will work perfectly when the tests are run sequentially using the jests --runInBand option or only single test is run.

Schema Validation

Jest-Rest extends the jest matcher to include schema validation using ajv. toMatchSchema

usage:

const schema = {
  properties: {
    foo: { type: 'string' },
    bar: { type: 'number', maximum: 3 },
  },
};
test('schema validation', async () => {
  const data = { foo: 'abc', bar: 2 };
  expect(data).toMatchSchema(schema);
});

Log request & response of axios

Use environment variable logger to log request and/ or response from axios to the console/terminal.

logger="*request" - To log axios request to console.

logger="*response" - To log axios response to console.

logger="*info" - To log axios request and response to console.

logger="*error" - To log axios error request and / or response to console.

usage: On Windows cmd

set logger=*request

using powershell

$env:logger="*request, *response"

on Mac/linux

export logger="*request, *response"

To disable logs, set an empty value logger="".

Usage with Typescript

Example Jest configuration in combination with ts-jest:

module.exports = {
  preset: 'jest-rest-preset',
  transform: {
    '^.+\\.ts$': 'ts-jest',
  },
};

Types are also available, which you can either use via directly in your test:

or at your central tsconfig.json either via types:

{
  "compilerOptions": {
    "types": ["jest-rest-preset", "@types/jest"]
  }
}

or via files:

{
  "files": ["@types/jest", "node_modules/jest-rest-preset/types/global.d.ts"]
}

HTML Reporters

There are multiple Html reporter plugin's available. Feel free to add as per your choice.

  • https://github.com/zaqqaz/jest-allure
  • https://github.com/dkelosky/jest-stare
  • https://github.com/Hazyzh/jest-html-reporters

Inspiration

Thanks to jest-playwright

License

MIT