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

Refactor Firebase Admin Stubbing #1459

Merged
merged 11 commits into from Jul 11, 2019
Merged

Refactor Firebase Admin Stubbing #1459

merged 11 commits into from Jul 11, 2019

Conversation

samtstern
Copy link
Contributor

@samtstern samtstern commented Jul 2, 2019

Description

Fixes issue #1454

This investigation took me very deep and along the way I also:

  • Added some standardization for how we resolve developer node modules and made sure we log them.
  • Simplified some of our logging code.

Scenarios Tested

Using these functions to test:

const functions = require("firebase-functions");
const admin = require('firebase-admin');

const app = admin.initializeApp();

exports.writeThroughAdmin = functions.https.onRequest(async (req, res) => {
    const firestore = admin.firestore();
    const ref = firestore.doc("info/test");
    await ref.set({ hello: (new Date().toISOString()) });
    ref.get().then((snap) => {
        res.json({ data: snap.data() });
    });
});

exports.writeThroughApp = functions.https.onRequest(async (req, res) => {
    const firestore = app.firestore();
    const ref = firestore.doc("info/test");
    await ref.set({ hello: (new Date().toISOString()) });
    ref.get().then((snap) => {
        res.json({ data: snap.data() });
    });
});

exports.firestoreReaction = functions.firestore.document("info/test").onWrite(async (change, ctx) => {
    console.log('~~~~~~~~~~ FIRESTORE WRITE ~~~~~~~~~~');
    return true;
});

I also added a unit test that verifies the same behavior.

Sample Commands

N/A

@googlebot googlebot added the cla: yes Manual indication that this has passed CLA. label Jul 2, 2019
@samtstern samtstern requested a review from abeisgoat July 2, 2019 18:24
@coveralls
Copy link

coveralls commented Jul 2, 2019

Coverage Status

Coverage increased (+0.1%) to 61.884% when pulling 6bf6372 on ss-fix-1454 into c871443 on master.

package-lock.json Outdated Show resolved Hide resolved
@samtstern samtstern requested review from yuchenshi and removed request for ryanpbrewster July 3, 2019 16:13
yuchenshi
yuchenshi previously approved these changes Jul 3, 2019
Copy link
Member

@yuchenshi yuchenshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I still cannot get my head around the three layers of stubbing involved in this PR (JS proxy, Node.js require cache, fake creds) and I'm not familiar with the code base. But I'm sure it will be fine somehow.

WANT_LGTM=abeisgoat

@samtstern
Copy link
Contributor Author

@yuchenshi thanks for taking a look. I agree with waiting for @abeisgoat

@yuchenshi yuchenshi dismissed their stale review July 3, 2019 18:30

Waiting on @abeisgoat to take a final pass.

Copy link
Contributor

@abeisgoat abeisgoat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good as long as there aren't any logic changes in the big function

src/emulator/functionsEmulatorRuntime.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants