Comments (12)
@james-dowell That would be amazing if you get the chance, thanks!
from cypress-firebase.
@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.
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.
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.
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.
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.
The current solution we are using is causing the following error:
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.
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.
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.
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.
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.
@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)
- publish-npm failing Error: Error [ERR_REQUIRE_ESM]: require() of ES Module HOT 1
- bug: cannot read properties of undefined (reading 'includes') HOT 4
- Login after a logout happening the application fails
- Cypress e2e test fails initialization HOT 1
- feat(build): native esm support
- fix: drop support for node pre 16 HOT 2
- Support passing user claims to cy.login() ? HOT 1
- Invalid options types are ignored, rather than erroring
- The automated release is failing 🚨
- bug(docs): README.md setup is not clear about service account HOT 6
- Retry on 401
- bug(firestore): FieldValue.delete() not handled correctly HOT 3
- feat(callFirestore): ability to use batch writes
- bug(firestore): nested Timestamp value not persisting HOT 3
- bug: callFirestore not recognized in NextJS test HOT 1
- feat: support for component testing
- feat: switch to modular firebase sdks internally HOT 2
- bug(core): Webpack error when running cypress tests with cypress-firebase HOT 10
- callFirestore task fails when running in the CI with message "PERMISSION_DENIED: Missing or insufficient permissions." HOT 1
- Problem with Token HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cypress-firebase.