Comments (15)
Great to know, thanks for reporting. I got it working with the example too, so going to do a bit more testing then get it ready for latest
from cypress-firebase.
Thanks for reporting! Moving the fs deps to their own file sounds like a good move, maybe something like node-utils.js
.
It would probably also help if some types are exported. I have actually been thinking about switching this library over to typescript anyway
from cypress-firebase.
That would make things SO much easier, if it were in typescript. Currently, I'm using a mix of code adapted from yours, but still using your commands through the command line. Once you go to Typescript, I will be able to use this completely!
from cypress-firebase.
@danielmhair and @dhair-seva Here is a PR where I started the switch over to typescript: #49. Planning on releasing it to next
soon, but want to test to make sure everything still works as expected.
Did you have something in particular that you were looking to import as far as types are concerned? I think it may be nice to use something like a global declaration to make sure that the extra commands are available on the cy
object.
For a shorter term fix for latest
, I think switching around where things are as @dhair-seva proposed still makes sense.
from cypress-firebase.
That sounds great! I noticed that it has v0.3.0-alpha. Am I able to use that version to test it? I looked through the code and yeah, I think the only thing needed is adding things to the cy object, especially your comments that you have above the functions, like login, logout, etc. Here is what I did before:
declare namespace Cypress {
interface Chainable {
/**
* Login to Firebase auth using FIREBASE_AUTH_JWT environment variable
* which is generated using firebase-admin authenticated with serviceAccount
* during test:buildConfig phase.
* @example cy.login()
* @type {Cypress.Command}
* @name cy.login
*/
login(): Chainable
/**
* Log out of Firebase instance
* @memberOf Cypress.Chainable#
* @type {Cypress.Command}
* @name cy.logout
* @example
* cy.logout()
*/
logout(): Chainable
/**
* Call Real Time Database path with some specified action. Authentication is through FIREBASE_TOKEN since firebase-tools is used (instead of firebaseExtra).
* @param {String} action - The action type to call with (set, push, update, remove)
* @param {String} actionPath - Path within RTDB that action should be applied
* @param {Object} opts - Options
* @param {Array} opts.args - Command line args to be passed
* @name cy.callRtdb
* @type {Cypress.Command}
* @example <caption>Set Data</caption>
* const fakeProject = { some: 'data' }
* cy.callRtdb('set', 'projects/ABC123', fakeProject)
* @example <caption>Set Data With Meta</caption>
* const fakeProject = { some: 'data' }
* // Adds createdAt and createdBy (current user's uid) on data
* cy.callRtdb('set', 'projects/ABC123', fakeProject, { withMeta: true })
* @example <caption>Get/Verify Data</caption>
* cy.callRtdb('get', 'projects/ABC123')
* .then((project) => {
* // Confirm new data has users uid
* cy.wrap(project)
* .its('createdBy')
* .should('equal', Cypress.env('TEST_UID'))
* })
* @example <caption>Other Args</caption>
* const opts = { args: ['-d'] }
* const fakeProject = { some: 'data' }
* cy.callRtdb('update', 'project/test-project', fakeProject, opts)
*/
callRtdb(action: string, actionPath: string, data?: any, opts?: any = {}): Chainable
/**
* Call Firestore instance with some specified action. Authentication is through serviceAccount.json since it is at the base
* level. If using delete, auth is through `FIREBASE_TOKEN` since firebase-tools is used (instead of firebaseExtra).
* @param {String} action - The action type to call with (set, push, update, remove)
* @param {String} actionPath - Path within RTDB that action should be applied
* @param {Object} opts - Options
* @param {Array} opts.args - Command line args to be passed
* @name cy.callFirestore
* @type {Cypress.Command}
* @example <caption>Basic</caption>
* cy.fixture('fakeProject.json').then((project) => {
* cy.callFirestore('add', 'project/test-project', project)
* })
* @example <caption>Fixture Path</caption>
* cy.fixture('fakeProject.json').then((project) => {
* cy.callFirestore('add', 'project/test-project', project)
* })
* @example <caption>Fixture Path</caption>
* cy.callFirestore('add', 'project/test-project', 'fakeProject.json')
* @example <caption>Recursive Delete</caption>
* const opts = { recursive: true }
* cy.callFirestore('delete', 'project/test-project', opts)
* @example <caption>Other Args</caption>
* const opts = { args: ['-r'] }
* cy.callFirestore('delete', 'project/test-project', opts)
*/
callFirestore(action: string, actionPath: string, data?: any, opts?: any = {}): Chainable
}
}
So I'm not sure if this allow you to add them to the cy object since your a third-party library, but perhaps.
Also, when you say switching things around as I proposed, are you meaning to allow us to import things like this?
import cypressFirebasePlugin from "cypress-firebase/plugin"
and
import attachCustomCommands from "cypress-firebase/support"
from cypress-firebase.
That version is not currently released, but when it is, yes you will be able to check it out.
I started to try to do what you did above with the extending of the cy
object, but within the cypress-firebase instead of in the test code. Not sure if I was doing something wrong, but for some reason the cy object was not picking up on the custom commands. Maybe if I export then import it?
Yes, about the separate imports not from the top level, like you mention, but the imports would probably stick to the file associated with them instead of creating new paths (i.e. import cypressFirebasePlugin from 'cypress-firebase/lib/extendWithFirebaseConfig'
or import attachCustomCommands from cypress-firebase/lib/attachCustomCommands'
.
from cypress-firebase.
Sounds good. Keep in mind that for typescript to be able to import it, that you declare the module in index.d.ts like this:
declare module "lib/extendWithFirebaseConfig"
from cypress-firebase.
Got the custom commands types working with the declare global
. Added a typescript example where the custom commands were loading successfully, but for some reason I was getting this error:
Not totally sure about how to go about debugging it, but I noticed that when commenting everything out in the commands file, the tests ran again.
from cypress-firebase.
I'm not too sure either, but this looks familiar. I know its not the support/index, but for plugins, I had to make it a plugins/index.js file, not an index.ts file. Not sure if this is it
from cypress-firebase.
Actually, just realized that you have index.js for plugins. Nevermind.
from cypress-firebase.
However, in my code, I did this:
const cypressFirebasePlugin = require("../support/firebase/extendWithFirebaseConfig").extendWithFirebaseConfig
const webpack = require('@cypress/webpack-preprocessor')
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
const options = {
webpackOptions: require('../../webpack.config'),
}
on('file:preprocessor', webpack(options))
return cypressFirebasePlugin(config)
}
Notice that I'm returning cypressFirebasePlugin, but in your example, your not. Is this needed?
from cypress-firebase.
Potentially, I'll look into it later, thanks for posting. Feel free to make PRs against that branch if you think of other changes 😄
from cypress-firebase.
Got the example working so I went ahead and released v0.3.0-alpha to the next
tag. Going to test it a bit more with some of the applications I have with tests that use cypress-firebase.
Let me know if you get a chance to give it a shot 😄
from cypress-firebase.
Thanks for that! I downloaded that version, and it worked great on my end! In fact, it worked much nicer than my make-shift version :)
That being said, I have an error occuring. I will log it as a separate bug, though
from cypress-firebase.
v0.3.0 was released to latest
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.