mesqueeb / vuex-easy-firestore

Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!
https://mesqueeb.github.io/vuex-easy-firestore
MIT License
234 stars 28 forks source link

E2E test with Cypress #390

Open yuucha opened 2 years ago

yuucha commented 2 years ago

The following settings are required in Store to enable access to the emulator, When E2E test with Cypress.

Firebase.firestore().settings({ experimentalForceLongPolling: true }); When performing E2E testing in Cypress, there seems to be a limited number of places to describe.

I thought I could just refer to the setup documentation and describe the settings, but "experimentalForceLongPolling" is not enabled.

In case it is not enabled

if (process.env.NODE_ENV != "production") {
    // NOTE: do NOT put this in production.
    // Cloud Functions is able
    Firebase.firestore().settings({ experimentalForceLongPolling: true });
    Firebase.auth().useEmulator("http://localhost:9099/");
    Firebase.storage().useEmulator('localhost', 9199);
    Firebase.firestore().useEmulator('localhost', 8081);
    Firebase.functions().useEmulator("localhost", 5001);
  }

This description gives a firebase permission error in Cypress.

FirebaseError
The following error originated from your application code, not from Cypress. It was caused by an unhandled promise rejection.

  > Missing or insufficient permissions.

Cypress is worked in the production envroiment. if you see the parameter of process.env.NODE_ENV, it works in production.

Therefore, create the .env under the root and write it. VUE_APP_EMULATE=true

If enabled

if (process.env.VUE_APP_EMULATE) {
    Firebase.firestore().settings({ experimentalForceLongPolling: true })
    Firebase.auth().useEmulator("http://localhost:9099/");
    Firebase.storage().useEmulator('localhost', 9199);
    Firebase.firestore().useEmulator('localhost', 8081);
    Firebase.functions().useEmulator("localhost", 5001);
  }

This method solves the problem and I have no problem with it, but if anyone else is having trouble, please refer to this.