Git Product home page Git Product logo

Comments (15)

prescottprue avatar prescottprue commented on June 3, 2024 2

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.

prescottprue avatar prescottprue commented on June 3, 2024 1

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.

danielmhair avatar danielmhair commented on June 3, 2024

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.

prescottprue avatar prescottprue commented on June 3, 2024

@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.

dhair-seva avatar dhair-seva commented on June 3, 2024

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.

prescottprue avatar prescottprue commented on June 3, 2024

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.

dhair-seva avatar dhair-seva commented on June 3, 2024

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.

prescottprue avatar prescottprue commented on June 3, 2024

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:

image

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.

dhair-seva avatar dhair-seva commented on June 3, 2024

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.

dhair-seva avatar dhair-seva commented on June 3, 2024

Actually, just realized that you have index.js for plugins. Nevermind.

from cypress-firebase.

dhair-seva avatar dhair-seva commented on June 3, 2024

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.

prescottprue avatar prescottprue commented on June 3, 2024

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.

prescottprue avatar prescottprue commented on June 3, 2024

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.

dhair-seva avatar dhair-seva commented on June 3, 2024

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.

prescottprue avatar prescottprue commented on June 3, 2024

v0.3.0 was released to latest

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.