Skip to content

Improve cleanup type definition #185

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

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,5 +32,5 @@ export const features: LazyFeatures = {
};

export interface FeaturesList extends LazyFeatures {
cleanup;
cleanup: InstanceType<typeof FirebaseFunctionsTest>['cleanup'];
}
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};