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

TypeError: Cannot read property 'storageBucket' of null #77

Closed
Ridermansb opened this issue Oct 4, 2020 · 1 comment
Closed

TypeError: Cannot read property 'storageBucket' of null #77

Ridermansb opened this issue Oct 4, 2020 · 1 comment

Comments

@Ridermansb
Copy link

I'm trying to create test for storage but.. TypeError: Cannot read property 'storageBucket' of null is throw

Version info

"firebase-admin": "^9.1.1".
"firebase-functions": "^3.11.0"
"firebase-functions-test": "^0.2.2"

Test case

Creating new trigger for storage onFinalize and try to test it

Steps to reproduce

Create trigger function that will be trigger on onFinalize

processMenuImages: functions
    .runWith(runtimeStorageOpts)
    .storage.object()
    .onFinalize(processMenuImages),

The processMenuImages function it's just function..

const processMenuImages = async (object) => { .. code.. }

And try to test...

const functionsTest = require('firebase-functions-test')(
    FIREBASE_CONFIG,
    process.env.GOOGLE_APPLICATION_CREDENTIALS
);

describe('firebase triggers', function () {
    let firebaseFunctions;
    beforeEach(() => {
        firebaseFunctions = require('.');
    });
    afterEach(() => {
        functionsTest.cleanup();
    });

    test('should be able to call the function', () => {
        const storageData = functionsTest.storage.makeObjectMetadata({
            name: 'unit_tests/Amaze.png',
            contentType: 'image/png',
        });
        const wrapped = functionsTest.wrap(
            firebaseFunctions.processMenuImages
        );
        return wrapped(storageData);
    });
});

Actual behavior

Once I start the test, I received this...

    TypeError: Cannot read property 'storageBucket' of null

      42 |             contentType: 'image/png',
      43 |         });
    > 44 |         const wrapped = functionsTest.wrap(
         |                                       ^
      45 |             firebaseFunctions.processMenuImages
      46 |         );
      47 |         return wrapped(storageData);

      at resourceGetter (functions/node_modules/firebase-functions/lib/providers/storage.js:56:53)
      at Function.get (functions/node_modules/firebase-functions/lib/cloud-functions.js:151:17)
      at hasPath (functions/node_modules/lodash/lodash.js:6153:24)
      at Function.has (functions/node_modules/lodash/lodash.js:13185:32)
      at Object.wrap (functions/node_modules/firebase-functions-test/lib/main.js:29:19)
      at Suite._context4 (functions/firebase-triggers.test.js:44:39)

Expected behavior

Should all test working..

@inlined
Copy link
Member

inlined commented Aug 30, 2021

You need to either pass a bucket explicitly, e.g.

processMenuImages: functions
    .runWith(runtimeStorageOpts)
    .storage.bucket("SOME_BUCKET").object()
    .onFinalize(processMenuImages),

or you need to set the FIREBASE_CONFIG environment variable, which includes a default bucket name.

@inlined inlined closed this as completed Aug 30, 2021
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

No branches or pull requests

2 participants