Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting Param classes to allow their import from firebase-functions/params #1455

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cborac
Copy link

@cborac cborac commented Aug 14, 2023

Description

Exported Param classes: BooleanParam, FloatParam, IntParam, SecretParam, StringParam, and ListParam.

Upon creating stubs using various tools to test my cloud functions which use firebase-functions, I faced an issue where I could not mock defineSecret as it was called too early. I could stub it before importing the function file, but it would impair the coding conventions, and cause more effort.

As a result, I tried to import SecretParam and tried to stub its prototype. Upon running, I had an error Package subpath './lib/params/types' is not defined by "exports" which is reasonable as it is not exported by default and rather used as a local class.

Despite presumably being a DX choice (to avoid wrongfully creating params), it causes trouble and limits the users' ability to interact with the library.

This PR doesn't break any existing code.

Code sample

Here's an example in TypeScript of creating a stub with the sinon library

import { params } from "firebase-functions";
import * as sinon from "sinon";

const fakeSecrets = {
     "secret1":  "secr3t.value"
};

sinon.stub(params.SecretParam.prototype, "value").callsFake(function (this: params.SecretParam) {
     return fakeSecrets[this.name];
});


const secret = defineSecret("secret1");
console.log(secret.value());   // "secr3t.value"

@cborac
Copy link
Author

cborac commented Aug 14, 2023

Also, to avoid confusion, the example I have given can be replaced by setting the proper process.env. However, the issue still persists in other circumstances.

https://github.com/firebase/firebase-functions/blob/a70663b0c6d2da08b665951686ef5bc35ebc0167/src/params/types.ts#L381C17-L381C24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant