From 97049ffe235e57e0f54f7610df065048cfb52a98 Mon Sep 17 00:00:00 2001 From: Nikita Galkin Date: Sat, 26 Nov 2022 11:02:56 -0400 Subject: [PATCH] Improve typing --- src/features.ts | 3 ++- src/index.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/features.ts b/src/features.ts index ae2c470..72616f8 100644 --- a/src/features.ts +++ b/src/features.ts @@ -5,6 +5,7 @@ import * as database from './providers/database'; import * as firestore from './providers/firestore'; import * as pubsub from './providers/pubsub'; import * as storage from './providers/storage'; +import { FirebaseFunctionsTest } from './lifecycle'; export interface LazyFeatures { mockConfig: typeof mockConfig; @@ -31,5 +32,5 @@ export const features: LazyFeatures = { }; export interface FeaturesList extends LazyFeatures { - cleanup; + cleanup: InstanceType['cleanup']; } diff --git a/src/index.ts b/src/index.ts index b049e11..3d1f8e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,16 +24,19 @@ import { AppOptions } from 'firebase-admin'; import { merge } from 'lodash'; import { FirebaseFunctionsTest } from './lifecycle'; -import { features as lazyFeatures, FeaturesList } from './features'; +import { FeaturesList } from './features'; -export = (firebaseConfig?: AppOptions, pathToServiceAccountKey?: string) => { +export = ( + firebaseConfig?: AppOptions, + pathToServiceAccountKey?: string +): FeaturesList => { const test = new FirebaseFunctionsTest(); test.init(firebaseConfig, pathToServiceAccountKey); // Ensure other files get loaded after init function, since they load `firebase-functions` // which will issue warning if process.env.FIREBASE_CONFIG is not yet set. - let features = require('./features').features as typeof lazyFeatures; + let features = require('./features').features; features = merge({}, features, { cleanup: () => test.cleanup(), }); - return features as FeaturesList; + return features; };