Code Monkey home page Code Monkey logo

Comments (12)

prescottprue avatar prescottprue commented on June 12, 2024 1

@james-dowell That would be amazing if you get the chance, thanks!

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024 1

@aziparu The admin SDK can not be loaded within Cypress since it is running within the browser environment. The reason that most of this logic has lived within custom tasks is that those live within the node environment and are called from the cypress test environment through the provided custom commands.

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024 1

Going to wait to close this until it is better documented, but v1.3.0 with the noted changes has been released

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024 1

Logic has been improved for Timestamps which are not serverTimestamp, and docs have been added.

@aziparu I have actually now started using firebase.firestore.Timestamp.now() for server timestamps, or firebase.firestore.Timestamp.fromDate(new Date('01/01/2020')) when specifying a specific date.

If you really still want to be setting a timestamp, you can do { _methodName: 'FieldValue.serverTimestamp' }, but as you mentioned that is a bit unclear. We will probably want to come up with a better way to detect this for serverTimestamps, but normal timestamps seem to be working well now.

Going to close, but reach out if things don't work as you all expect or if you have more ideas for better handling of serverTimestamp

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024

Yeah, I have bumped into this one before and that was the thought around the withMeta option, but that only does createdAt and createdBy. Ideally it would allow service timestamps on any param like what you have shown.

Thanks for posting your solution! That is actually really similar to what I was thinking, but we would hopefully have it also handle multiple levels deep

from cypress-firebase.

james-dowell avatar james-dowell commented on June 12, 2024

I could take a stab at a PR for something a bit more robust with a test that could handle deeply nested timestamps if you'd like? .. probably in the next day or two. Unless you've already got it covered of course 😀

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024

The current solution we are using is causing the following error:

image

This is because we are actually using firebase-admin in the plugin code instead of using the timestamp passed from the adminInstance - this is needed to handle how things are done in the Cypress environment and is actually the reason that the admin instance needs to be passed to begin with. firebase-admin should only be getting used for types instead of required

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024

Pushed up a change to the v1.3.0 branch that should fix the issue - going to wait until I can do a bit more testing before merging

from cypress-firebase.

james-dowell avatar james-dowell commented on June 12, 2024

Ahh I see okay 👍 sounds good. Thanks for pushing this through @prescottprue , much appreciated.

Let me know if I can help out with anything else

from cypress-firebase.

aziparu avatar aziparu commented on June 12, 2024

Hi @james-dowell. Thanks to you and @prescottprue for writing the changes to allow for server timestamps. I started using v1.3.0 and things are working fine so far. I was wondering if you could help me with something. I'm not able to use firestore.FieldValue.serverTimestamp() as you did in your example in the OP. If I add import { firestore } from 'firebase-admin';, then I get this error in the Cypress browser:

Error: Webpack Compilation Error
./node_modules/@google-cloud/firestore/node_modules/google-gax/build/src/operationsClient.js
Module not found: Error: Can't resolve './operations_client_config'

There are several more module not found errors as well. If I add import { firestore } from 'firebase'; instead, then I get this error during the test run:

CypressError
cy.task('callFirestore') failed with the following error:
> Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    --- property 'Ca' closes the circle

This was in the stack trace:

From Your Spec Code:
    at Context.eval (webpack:///node_modules/cypress-firebase/lib/attachCustomCommands.js:163:1)

Right now, I'm using { _methodName: 'FieldValue.serverTimestamp' } instead of firestore.FieldValue.serverTimestamp(), which works. Any help would be appreciated.

from cypress-firebase.

aziparu avatar aziparu commented on June 12, 2024

I see. That makes sense. Do you know how can I set a serverTimestamp on a field using cy.callFirestore like

cy.callFirestore('set', 'path/to/doc`, { 
  name: 'Apples',
  lastUpdated: firestore.FieldValue.serverTimestamp() 
});

aside from using { _methodName: 'FieldValue.serverTimestamp' } instead of firestore.FieldValue.serverTimestamp()?

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024

@aziparu You should be able to pull that in from the client Firebase SDK:

import firebase from 'firebase/app'
import 'firebase/firestore'

// Then later
firebase.firestore.FieldValue.serverTimestamp()

from cypress-firebase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.