5
votes

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

3 Answers

3
votes

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() {
    ...
}
0
votes

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');
}
0
votes
> 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.