9

I have written a scheduled function like described here: https://firebase.google.com/docs/functions/schedule-functions

How can I test this function now? When I wrap this function (as I would with any other cloud function), there is an error that says: "Property 'wrap' does not exist on type 'TestFunction'."

const functionWrapper = test.wrap(function);

Is there any other way to test these functions?

3 Answers 3

8

One workaround I found is isolating my code in a function and calling that function from the scheduled function. When I test, instead of calling the scheduled function, I call the isolated function directly.

Ex:

export const dailyJob = functions.pubsub
        .schedule('0 0 * * *')
        .onRun(async context => {
    return isolatedFunction();
})

export function isolatedFunction() {
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

3
> firebase functions:shell  
> firebase> RUN_NAME_OF_THE_FUCTION()

Not sure since when - but this is my way of handling the scheduler function. The problem I have is I do not have a context nor I do not know how to pass params to these functions.

WIP but at least I can easily manually run it on my local env.

Comments

-1

You can write like this

exports.scheduledFunction = () => functions.pubsub.schedule('every 1 minutes').onRun((context) => {
    console.log('Start scheduledFunction every 1 minutes');
    sendEmail();
    return null;
});


async function sendEmail() {
    console.log('Start sendEmail');
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.