All Projects → octokit → fixtures

octokit / fixtures

Licence: MIT license
Fixtures for all the octokittens

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fixtures

Monkey
Monkey is an unofficial GitHub client for iOS,to show the rank of coders and repositories.
Stars: ✭ 1,765 (+2052.44%)
Mutual labels:  octokit, github-api
Octokit.rb
Ruby toolkit for the GitHub API
Stars: ✭ 3,522 (+4195.12%)
Mutual labels:  octokit, github-api
actions
Collection of repetitive GitHub Actions
Stars: ✭ 12 (-85.37%)
Mutual labels:  github-api
journalist
App to write journal digitally. Simple as that.
Stars: ✭ 23 (-71.95%)
Mutual labels:  github-api
neo
A Discord bot built to satisfy a multitude of needs
Stars: ✭ 16 (-80.49%)
Mutual labels:  github-api
Triton
GitHub notifications tracker for Telegram. Pushes GitHub notifications to Telegram.
Stars: ✭ 12 (-85.37%)
Mutual labels:  github-api
awesome-generator
Generate awesome list over Github API
Stars: ✭ 46 (-43.9%)
Mutual labels:  github-api
Gitter
Gitter for GitHub - 可能是目前颜值最高的GitHub微信小程序客户端
Stars: ✭ 3,555 (+4235.37%)
Mutual labels:  github-api
github-status-updater
Command line utility for updating GitHub commit statuses and enabling required status checks for pull requests
Stars: ✭ 83 (+1.22%)
Mutual labels:  github-api
org-stats
Get the contributor stats summary from all repos of any given organization
Stars: ✭ 151 (+84.15%)
Mutual labels:  github-api
larry
Larry 🐦 is a really simple Twitter bot generator that tweets random repositories from Github built in Go
Stars: ✭ 64 (-21.95%)
Mutual labels:  github-api
zulipbot
GitHub workflow-optimizing bot by @zulip
Stars: ✭ 70 (-14.63%)
Mutual labels:  github-api
ezprofile
🚀 Create an automatic portfolio based on GitHub profile.
Stars: ✭ 344 (+319.51%)
Mutual labels:  github-api
myPortfolio
This is a portfolio application built by using Next.js, ChakraUi, Typescript and Dev.to api.
Stars: ✭ 127 (+54.88%)
Mutual labels:  github-api
GithubClient
Github iOS Client based on Github REST V3 API and GraphQL V4 API
Stars: ✭ 42 (-48.78%)
Mutual labels:  github-api
Recent-Commits-on-Repository
Find a github repository an its recent commits
Stars: ✭ 12 (-85.37%)
Mutual labels:  github-api
github-react-native-apollo-graphql
📱 A GitHub mobile app built with React-Native and Apollo GraphQL
Stars: ✭ 24 (-70.73%)
Mutual labels:  github-api
gh-notify
GitHub CLI extension to display GitHub notifications
Stars: ✭ 66 (-19.51%)
Mutual labels:  github-api
github-markdown-render
Display Markdown formatted documents on your local web server using GitHub's Markdown rendering API and CSS to mimic the visuals of GitHub itself.
Stars: ✭ 18 (-78.05%)
Mutual labels:  github-api
github-app
node module to handle authentication for the GitHub Apps API
Stars: ✭ 51 (-37.8%)
Mutual labels:  github-api

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].