cypress-firebase: bug(callFirestore): calling callFirestore with an object does not work on Windows (only fixtures do)

I tried calling:

cy.callFirestore("update", "companies/my-id", { creditsRemaining: 1000 })

and

cy.callFirestore("set", "companies/my-id", { creditsRemaining: 1000 })

But receive this error:

Error: the string "(node:25288) UnhandledPromiseRejectionWarning: Error: Fixture not found at path: test\\e2e\\fixtures\\'{creditsRemaining:1000}' or cypress\\fixtures\\'{creditsRemaining:1000}'\n    at readFixture (C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\firebase-tools-extra\\lib\\commands\\firestore.js:26:19)\n    at C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\firebase-tools-extra\\lib\\commands\\firestore.js:96:39\n    at step (C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\tslib\\tslib.js:136:27)\n    at Object.next (C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\tslib\\tslib.js:117:57)\n    at C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\tslib\\tslib.js:110:75\n    at new Promise (<anonymous>)\n    at Object.__awaiter (C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\tslib\\tslib.js:106:16)\n    at firestoreAction (C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\firebase-tools-extra\\lib\\commands\\firestore.js:87:20)\n    at runFirebaseExtra (C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\firebase-tools-extra\\bin\\firebase-tools-extra:57:12)\n    at Object.<anonymous> (C:\\Users\\I20649\\Workspace\\testramp-ng8\\node_modules\\firebase-tools-extra\\bin\\firebase-tools-extra:66:2)\n(node:25288) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)\n(node:25288) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code." was thrown, throw an Error :)

Because this error occurred during a 'before all' hook we are skipping the remaining tests in the current suite: 'Client New Test Run Page'

It looks like it won’t allow an object like your documentation states:

cy.callFirestore('set', `testCollection/${TEST_UID}`, {
  name: 'axa',
  age: 8,
})

Versions: cypress-firebase: “0.4.1” cypress: “3.4.1” firebase-tools: “^7.8.0”

This seems like a bug.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 28 (27 by maintainers)

Commits related to this issue

Most upvoted comments

I have started work on a new method of doing things (through tasks instead of passing through the firebase-tools-extra cli). This should help fix things, but it is definetly a work in progress

To try it out do the following:

  1. Install from alpha and install firebase-admin npm i --save-dev cypress-firebase@alpha firebase-admin (currently at 0.11.0-alpha.2)
  2. Switch your plugin import to be pluginWithTasks like so:
- const cypressFirebasePlugin = require('cypress-firebase').plugin
+ const cypressFirebasePlugin = require('cypress-firebase').pluginWithTasks
  1. Pass the new arguments to the new plugin:
+ const admin = require('firebase-admin')
const cypressFirebasePlugin = require('cypress-firebase').pluginWithTasks

module.exports = (on, config) => {
+  return cypressFirebasePlugin(on, config, admin)
-  return cypressFirebasePlugin(config)
}

Full example

const admin = require('firebase-admin')
const cypressFirebasePlugin = require('cypress-firebase').pluginWithTasks

module.exports = (on, config) => {
// Pass on function, config, and admin instance. Returns extended config
  return cypressFirebasePlugin(on, config, admin)
}

I have a temporary workaround. Basically we save the object and then use that as a fixture. It works for our use case and we have used over 50 e2e tests with it. Obviously its not ideal, but it works for now.

import { isObject } from "lodash"
import * as uuid from "uuid/v4"

Cypress.Commands.overwrite("callFirestore", (originalFn: any, type: string, path: any, fixtureOrData: string | any, ...args) => {
  let id = ""
  if (isObject(fixtureOrData)) {
    id = (fixtureOrData as any)._id
    if (!id) {
      id = "Automation-" + uuid()
    }

    const fixturePath = "test-fixtures/" + id + ".json"
    return cy
      .writeFile("cypress/fixtures/" + fixturePath, fixtureOrData, "utf-8")
      .then(() => {
        fixtureOrData = fixturePath
        return originalFn(type, path, fixtureOrData, ...args)
      })
  }

  return originalFn(type, path, fixtureOrData, ...args)
})

@prescottprue Okay, so I tried this same command on my MAC, and it works just fine. This is a Windows-specific bug.

Actually, looks like the error is displayed here. https://github.com/prescottprue/firebase-tools-extra/blob/master/src/commands/firestore.ts I’m trying to look into this bug, because my workaround is really making a lot of code. (writing a file everytime I need to update an object in firestore.