Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ“… 11/21 @ 12:00pm PT - Refactoring a 10+ years old code base: nock (Part II) #54

Closed
6 of 7 tasks
gr2m opened this issue Nov 21, 2021 · 5 comments
Closed
6 of 7 tasks
Labels
show Preparation issue for a live show

Comments

@gr2m
Copy link
Owner

gr2m commented Nov 21, 2021

πŸ’πŸ» Refactoring a 10+ years old code base: nock
πŸ“… Sunday, November 21, 2021
πŸ• 12:00am Pacific Time
πŸŽ™οΈ no guests
πŸ“ https://www.twitch.tv/gregorcodes
🏷️ opensource


Subscribe to this issues to get a notification before the show begins and a summary after the show concludes.

Refactoring a 10+ years old code base: nock

nock is, to the best of my knowledge, the most widely used http mocking library for Node.js. It's first commit by Pedro is from September 2011. Around 6 years later, Pedro invited me as a maintainer, about a year after Pedro himself stopped maintaining nock.

I offered to take one the maintenance as we depended on nock for other projects I was maintaining, mostly @hoodiehq and @octokit. I, and increasingly we as a new maintainer team, were able to onboard more maintainers (RichardLitt, Paul, and Matt), and we were able to secure a sponsorship of $5,000 by Coinbase. Together, we were able to bring nock to a more maintainable state (most notably: 100% test coverage) and started addressing open issues and pull requests again.

But the nock code base is still a huge monolith of intertwined logic which is hard to understand and impossible to maintain with a few hours of time that people graciously donated from time to time.

In order to make nock's code base easier to understand, to maintain, and to make it possible to distribute the maintainership across more people, we decided the code base needs to be split up into separate modules

  1. @nock/intercept - overwrite Node's native APIs to hook into the request lifecycle.
  2. @nock/mock - provides API to define HTTP mocks
  3. @nock/recorder - APIs to record requests/responses and replay them from files

In this series of helpdesk shows, I'll live code on the nock code base attempting to split it up into the above modules.

Outline

In my first extended session working on nock (#53), I dove into the current code base and tried to understand it. In the 2nd part I focused on the intercept part. After the show I managed to make it actually work, with a hard-coded mock (notes).

  1. In this show I will try to figure out how to return a custom http.IncomingMessage instance for an intercepted request.
  2. Once I figure that out, I want to make it optionally possible to let the request pass through without intercepting, making it possible to record both the request and the response.
  3. With these features I should be able to replace the existing interception logic with the new internal intercept module. The goal is to make all existing tests pass using the new module.
  4. Finally, I'll move the internal module into its own repository and publish it as its own npm module.

I expect the work about will take about 3 shows.

TODOs

Before the show

undefined

When show begins

After the show

  • Reset twitter profile after the show
  • recording available tweet

Recordings

Shownotes

nock/nock#2247 (comment)

@gr2m gr2m changed the title DO NOT EDIT - Await parsing by GitHub Actions πŸ“… 11/21 @ 12:00pm PT - Refactoring a 10+ years old code base: nock Nov 21, 2021
@gr2m gr2m added the show Preparation issue for a live show label Nov 21, 2021
@gr2m
Copy link
Owner Author

gr2m commented Nov 21, 2021

Going live in 30 minutes at https://twitch.tv/gregorcodes

@gr2m
Copy link
Owner Author

gr2m commented Nov 21, 2021

I'm now live on https://twitch.tv/gregorcodes

@gr2m
Copy link
Owner Author

gr2m commented Nov 21, 2021

I'm taking a break, I'll be back in 20 min

@gr2m
Copy link
Owner Author

gr2m commented Nov 21, 2021

more like 30min, but I'm back

@gr2m
Copy link
Owner Author

gr2m commented Nov 22, 2021

done, for good now :)

@gr2m gr2m closed this as completed Nov 22, 2021
@gr2m gr2m changed the title πŸ“… 11/21 @ 12:00pm PT - Refactoring a 10+ years old code base: nock πŸ“… 11/21 @ 12:00pm PT - Refactoring a 10+ years old code base: nock - Part II Nov 22, 2021
@gr2m gr2m changed the title πŸ“… 11/21 @ 12:00pm PT - Refactoring a 10+ years old code base: nock - Part II πŸ“… 11/21 @ 12:00pm PT - Refactoring a 10+ years old code base: nock (Part II) Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
show Preparation issue for a live show
Projects
None yet
Development

No branches or pull requests

1 participant