LoginSignup
0
0

More than 1 year has passed since last update.

Firebase Cloud FunctionsのCronjobはfirebase-functions-testでテスト出来る

Posted at

以下のように、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({});

    // ...
  });
});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0