prescottprue / cypress-firebase

Cypress plugin and custom commands for testing Firebase projects
MIT License
272 stars 50 forks source link

bug: cannot read properties of undefined (reading 'includes') #1072

Open AlanMendicutti opened 1 year ago

AlanMendicutti commented 1 year ago

The test is crashing and returning to the login page after showing this error message: "Cannot read properties of undefined (reading 'includes')"

This was working yesterday, and then all of the sudden today it started to show that error.

BTW the error only shows up in my Github Actions (CD/CD flow) during the cypress tests execution. Locally works like a charm.

My config: next13-pwa (0.1.0)

node (18.16.2)

cypress (^13.1.0) cypress-firebase (^2.2.5)

The test that fails:


import 'cypress-firebase';

describe('Prueba', () => {

  beforeEach(() => {
    // Intercept all network requests before each test
    cy.interceptAllRequests();
  });

  it('passes', () => {
    cy.login('dQbHJ62C6OgFyLlXBNLlu4ISjVG2');
    cy.visit('/');
    cy.contains('Postulaciones');
  })
})

My cypress.config.ts

import { defineConfig } from "cypress";
import admin from 'firebase-admin';
import { plugin as cypressFirebasePlugin } from 'cypress-firebase';

export default defineConfig({
  e2e: {
    baseUrl: 'http://localhost:3000',
    setupNodeEvents(on, config) {
      // implement node event listeners here
      cypressFirebasePlugin(on, config, admin);
    },
  },
});

The error message:

Dashboard -- Logged In -- sees basic admin options (failed)

Does anyone else is going through this? Thanks!

prescottprue commented 1 year ago

@AlanMendicutti make sure you are returning the plugin as per the setup documentation (your example only calls cypressFirebasePlugin but doesn't return it in setupNodeEvents:

    setupNodeEvents(on, config) {
      // implement node event listeners here
-    cypressFirebasePlugin(on, config, admin);
+    return cypressFirebasePlugin(on, config, admin);
    },

Did you also make sure to setup custom commands using attachCustomCommands:

cypress/support/e2e.js

import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
import 'firebase/firestore';
import { attachCustomCommands } from 'cypress-firebase';

const fbConfig = {
  // Your config from Firebase Console
};

firebase.initializeApp(fbConfig);

attachCustomCommands({ Cypress, cy, firebase });
AlanMendicutti commented 1 year ago

@prescottprue Yes this is me e2e.ts (btw i'm using Typescript)

import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
import 'firebase/compat/database';
import { attachCustomCommands } from 'cypress-firebase';

const fbConfig = {
    apiKey: "xxxx",
    authDomain: "xxxx",
    projectId: "xxxx",
    storageBucket: "xxxx",
    messagingSenderId: "xxx",
    appId: "xxxx",
};

firebase.initializeApp(fbConfig);
attachCustomCommands({ Cypress, cy, firebase });

The issue with typescript is that i can't add the return statement for the cypressFirebasePlugin Because i get this: Type '(on: PluginEvents, config: PluginConfigOptions) => ExtendedCypressConfig' is not assignable to type '(on: PluginEvents, config: PluginConfigOptions) => void | PluginConfigOptions | Promise<void | PluginConfigOptions>'.

But could that be related? Because locally works great. It's only in the github actions where I get that error.

prescottprue commented 1 year ago

@AlanMendicutti - is there a reason for the import of cypress-firebase within the test itself? That could cause issues

Is the rest of stack available in the error? I.e. showing what line is calling .includes?

AlanMendicutti commented 1 year ago

Not at all, I removed it and the same issue persists. I've tried to see the stack trace but without success.

I just realized that it gets that error if it has a cy.wait(n miliseconds); or cy.contains('anything'); So it's more probably related to a node versions compatibility, right @prescottprue ?

prescottprue commented 1 month ago

@AlanMendicutti Node 18 is still supported, so I'm not sure why it would be a node version compatibility issue

If you are able to provide a repo where this issue is able to be replicated I'm sure we can get to the bottom of it. I've tried a number of combinations, but haven't been able to replicate