Skip to content
This repository was archived by the owner on Mar 29, 2022. It is now read-only.

Initial attempt at supporting Firebase 3.x #51

Merged
merged 4 commits into from
Jun 22, 2016
Merged

Initial attempt at supporting Firebase 3.x #51

merged 4 commits into from
Jun 22, 2016

Conversation

nfarina
Copy link
Contributor

@nfarina nfarina commented May 23, 2016

See #50.

Opening this PR early for feedback. This is not ready to merge!

The new Firebase client, besides having a different API structure, is hardcoded to authenticate with google.com using a service account. To skip this process requires some extensive mocking, which you'll see in server.spec.js. Additionally, I could not get any mocks to work without the @global option which proxyquire strongly discourages.

But it works well enough for most of the tests to pass.

With this level of mocking, I think "copy and paste this mocking code into your tests" is probably too onerous for the user, so I would recommend moving this code into firebase-server proper for the user to activate with one command.

Checklist of what is remaining:

  • Make remaining tests pass.
  • Improve mocking to avoid the @global require override.
  • Refactor out mocks and make them easily accessible to the user.

Open to any and all feedback on this! This has become quite a project and I will probably need some help to finish it.

nfarina added 2 commits May 23, 2016 14:21
- Currently 27 passing, 10 failing tests.
- Expanded stubbing required to trick Firebase 3.x into connecting
locally without any network calls.
@nfarina
Copy link
Contributor Author

nfarina commented May 23, 2016

Quick update: It turns out mocking is actually not necessary for firebase-server itself, as goOffline() does indeed prevent the internal client from connecting to Google. I'll update the PR text above to reflect this.

@nfarina
Copy link
Contributor Author

nfarina commented May 23, 2016

Alright, only four failing tests left. These will be tricky, because they concern testing the client authentication features (using generated "custom tokens"). When the firebase module is used from within a NodeJS environment, it exposes a different API - it assumes you are running it on a server, and the only authentication method supported is Google service accounts.

Firebase seems to determine at runtime which "version" of itself to use - either the Browser or the Server implementation of the Firebase client.

This creates an interesting problem - when running in the browser, your code consuming Firebase will have access to a completely different API than it will have access to while running mocha tests in NodeJS.

@urish
Copy link
Owner

urish commented May 24, 2016

Looks promising, thanks!

@urish urish merged commit e5cafae into urish:master Jun 22, 2016
@nfarina
Copy link
Contributor Author

nfarina commented Jun 22, 2016

Well I guess this PR was getting a bit stale. I've been poking around trying to improve all this but haven't made much progress. I'll open a new PR for some cleanup.

@urish
Copy link
Owner

urish commented Jun 22, 2016

Thank you @nfarina , I am working on finishing it as we speak. We still have 4 tests fail since there is no authentication API on the server side. I will commit my progress so far in a few minutes

@nfarina
Copy link
Contributor Author

nfarina commented Jun 22, 2016

OK cool, I'll check that out when you're ready. There is one small bugfix that I hadn't checked in yet - in index.js:

screen shot 2016-06-22 at 9 30 31 am

Also, the proxyquire dep needs to be moved from devDependencies to just dependencies - the firebase module needs to always be mocked for firebase-server to work at all.

@urish
Copy link
Owner

urish commented Jun 22, 2016

yes, I just figured that one myself now :)

Regarding proxyquire - I don't see it being used inside index.js, can you explain why it is required then?

@nfarina
Copy link
Contributor Author

nfarina commented Jun 22, 2016

It's not mocked in index.js currently but perhaps should be. Right now the tests pass because the test runner happens to set up the mocks before index.js is required. You'll see the problem if you try to run firebase-server as a "standalone server" listening on a port - i.e. not in a test context. It won't work at all unless someone (itself?) mocks firebase.

@nfarina
Copy link
Contributor Author

nfarina commented Jun 22, 2016

Well of course now I can't repro that problem. Perhaps goOffline does in fact prevent firebase from reaching out to Google Auth. Trying to remember why I thought this was a problem now.

@nfarina
Copy link
Contributor Author

nfarina commented Jun 22, 2016

Alright I'm wrong! goOffline does the trick, and running firebase-server from the command-line works just fine without mocks. Wow, that makes things much much simpler.

@urish
Copy link
Owner

urish commented Jun 22, 2016

That's superb! I am about to finishing fixing tests, committing soon and aiming for 0.6.0 release today, with Firebase 3 support :-)

@nfarina
Copy link
Contributor Author

nfarina commented Jun 22, 2016

Awesome. Oh, and in regards to the @global flag for proxyquire, I think it's much less harmful than it appears - it's only "global" within the local context of modules internally loaded by firebase itself, not global across the entire loaded NodeJS app.

@urish
Copy link
Owner

urish commented Jun 22, 2016

Seems like we tests are passing now, hooray!

@nfarina nfarina deleted the support-firebase-3 branch June 22, 2016 19:04
@nfarina
Copy link
Contributor Author

nfarina commented Jun 22, 2016

Wow, your mocking method is so much cleaner! Looks awesome and seems to work great.

@urish
Copy link
Owner

urish commented Jun 22, 2016

Thank you :)

It took a few hours of experimentation to get there though...

@urish
Copy link
Owner

urish commented Jun 22, 2016

Released as 0.6.0. Thank you again for all your contribution to this release!

@hoppula
Copy link

hoppula commented Jun 22, 2016

This is great! Thanks @nfarina and @urish!

@urish urish mentioned this pull request Jul 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants