Skip to content

onSnapshot support #19

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

Merged
merged 14 commits into from
Dec 11, 2019
Merged

onSnapshot support #19

merged 14 commits into from
Dec 11, 2019

Conversation

zeevl
Copy link

@zeevl zeevl commented Nov 12, 2019

Hey, first, thanks so much for offering to take over support of this project!

This brings over support for onSnapshot that current exists in soumak77#158.

I added metadata to the MockFirestoreDocumentSnapshot so we could use this in our project. However, I'm not sure what the proper etiquette is for this type of PR... other people's work on the upstream (dead) project, only slightly modified? They certainly deserve the credit here, haha.

Anyways, let me know if you want something done differently here.

BrianChapman and others added 6 commits January 23, 2019 08:38
…l the onSnapshot callbacks no mater where the flush is called from.
…tial callback-call.

First case where it would fail: the initial-data was null and it would think "no change", despite it needing to always trigger initially.

Second case where it would fail: calling onSnapshot on a document instead of a query.
@dmurvihill
Copy link
Owner

Hey @zeevl, thanks for the pull request. Your name is on the PR but @BrianChapman's and @Venryx's names are still attached to all of the commits, so I think we should have no trouble with attribution. I'm just returning from a vacation and need a minute to look these over.

package-lock.json was deleted and re-created to resolve a merge
conflict.

# Conflicts:
#	package-lock.json
@dmurvihill
Copy link
Owner

After merging in master, I am seeing 5 failing unit tests:

  463 passing (1s)
  27 pending
  5 failing

  1) MockFirestoreDocument #onSnapshot returns value after document is updated:
     AssertionError: expected undefined to equal 'A new title'
      at test/unit/firestore-document.js:470:41
      at onSnapshot (src/firestore-document.js:9:14768)
      at MockFirestoreDocument.onSnapshot (src/firestore-document.js:9:15093)
      at Context.<anonymous> (test/unit/firestore-document.js:469:11)
      at process.topLevelDomainCallback (domain.js:120:23)

  2) MockFirestoreDocument #onSnapshot returns error if error occured:
     Error: done() called multiple times
      at Suite.<anonymous> (test/unit/firestore-document.js:477:5)
      at Suite.<anonymous> (test/unit/firestore-document.js:467:3)
      at Object.<anonymous> (test/unit/firestore-document.js:14:1)
      at Module._compile (internal/modules/cjs/loader.js:689:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
      at Object.Module._extensions.(anonymous function) [as .js] (node_modules/istanbul/lib/hook.js:109:37)
      at Module.load (internal/modules/cjs/loader.js:599:32)
      at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
      at Function.Module._load (internal/modules/cjs/loader.js:530:3)
      at Module.require (internal/modules/cjs/loader.js:637:17)
      at require (internal/modules/cjs/helpers.js:22:18)

  3) MockFirestoreDocument #onSnapshot does not returns value when not updated:

      AssertionError: expected 2 to equal 1
      + expected - actual

      -2
      +1
      
      at Context.<anonymous> (test/unit/firestore-document.js:497:28)
      at process.topLevelDomainCallback (domain.js:120:23)

  4) MockFirestoreDocument #onSnapshot unsubscribes:

      AssertionError: expected 2 to equal 1
      + expected - actual

      -2
      +1
      
      at Context.<anonymous> (test/unit/firestore-document.js:511:28)
      at process.topLevelDomainCallback (domain.js:120:23)

  5) MockFirestoreDocument #onSnapshot accepts option includeMetadataChanges:
     AssertionError: expected undefined to equal 'A new title'
      at test/unit/firestore-document.js:521:41
      at onSnapshot (src/firestore-document.js:9:14768)
      at MockFirestoreDocument.onSnapshot (src/firestore-document.js:9:15093)
      at Context.<anonymous> (test/unit/firestore-document.js:520:11)
      at process.topLevelDomainCallback (domain.js:120:23)



[19:00:00] '<anonymous>' errored after 12 ms
[19:00:00] Error in plugin 'gulp-mocha'
Error
    at Domain.handleException (/Users/dolan/firebase-mock/node_modules/gulp-mocha/index.js:46:24)
    at Domain.emit (events.js:189:13)
    at Domain.EventEmitter.emit (domain.js:441:20)
    at Domain._errorHandler (domain.js:223:23)
    at Object.setUncaughtExceptionCaptureCallback (domain.js:139:29)
    at process._fatalException (internal/bootstrap/node.js:493:31)
[19:00:00] 'test' errored after 417 ms
npm ERR! Test failed.  See above for more details.

Does this work on your branch? I'm running a newer version of node and gulp.

@zeevl
Copy link
Author

zeevl commented Nov 19, 2019

Honestly I haven't been able to get tests to run -- gulp keeps crashing with node.

What versions are you using? I've tried with both node 10.x and 12.x and they both crash with node stracktraces, which seem to be incompatibility errors. Maybe time to upgrade to gulp 4?

@dmurvihill
Copy link
Owner

Gulp 3 is incompatible with Node 10+, but if you merge dmurvihill:master you should get Gulp 4.

@zeevl
Copy link
Author

zeevl commented Nov 20, 2019

Perfect, thanks! Tests fixed.

…into issue-81-onsnapshot

� Conflicts:
�	package-lock.json
Copy link
Owner

@dmurvihill dmurvihill left a comment

Choose a reason for hiding this comment

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

Ok, this is almost ready. I see a couple of very subtle bugs and scads of missing tests. A couple of hours of editing and we will be there.

@@ -67,37 +67,11 @@ MockFirestoreQuery.prototype.get = function () {
var self = this;
return new Promise(function (resolve, reject) {
self._defer('get', _.toArray(arguments), function () {
var results = {};
var results = self._results();
var limit = 0;
Copy link
Owner

Choose a reason for hiding this comment

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

used?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, but limit wasn't. Removed.

}
});
}

resolve(new QuerySnapshot(self.parent === null ? self : self.parent.collection(self.id), results));
Copy link
Owner

Choose a reason for hiding this comment

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

I think these two branches are equivalent now.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what you're referring to here..

Copy link
Owner

Choose a reason for hiding this comment

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

Line 71 and line 73 do the same thing, which means the if-else is meaningless.

@zeevl zeevl requested a review from dmurvihill November 22, 2019 20:50
@zeevl
Copy link
Author

zeevl commented Nov 22, 2019

Thanks for the quality review @dmurvihill!

# Conflicts:
#	package-lock.json
#	src/firestore-query.js
@dmurvihill dmurvihill merged commit 71528b9 into dmurvihill:master Dec 11, 2019
@dmurvihill
Copy link
Owner

Merged. Look for a release in the next few days. Thanks @BrianChapman, @Venryx, and @zeevl for getting this over the line.

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

Successfully merging this pull request may close these issues.

4 participants