mock-registry #3633

Closed
robertkowalski opened this Issue Jul 7, 2013 · 4 comments

Projects

None yet

4 participants

@robertkowalski
Member

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

@luk-
luk- commented Jul 10, 2013

It might just be easier to set up your own npm server

@domenic
Member
domenic commented Jul 10, 2013

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.

@isaacs
Member
isaacs commented Jul 10, 2013

Yes. I've thought about doing this many times, but it's tedious. If you want to do this, you have my blessing.

@robertkowalski
Member

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

@robertkowalski robertkowalski added a commit to robertkowalski/npm that referenced this issue Aug 1, 2013
@robertkowalski robertkowalski use npm-registry-mock, fixes #3633 a2dfe0f
@robertkowalski robertkowalski added a commit to robertkowalski/npm that referenced this issue Aug 1, 2013
@robertkowalski robertkowalski use npm-registry-mock, fixes #3633 f0f5945
@domenic domenic closed this in 667f7ba Aug 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment