Every time I develop a new thing for npm I want to write tests, where the most boring and repeated part is to mock the registry. Even worse, for small features I don't write a test because all that mocking overhead is far too annoying.
So here is my pitch: If there is nothing around for it, I would start to develop a mock-registry which mocks most of the interactions of npm and friends with the registry.
I would suggest using nock or hock as base and if someone wants to participate (in case there is no such thingy for the npm-registry) I can add them to the repo.
//cc @mmalecki @pgte
It might just be easier to set up your own npm server
No, it'd be nice to have a very fast in-memory one that you can use in true unit tests, like @robertkowalski has already done in the tests he committed.
My advice would be to not worry about creating a full-fledged mock registry, but instead extract what you've already done in your tests into a single mock registry abstraction that's very easy to use. Then keep adding features to it as you build more tests. Trying to get it all right the first time seems not very fun.
Yes. I've thought about doing this many times, but it's tedious. If you want to do this, you have my blessing.
Build a first one based on the plain http-server, but the routing was a mess and the whole thing smelled slightly like Not-Invented-Here.
I build a second version afterwards based on nock which has much less lines of code that is able to mock the same routes which I previously defined in my tests for the first mock-server. It is not a full registry, but the idea is to add more features over time when they are needed, like @domenic suggested.
If you want to have a look: https://github.com/robertkowalski/npm-registry-mock
use npm-registry-mock, fixes #3633