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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mikrotester

v1.0.0

Published

Smooth, minimalist integration testing for humans.

Downloads

5

Readme

MikroTester

Smooth, minimalist integration testing for humans.

Build Status Quality Gate Status codecov Maintainability


Integration testing is sometimes made harder and more complicated than it really is. If you ever wanted to do integration testing with the least amount of effort, then MikroTester should fit like hand in glove.

  • Simple syntax
  • Lightweight, only one dependency, Ajv, which is used for JSON schema comparisons
  • High test coverage

Behavior

MikroTester allows you to pass in an array of simple-to-define tests. For each endpoint, you may add one or multiple assertions.

The result will always contain a boolean (true/false) success state for each assertion.

Native Fetch is used, so you will need a Node version newer than 18 or so.

Usage

MikroTester is very simple to use. We'll use the Star Wars API to demonstrate just how easy it is!

import { MikroTester } from 'mikrotester';

const tests = [
  {
    "endpoint": "https://swapi.dev/api/people/1",
    "method": "GET",
    "assertions": [
      {
        "name": "The status code is 200",
        "statusCodeIs": 200
      }
    ]
  }
];

const mikrotester = new MikroTester();
const results = await mikrotester.runTests(tests);

console.log(results);

So, what's going on here?

  • The endpoint should be self-explanatory.
  • The method can be GET, POST, PUT, PATCH and DELETE.
  • The assertions always contain a name (what does the test do?) and one of several types: statusCodeIs, is, or matches.

Next, let's check out all the ways you can do those assertions.

Matches (matches)

Use a JSON Schema to check your response. This is a good, solid option for more mature tests.

[
  {
    "endpoint": "https://swapi.dev/api/people/1",
    "method": "GET",
    "assertions": [
      {
        "name": "The result matches the JSON Schema",
        "matches": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "name": {
              "type": "string"
            },
            "height": {
              "type": "string"
            },
            "mass": {
              "type": "string"
            },
            "hair_color": {
              "type": "string"
            },
            "skin_color": {
              "type": "string"
            },
            "eye_color": {
              "type": "string"
            },
            "birth_year": {
              "type": "string"
            },
            "gender": {
              "type": "string"
            },
            "homeworld": {
              "type": "string"
            },
            "films": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "species": {
              "type": "array",
              "items": {}
            },
            "vehicles": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "starships": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "created": {
              "type": "string"
            },
            "edited": {
              "type": "string"
            },
            "url": {
              "type": "string"
            }
          },
          "required": [
            "birth_year",
            "created",
            "edited",
            "eye_color",
            "films",
            "gender",
            "hair_color",
            "height",
            "homeworld",
            "mass",
            "name",
            "skin_color",
            "species",
            "starships",
            "url",
            "vehicles"
          ]
        }
      }
    ]
  }
]

Is object (is)

Check for an exact match of the object. For very stable systems this will work just fine, but it also creates quite a bit of coupling between test and reality.

[
  {
    "endpoint": "https://swapi.dev/api/people/1",
    "method": "GET",
    "assertions": [
      {
        "name": "The result is exactly correct",
        "is": {
          "name": "Luke Skywalker",
          "height": "172",
          "mass": "77",
          "hair_color": "blond",
          "skin_color": "fair",
          "eye_color": "blue",
          "birth_year": "19BBY",
          "gender": "male",
          "homeworld": "https://swapi.dev/api/planets/1/",
          "films": [
            "https://swapi.dev/api/films/1/",
            "https://swapi.dev/api/films/2/",
            "https://swapi.dev/api/films/3/",
            "https://swapi.dev/api/films/6/"
          ],
          "species": [],
          "vehicles": ["https://swapi.dev/api/vehicles/14/", "https://swapi.dev/api/vehicles/30/"],
          "starships": [
            "https://swapi.dev/api/starships/12/",
            "https://swapi.dev/api/starships/22/"
          ],
          "created": "2014-12-09T13:50:51.644000Z",
          "edited": "2014-12-20T21:17:56.891000Z",
          "url": "https://swapi.dev/api/people/1/"
        }
      }
    ]
  }
]

Is response (is)

Check for an exact string response. Good for simple services that give short, stable messages.

[
  {
    "endpoint": "https://swapi.dev/api/people/3",
    "method": "GET",
    "assertions": [
      {
        "name": "The message matches",
        "is": "There is a message here"
      }
    ]
  }
]

Status code is (statusCodeIs)

Verifies that the status code is the expected one.

[
  {
    "endpoint": "https://swapi.dev/api/people/1",
    "method": "GET",
    "assertions": [
      {
        "name": "The status code is 200",
        "statusCodeIs": 200
      }
    ]
  }
]

The response

The response for all of the calls will be:

[
  {
    "name": "Your test name",
    "success": true, // Always a boolean
    "status": 200, // Whatever the response status code was
    "response": { ... }, // Response from the integration call
    "expected": { ... } // Assertion that you passed in
  },
  {
    ... // Next test
  }
]

License

MikroTester is licensed under the MIT license.