Skip to content

Commit 5e08c42

Browse files
authored
Fix integration tests (#1198)
Integration test caught some bugs! 1. From #1155 - Some internal type must be exposed - otherwise compiling user projects fails w/ error message like below: ``` Error: node_modules/firebase-functions/lib/common/params.d.ts(10,13): error TS2314: Generic type 'Extract' requires 2 type argument(s). Error: node_modules/firebase-functions/lib/common/params.d.ts(10,21): error TS2304: Cannot find name 'Split'. Error: node_modules/firebase-functions/lib/common/params.d.ts(10,27): error TS2304: Cannot find name 'NullSafe'. ``` 2. From #1181 - There is no way to call private callable functions since GCF requrie GCP identity token as authorization header while callable function requires Firebase auth tokens. Disabling those test cases in the integration test until we can mint a GCP project w/ permission to create public functions.
1 parent c303eab commit 5e08c42

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

integration_test/functions/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import * as testLab from "./v1/testLab-utils";
2020
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
2121
admin.initializeApp();
2222

23+
// Re-enable no-unused-var check once callable functions are testable again.
24+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2325
async function callHttpsTrigger(name: string, data: any) {
2426
const url = `https://${REGION}-${firebaseConfig.projectId}.cloudfunctions.net/${name}`;
2527
const client = await new GoogleAuth().getIdTokenClient("32555940559.apps.googleusercontent.com");
@@ -36,6 +38,8 @@ async function callHttpsTrigger(name: string, data: any) {
3638
}
3739
}
3840

41+
// Re-enable no-unused-var check once callable functions are testable again.
42+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3943
async function callV2HttpsTrigger(name: string, data: any, accessToken: string) {
4044
const getFnResp = await fetch(
4145
`https://cloudfunctions.googleapis.com/v2beta/projects/${firebaseConfig.projectId}/locations/${REGION}/functions/${name}`,
@@ -127,7 +131,8 @@ function v1Tests(testId: string, accessToken: string): Array<Promise<unknown>> {
127131
// A firestore write to trigger the Cloud Firestore tests.
128132
admin.firestore().collection("tests").doc(testId).set({ test: testId }),
129133
// Invoke a callable HTTPS trigger.
130-
callHttpsTrigger("v1-callableTests", { foo: "bar", testId }),
134+
// TODO: Temporarily disable - doesn't work unless running on projects w/ permission to create public functions.
135+
// callHttpsTrigger("v1-callableTests", { foo: "bar", testId }),
131136
// A Remote Config update to trigger the Remote Config tests.
132137
updateRemoteConfig(testId, accessToken),
133138
// A storage upload to trigger the Storage tests
@@ -141,10 +146,12 @@ function v1Tests(testId: string, accessToken: string): Array<Promise<unknown>> {
141146
];
142147
}
143148

149+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
144150
function v2Tests(testId: string, accessToken: string): Array<Promise<void>> {
145151
return [
146152
// Invoke a callable HTTPS trigger.
147-
callV2HttpsTrigger("v2-callabletests", { foo: "bar", testId }, accessToken),
153+
// TODO: Temporarily disable - doesn't work unless running on projects w/ permission to create public functions.
154+
// callV2HttpsTrigger("v2-callabletests", { foo: "bar", testId }, accessToken),
148155
];
149156
}
150157

integration_test/functions/src/v1/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export * from "./pubsub-tests";
22
export * from "./database-tests";
33
export * from "./auth-tests";
44
export * from "./firestore-tests";
5-
export * from "./https-tests";
5+
// Temporarily disable http test - will not work unless running on projects w/ permission to create public functions.
6+
// export * from "./https-tests";
67
export * from "./remoteConfig-tests";
78
export * from "./storage-tests";
89
export * from "./testLab-tests";

integration_test/functions/src/v2/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import { setGlobalOptions } from "firebase-functions/v2";
22
import { REGION } from "../region";
33
setGlobalOptions({ region: REGION });
44

5-
export * from "./https-tests";
5+
// TODO: Temporarily disable - doesn't work unless running on projects w/ permission to create public functions.
6+
// export * from "./https-tests";

src/common/params.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
/** @internal */
23+
/**
24+
* A type that splits literal string S with delimiter D.
25+
*
26+
* For example Split<"a/b/c", "/"> is ['a' | "b" | "c"]
27+
*/
2428
export type Split<S extends string, D extends string> =
2529
// A non-literal string splits into a string[]
2630
string extends S
@@ -36,7 +40,9 @@ export type Split<S extends string, D extends string> =
3640
: // A string without delimiters splits into an array of itself
3741
[S];
3842

39-
/** @internal */
43+
/**
44+
* A type that ensure that type S is not null or undefined.
45+
*/
4046
export type NullSafe<S extends null | undefined | string> = S extends null
4147
? never
4248
: S extends undefined
@@ -45,7 +51,14 @@ export type NullSafe<S extends null | undefined | string> = S extends null
4551
? S
4652
: never;
4753

48-
/** @internal */
54+
/**
55+
* A type that extracts parameter name enclosed in bracket as string.
56+
* Ignore wildcard matches
57+
*
58+
* For example, Extract<"{uid}"> is "uid".
59+
* For example, Extract<"{uid=*}"> is "uid".
60+
* For example, Extract<"{uid=**}"> is "uid".
61+
*/
4962
export type Extract<Part extends string> = Part extends `{${infer Param}=**}`
5063
? Param
5164
: Part extends `{${infer Param}=*}`

0 commit comments

Comments
 (0)