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

Prevent tests from ever connecting to a couch instance... #38

Open
the-t-in-rtf opened this issue Sep 25, 2014 · 3 comments
Open

Prevent tests from ever connecting to a couch instance... #38

the-t-in-rtf opened this issue Sep 25, 2014 · 3 comments

Comments

@the-t-in-rtf
Copy link
Contributor

In working on recent tests, I have noticed that nock is not entirely preventing connections to the local couch instance, which is still required to run many tests.

I would propose one of the following:

  1. migrating to using pouchdb for testing. I have had good results using that to replace couch in other unit tests, as long as the views used are not too complex (ours aren't in this case).
  2. firewalling nock by disabling connections using disableNetConnect() and fixing any tests that break (see below).

For the firewalling option, I tried using code like the following:

 nock.disableNetConnect();
 nock.enableNetConnect("(localhost|127.0.0.1):(?!5984).*");

In doing so, I discovered that nock appears to be shared across tests, which is hugely dangerous. I will file a separate bug on that.

@warrensplayer
Copy link
Collaborator

I am all for calling nock.disableNetConnect(); to prevent nock from calling out to a real endpoint. It is definitely best practice for unit tests to not rely on external endpoints.

I don't think it is worth changing all the tests to use pouchdb unless there are some other benefits that it provides over nock.

@warrensplayer
Copy link
Collaborator

@the-t-in-rtf Can you paste in the output from the tests before you added that nock.disableNetConnect()? I want to make sure I can reproduce your issue. Thanks!

@the-t-in-rtf
Copy link
Contributor Author

@warrensplayer, check out this branch:

https://github.com/the-t-in-rtf/express-couchUser/tree/nock-disable-net

With a single line change to one test I can break all tests. I disabled networking connections in the signup tests, and the rest of the tests (signin, delete) stop working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants