cypress-firebase icon indicating copy to clipboard operation
cypress-firebase copied to clipboard

cypress v10 migration

Open satishchilkaka opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe.

Recently cypress upgraded to version 10, For some reasons plugin.{ts.js} is deprecated, cypress does not recommending to use plugin files.

Describe the solution you'd like

Cypress introduced a setupNodeEvents function, would like to see cypress-firebase plugin work with setupNodeEvents

Describe alternatives you've considered

Additional context

Trying to migrating cypress-firebase plugin to using this format, not able to read the firebase config, However able to initialize the firebase config in console

 setupNodeEvents(on, config) {
      // bind to the event we care about
      on('<event>', (arg1, arg2) => {
        // plugin stuff here
      })
    }

satishchilkaka avatar Jun 06 '22 22:06 satishchilkaka

@Satishchilkaka Thanks for reporting and including an example! I'll start looking into the change

prescottprue avatar Jun 13 '22 19:06 prescottprue

@Satishchilkaka Thanks for reporting and including an example! I'll start looking into the change

That sounds great! I think it would also help with using cypress-firebase in component testing as right now running, for example, cy.login() yields the following error:

cy.task('createCustomToken') failed with the following error:

The 'task' event has not been registered in the setupNodeEvents method. You must register it before using cy.task()

Fix this in your setupNodeEvents method here:
/Users/andershansen/Documents/Code/sim-project-manager-app/cypress.config.ts

This is with a setup where the component test is outside of the cypress folder. Just a heads up that this might be related.

andershoegh2 avatar Jun 14 '22 19:06 andershoegh2

Thanks for posting @andershoegh2 - haven't tried in component testing yet, but I will take a look

@Satishchilkaka I got v10 of Cypress working in the basic example working with the current version of cypress-firebase in this PR by adding the following to cypress.config.js:

const { defineConfig } = require('cypress')
const tasks = require('cypress-firebase/lib/tasks')
const cypressFirebasePlugin = require('cypress-firebase').plugin
const admin = require('firebase-admin')

module.exports = defineConfig({
  e2e: {
    baseUrl: 'http://localhost:3000',
    supportFile: 'cypress/support/e2e/index.js',
    setupNodeEvents(on, config) {
      cypressFirebasePlugin(on, config, admin)
    },
  },
})

I'm currently updating the docs to cover this with the current version, but I'm sure there will be other improvements that can be made to the interface of cypress-firebase (that may be breaking) to work well with Cypress v10

prescottprue avatar Jun 15 '22 19:06 prescottprue

Thanks for posting @andershoegh2 - haven't tried in component testing yet, but I will take a look

@Satishchilkaka I got v10 of Cypress working in the basic example working with the current version of cypress-firebase in this PR by adding the following to cypress.config.js:

const { defineConfig } = require('cypress')
const tasks = require('cypress-firebase/lib/tasks')
const cypressFirebasePlugin = require('cypress-firebase').plugin
const admin = require('firebase-admin')

module.exports = defineConfig({
  e2e: {
    baseUrl: 'http://localhost:3000',
    supportFile: 'cypress/support/e2e/index.js',
    setupNodeEvents(on, config) {
      cypressFirebasePlugin(on, config, admin)
    },
  },
})

I'm currently updating the docs to cover this with the current version, but I'm sure there will be other improvements that can be made to the interface of cypress-firebase (that may be breaking) to work well with Cypress v10

Thanks for the quick update @prescottprue, this looks awesome. When I was experimenting with cypress v10 I used the same approach

setupNodeEvents(on, config) {
      cypressFirebasePlugin(on, config, admin)
    }

This looks cool and simple. waiting to merge and update the latest version.

satishchilkaka avatar Jun 15 '22 20:06 satishchilkaka

@prescottprue we've been playing around with component testing and we've got commands working. However, we've stumbled into an issue with onAuthStateChanged.

Our app depends on the onAuthStateChanged setting the user. When using cy.login() in a component test we get null and thus the app can't get past our login screen when we test components that depend on authentication and user role functionality. With no difference in the setup we can run E2E without a problem. The only thing I can think of is that in E2E we run the cy.visit command after cy.login, which we do not in component tests. Maybe that's the reason that onAuthStateChanged never runs and yields a user object?

Looking forward to being able to use cypress-firebase for component testing as well! It's an integral part of our testing efforts. Great work on this libary @prescottprue :-)

andershoegh avatar Jun 23 '22 15:06 andershoegh

@prescottprue we've been playing around with component testing and we've got commands working. However, we've stumbled into an issue with onAuthStateChanged.

Our app depends on the onAuthStateChanged setting the user. When using cy.login() in a component test we get null and thus the app can't get past our login screen when we test components that depend on authentication and user role functionality. With no difference in the setup we can run E2E without a problem. The only thing I can think of is that in E2E we run the cy.visit command after cy.login, which we do not in component tests. Maybe that's the reason that onAuthStateChanged never runs and yields a user object?

Looking forward to being able to use cypress-firebase for component testing as well! It's an integral part of our testing efforts. Great work on this libary @prescottprue :-)

We have the exact same issue. Any workarounds?

shihananuruddha avatar Jun 29 '22 06:06 shihananuruddha

Since this was originally about cypress 10 which examples are updated for, I opened this new issue to track component testing support https://github.com/prescottprue/cypress-firebase/issues/742

Thanks for reporting @andershoegh and @shihananuruddha

prescottprue avatar Dec 30 '22 17:12 prescottprue