以下のように、CronJob形式で書いたFirebase Functionsがあった時、
export const scheduledFunction = functions.pubsub
.schedule('every 24 hours')
.onRun(
(context: functions.EventContext) => {
...
});
最初どうやって関数の内容に関する単体テストを書いたものかと迷いました。
結局、firebase-functions-test
が使えて、他の関数と同じようにwrapして呼び出せば良いようです。
import firebaseFunctionsTest from 'firebase-functions-test';
import { describe, it } from 'mocha';
// sut includes scheduledFunction.
import * as sut from '../src/index';
const test = firebaseFunctionsTest(
// your settings...
);
// ...
describe('test', () => {
it('scheduledFunction', async () => {
const wrapped = test.wrap(sut.scheduledFunction);
await wrapped({});
// ...
});
});