question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mock server that mimics the GitHub API and supports webhooks

See original GitHub issue

Feature Request

Is your feature request related to a problem? Please describe.

Simulating a probot environment is hard. You have to mock many things and create fixtures. Also there are many steps when getting started: create a github API, create a private key, use something like smee.io to receive webhooks,…

Describe the solution you’d like I would like to simulate a whole environment locally. Many other platforms do so. If you want to develop an application using Amazon DynamoDB you can download an implementation that you can run locally. Same with Google App Engine: you can download an SDK that simulates the whole environment (or almost).

It would be great to have something similar for octokit/probot. Initially it would just be an HTTP server that mimics the GitHub API. I’ve called it mocktokit https://github.com/gimenete/mocktokit It stores all the information in memory. I’ll explain the idea better with an example.

const server = await mocktokit(5000, webhook)

// Create an octokit client with a custom baseUrl
const octokit = require('@octokit/rest')({
  baseUrl: 'http://localhost:5000'
})

// Now you can start making API requests to the mock server
// Just by using octokit

// At any moment you can get an immutable snapshot of the state
const state1 = server.getState()

// Modify something by using regular octokit methods
await octokit.issues.create({
  owner: 'gimenete',
  repo: 'test-repo',
  title: 'One issue'
})
// Take another snapshot
const state2 = server.getState()

Having something like this would allow anyone to do unit testing against octokit without having to mock anything theirselves, not even have to create fixtures. It would also lower the barrier to create probot applications because it would mimic also the webhooks behavior without having to set up anything else.

The basic structure is there, but it would require to implement all the methods available in octokit one by one. On the flip side, since everything is in memory, I don’t think it would be that hard.

Take a look to the README and let me know what you think.

PS: if this hook mechanism https://github.com/octokit/rest.js/issues/601#issuecomment-401491907 gets implemented, the mock server could be implemented without even creating an http server, just capturing the requests and generating proper responses. The API could be just:

const octokit = require('@octokit/rest')()
const mock = mocktokit(ocktokit) // installs the hook

// At any moment you can get an immutable snapshot of the state
const state1 = mock.getState()

// Modify something by using regular octokit methods
await octokit.issues.create({
  owner: 'gimenete',
  repo: 'test-repo',
  title: 'One issue'
})
// Take another snapshot
const state2 = mock.getState()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
gimenetecommented, Jul 3, 2018

Just a quick update. I’ve been able to add the monaco editor and inject the octokit types to it in runtime. Also, I’ve put a log of events to the right with the idea to inspect all events and be able to travel back in time to one of them. There’s also a “copy test to clipboard” which could be a functionality to generate and copy a complete jest/mocha test that re-creates all the events and asserts the final state.

screen shot 2018-07-03 at 12 35 01
2reactions
gr2mcommented, Jul 2, 2018

Hawman this looks really cool! That would be useful way beyond Probot, it would be useful to everyone integrating with the GitHub platform 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

opendevstack/mockbucket: The mock service of ODS
MockBucket. The mock service of ODS. Contents. This project provides a docker image with the following mocked services for ODS: GIT http server;...
Read more >
mock-api · GitHub Topics
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account ... Free, 11MB, containerized, self-hosted mock...
Read more >
Using the GitHub API in your app
This guide will help you build a GitHub App and run it on a server. The app you build will add a label...
Read more >
adrienverge/localstripe: A fake but stateful Stripe server ...
This is a program that you can launch to simulate a Stripe server locally, without touching real Stripe servers nor the Internet. Unlike...
Read more >
support dry-run variable · Issue #601 · octokit/octokit.js
When initializing the GitHubAPI client, there should be a ... Mock server that mimics the GitHub API and supports webhooks probot/probot#601.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found