Skip to content

Conversation

@alexandercerutti
Copy link

@alexandercerutti alexandercerutti commented Oct 31, 2025

Description

Fixes #210

I've added the tests to check if the things are working correctly and all the tests run perfectly. Same as linting.

The only catch, with the current changes, are that in order to test a scheduled function, since Firebase sets the provided handler to onSchedule as the run function, the function that is provided inside onSchedule must have at least one parameter, even if unused. This is not a thing that I really like, but we'd need to change how onSchedule actually works - and I'm not here for this.

Another thing is that I had to change the implementation of isV2CloudFunction and remove one of the conditions. I don't like this either, but the tests are ending correctly.

Imho, in order to detect the correct type of function, wrapV2 module should expose the assertIsCloudFunctionV2 and we should use it... or convert the package to not have a middle switch point between v1 and v2 but have two exports, one for v1 and one for v2.

Let me know how does this feel.
Thank you!

import { onSchedule } from "firebase-functions/v2/scheduler";

const myScheduledFn = onSchedule("every 5 minutes", (_e) => {});

// ... in the tests ...

import firebaseFunctionsTest from 'firebase-functions-test';
const { wrap } = firebaseFunctionsTest();

const wrappedScheduled = wrap(myScheduledFn);

await wrappedScheduled({
  jobName: "test-job",
  scheduleTime: "2025-10-31T00:00:00Z"
})

Copilot AI review requested due to automatic review settings October 31, 2025 17:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for wrapping Firebase V2 scheduled functions (ScheduleFunction) in the test wrapper library. It extends the existing wrapping functionality to handle scheduler.onSchedule() functions alongside the already-supported CloudFunction and CallableFunction types.

Key changes:

  • Added ScheduleFunction support with type guards and wrapper implementation
  • Added input validation for scheduled event options
  • Enhanced null checking for cloud functions before wrapping

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/v2.ts Added ScheduleFunction type support with type guards, wrapper creation, and option validation
src/main.ts Enhanced type checking with null guard and updated type annotations
spec/v2.spec.ts Added test coverage for scheduler.onSchedule() wrapping functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +75 to +81
function assertIsCloudFunctionV2<T extends CloudEvent<unknown>>(
cf: CloudFunction<T> | CallableFunction<any, any>
): asserts cf is CloudFunction<T> {
if (cf?.__endpoint?.platform !== 'gcfv2') {
throw new Error('This function can only wrap V2 CloudFunctions.');
}
}
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertIsCloudFunctionV2 function should accept ScheduleFunction in its parameter type since it's called with a V2WrappableFunctions union type (line 117) which includes ScheduleFunction. Without this, TypeScript will raise a type error when ScheduleFunction is passed to assertIsCloudFunctionV2.

Copilot uses AI. Check for mistakes.
@CorieW
Copy link
Member

CorieW commented Nov 3, 2025

Hi @alexandercerutti. Thanks for your contribution! I'll be sure to review as soon as possible.

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

Successfully merging this pull request may close these issues.

firebase-functions/v2/scheduler onSchedule is not supported by the wrapper

2 participants