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

@octokit/fixtures

v23.1.1

Published

Fixtures for all the octokittens

Downloads

3,108

Readme

fixtures

Fixtures for all the octokittens

Test

Records requests/responses against the GitHub REST API and stores them as JSON fixtures.

Usage

Currently requires node 8+

fixtures.mock(scenario)

fixtures.mock(scenario) will intercept requests using nock. scenario is a String in the form <host name>/<scenario name>. host name is any folder in scenarios/. scenario name is any filename in the host name folders without the .js extension.

const https = require("https");
const fixtures = require("@octokit/fixtures");

fixtures.mock("api.github.com/get-repository");
https
  .request(
    {
      method: "GET",
      hostname: "api.github.com",
      path: "/repos/octokit-fixture-org/hello-world",
      headers: {
        accept: "application/vnd.github.v3+json",
      },
    },
    (response) => {
      console.log("headers:", response.headers);
      response.on("data", (data) => console.log(data.toString()));
      // logs response from fixture
    },
  )
  .end();

For tests, you can check if all mocks have been satisfied for a given scenario

const mock = fixtures.mock("api.github.com/get-repository");
// send requests ...
mock.done(); // will throw an error unless all mocked routes have been called
mock.isDone(); // returns true / false
mock.pending(); // returns array of pending mocks in the format [<method> <path>]

mock.explain can be used to amend an error thrown by nock if a request could not be matched

const mock = fixtures.mock("api.github.com/get-repository");
const github = new GitHub();
return github.repos
  .get({ owner: "octokit-fixture-org", repo: "hello-world" })
  .catch(mock.explain);

Now instead of logging

Error: Nock: No match for request {
  "method": "get",
  "url": "https://api.github.com/orgs/octokit-fixture-org",
  "headers": {
    "host": "api.github.com",
    "content-length": "0",
    "user-agent": "NodeJS HTTP Client",
    "accept": "application/vnd.github.v3+json"
  }
}

The log shows exactly what the difference between the sent request and the next pending mock is

 Request did not match mock:
 {
   headers: {
-    accept: "application/vnd.github.v3"
+    accept: "application/vnd.github.v3+json"
   }
 }

fixtures.get(scenario)

fixtures.get(scenario) will return the JSON object which is used by nock to mock the API routes. You can use that method to convert the JSON to another format, for example.

fixtures.nock

fixtures.nock is the nock instance used internally by @octokit/fixtures for the http mocking. Use at your own peril :)

License

MIT