Issue encountered while trying to import firebase-functions-test for testing using mocha

I've been attempting to configure a Firebase Cloud Functions repository for running mocha tests. However, I keep encountering an error when utilizing

import * as firebase from "firebase-functions-test";
or
const firebase = require("firebase-functions-test")();
. Even though I haven't executed the actual Firebase functions in my code yet, it seems like there might be a setup issue.

Inquiry: What modification should I make to enable mocha testing for Firebase Functions using import syntax?

Successful test code

import { assert } from "chai";
describe("Sanity Check", () => {
  it("should pass", () => {
    assert.equal(0, 0);
  });
});

Failed Test Code utilizing require

const test = require("firebase-functions-test")();
import { assert } from "chai";
describe("Sanity Check", () => {
  it("should pass", () => {
    assert.equal(0, 0);
    test.cleanup();
  });
});

Failed code utilizing import

import * as firebase from "firebase-functions-test";
import { assert } from "chai";

const test = firebase();
describe("Sanity Check", () => {
  it("should pass", () => {
    assert.equal(0, 0);
    test.cleanup();
  });
});

Error message for the failure

> functions@ test /Users/cupidchan/temp/functions
> mocha -r ts-node/register test/**/*.spec.ts

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/encoder' is not defined by "exports" in /Users/cupidchan/temp/functions/node_modules/firebase-functions/package.json
    at new NodeError (internal/errors.js:322:7)
    ...
    ...

package.json

{
  "name": "functions",
  "scripts": {
    ...
    ...
  },
  "engines": {
    "node": "14"
  },
  "main": "lib/index.js",
  "dependencies": {
    ...
    ...
  },
  "devDependencies": {
    ...
    ...
  },
  "private": true
}

tsconfig.json

{
  "compilerOptions": {
    ...
    ...
  },
  "compileOnSave": true,
  "include": ["src", "test"]
}

Answer №1

To fix this issue, make sure to specify the most recent versions of the following:

  • firebase-functions, v3.16.0, and

  • firebase-functions-test, v0.3.3.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is the use of 'use client' always necessary in order to utilize a hook in Next.js?

Is it necessary to include 'use client' in every page that uses useSelector when working with Redux in Next.js? If I don't include 'use client', I encounter this error: - error node_modules\react-redux\lib\component ...

Console shows successful jQuery ajax request, but the callback function is not being executed

I've been working on a jQuery POST request that's been giving me some trouble. Here is a snippet of the code I'm using: $.ajax("/myurl",{ data:{ ... }, mimeType:"application/json", dataType:"application/json", me ...

Adjusting the location of circles generated by d3 using a time interval

As a newbie to d3 and JavaScript, I'm facing an error that is beyond my current knowledge. I have successfully generated 6 circles using a 2D array and implemented a function to increment their x and y positions by 1 in each call of a timer. However, ...

Ways to sign up for the activeDate variable in MatCalendar so you can display the month and year labels of the current active date in the

As a newcomer to Angular, I am working on creating a datepicker with a customized header. I have successfully passed a custom header for the mat-calendar component. Reference: https://material.angular.io/components/datepicker/overview#customizing-the-calen ...

Implementing an Ajax call within a loop

When trying to fetch data from a website using certain codes, I end up with a list of 330 categories. According to the WooCommerce REST API documentation, this endpoint typically only returns the first 100 categories. In order to get all the categories, ...

Error: The StsConfigLoader provider is not found! MSAL angular

I am currently using Auth0 to manage users in my Angular application, but I want to switch to Azure Identity by utilizing @azure/msal-angular. To make this change, I removed the AuthModule from my app.module and replaced it with MsalModule. However, I enco ...

In configuring the print settings, I specified margins to ensure proper formatting. However, I noticed that the margin adjustment only applies to the first page. I need

I have a method that retrieves margin top value from the backend. It works perfectly on the first page of print, but on the second page, the margin top space is missing. initializePrintingSettings() { this.printService.fetchPrintSettings().subscribe(respon ...

Deciphering Google location data using JavaScript

It appears that this code is not functioning properly for unknown reasons let url = "https://maps.googleapis.com/maps/api/place/search/json?"; url += "location="+lat+","+lng+"&"; url += "radius=500&"; url += "types=&"; url += "name=&"; url ...

Passing props from Vue3 to a component being rendered through RouterView

I'm facing an issue with the following code snippet: <template> <router-view /> </template> <script setup lang="ts"> ... const product: Ref<IProduct|undefined>: ref(); ... </script> The challenge is ...

What is the proper way to invoke the function located within a jQuery plugin?

I have incorporated a jquery plugin called vTicker on my webpage for automatic vertical news scrolling. This plugin, available from this link, works seamlessly with an rss jquery plugin. The integration is successful, but I now have a requirement to add a ...

Use javascript/ajax to create a dynamic dropdown menu

I have successfully retrieved data from an ajax and JSON request on another php page. Using json parse, I was able to extract two array strings. JAVASCRIPT: if (xmlhttp.readyState==4 && xmlhttp.status==20 { var data = JSON.parse(xmlhttp.respon ...

Create a collection of SVG illustrations using Vivus.js

Is it possible to draw multiple SVGs using Vivus.js without having to call the function for each individual drawing? I've encountered an issue with the second drawing not animating properly. Any suggestions or experience with this? Check out this pen ...

Can anyone provide a method for obtaining a date that is x days earlier through date arithmetic?

Is there a method to obtain the date from 63 days ago with only day, month, and year information needed, excluding hours, minutes, and seconds? I am aware that one can calculate Date object - Date object, but I am curious if it is feasible to derive a dat ...

Verify if there are any duplicate values in the dropdown menu

I am currently working on a code that adds items to a select list, and it is functioning properly. However, I am facing a challenge in comparing values to prevent duplicates. I know how to compare values, but I am struggling with checking for values that h ...

Typescript raises an issue regarding a React component's optional prop potentially being undefined

I have a basic React component that looks like this: interface ComponentProperties { onClick?: () => void; } const CustomComponent = (properties: ComponentProperties) => { if (!properties.onClick) { return <></>; } ...

Adjusting the orientation of a vector worldwide using a quaternion in THREE.js

Is there a way to set the absolute global rotation of a vector using a quaternion? Imagine a function called f(v, q) which rotates vector v to quaternion q. While THREE.Vector3 has a .applyQuaternion function for applying rotations to vectors, this is a ...

jQuery menu animation not triggering until second click

I am currently working on implementing a menu that will slide in after clicking the hamburger button (located in the upper right corner). Instead of simply appearing, I wanted to use a jQuery function for a smoother sliding effect. However, I seem to be e ...

Unable to access HTTP response headers during Ext.ajax.request callback in ExtJS 4.2.1

When making an Ext.ajax.request, I am attempting to read the headers of the response that is coming. Here is the code snippet: Ext.Ajax.request({ url: 'http://localhost:3000/v0.1/login' , method: 'POST', scope:this, jsonDat ...

Tips for creating a cohesive group of HTML elements within an editable area

Imagine having a contenteditable area with some existing content: <div contenteditable="true"> <p>first paragraph</p> <p> <img width='63' src='https://developer.cdn.mozilla.net/media/img/mdn-logo-s ...

How can I automatically close the menu when I click on a link in Vue?

Tap the menu icon Select a link The URL changes in the background. However, the menu remains open. How do I close the menu when a link is selected? The menu is wrapped in a details HTML element. Is there a way to remove the "open" attribute from the detai ...