Skip to content

fix(wrap): Extensions functions.handler -> eventType key exists but is undefined value #49

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 5 commits into from
Nov 4, 2019
Merged

fix(wrap): Extensions functions.handler -> eventType key exists but is undefined value #49

merged 5 commits into from
Nov 4, 2019

Conversation

Salakar
Copy link
Member

@Salakar Salakar commented Oct 23, 2019

Description

I've been working on adding tests to firebase/extensions and when trying to wrap the function handlers used by Extensions (e.g. functions.handler.firestore.document.onWrite) it errors with TypeError: Cannot read property 'match' of undefined as the eventType key 'does' exist on the defaultContext object, but has an undefined value assigned.

This small PR adds an additional undefined check.

export const fstranslate = functions.handler.firestore.document.onWrite(
  async (change): Promise<void> => {
  console.warn('Hello from inside my wrapped handler function.');
  return;
});

// ...
import * as functionsTestInit from "firebase-functions-test";
// ...
let functionsTest = functionsTestInit();
// ...


const wrappedFn = functionsTest.wrap(exportedFns.fstranslate);
const before = functionsTest.firestore.makeDocumentSnapshot({}, "foo/id1");
const after = functionsTest.firestore.makeDocumentSnapshot({ input: "hello" }, "foo/id1");
const change = functionsTest.makeChange(before, after);

wrappedFn(change); // Errors

Before:
image

After:
image

Code sample

N/A


cc @laurenzlong @karayu

On Firebase Extensions when wrapping an exported Firestore onWrite fn it errors with `Cannot read property 'match' of undefined`.
Copy link
Contributor

@laurenzlong laurenzlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! there seems to be some TS errors

node_modules/@types/chai/index.d.ts:121:9 - error TS8020: JSDoc types can only be used inside documentation comments.
121         any?, // actual value
            ~~~~
node_modules/@types/chai/index.d.ts:122:9 - error TS8020: JSDoc types can only be used inside documentation comments.
122         boolean? // showDiff
            ~~~~~~~~
node_modules/@types/chai/index.d.ts:126:16 - error TS2370: A rest parameter must be of an array type.
126         assert(...args: AssertionArgs): void;
                   ~~~~~~~~~~~~~~~~~~~~~~

@Salakar
Copy link
Member Author

Salakar commented Oct 23, 2019

Thanks for the fix! there seems to be some TS errors

These are on master too - but I'll look into it, thanks!

Looks like theres a breaking change in a minor release of the chai types.
Node.js 6 is no longer supported by the newer `firebase-functions` versions as it uses `async/await` which is only supported in version 8+
@Salakar
Copy link
Member Author

Salakar commented Oct 23, 2019

@laurenzlong fixed the types issue that was on master - breaking change in the chai types that was non semver, I've switched the version in package.json to use approximate versioning.

Came across another issue after though with the dev dependencies; the firebase-admin SDK was quite far out of date that the native GRPC dep wouldn't compile on the latest stable Node.js version - so I updated to the latest firebase-admin & firebase-functions versions. This broke the types as typescript was too old, updated typescript to fix, that broke mocha types as too old, and so on 😅 - so I've just updated all of the dev dependencies and all is working well now.

I also had to remove Node.js v6 testing from travis - newer firebase-functions versions uses async/await which isn't available on v6. Also the functions runtimes now are only v8 & v10 so have updated travis to reflect.

Hope these additional changes to get CI working again are ok?

Copy link
Contributor

@laurenzlong laurenzlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my delayed review! This looks awesome! Thanks for fixing so many things!

@laurenzlong laurenzlong merged commit c0c144f into firebase:master Nov 4, 2019
@laurenzlong
Copy link
Contributor

@Salakar This has now been released in v0.1.7

@Salakar
Copy link
Member Author

Salakar commented Nov 5, 2019

@laurenzlong Thank you 🎉

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.

2 participants