@@ -2,8 +2,9 @@ import * as SentryCore from '@sentry/core';
22
33import { cron } from '../src' ;
44import type { CronJob , CronJobParams } from '../src/cron/cron' ;
5+ import type { NodeCron , NodeCronOptions } from '../src/cron/node-cron' ;
56
6- describe ( 'cron' , ( ) => {
7+ describe ( 'cron check-ins ' , ( ) => {
78 let withMonitorSpy : jest . SpyInstance ;
89
910 beforeEach ( ( ) => {
@@ -78,4 +79,49 @@ describe('cron', () => {
7879 } ) ;
7980 } ) ;
8081 } ) ;
82+
83+ describe ( 'node-cron' , ( ) => {
84+ test ( 'calls withMonitor' , done => {
85+ expect . assertions ( 5 ) ;
86+
87+ const nodeCron : NodeCron = {
88+ schedule : ( expression : string , callback : ( ) => void , options ?: NodeCronOptions ) : unknown => {
89+ expect ( expression ) . toBe ( '* * * Jan,Sep Sun' ) ;
90+ expect ( callback ) . toBeInstanceOf ( Function ) ;
91+ expect ( options ?. name ) . toBe ( 'my-cron-job' ) ;
92+ return callback ( ) ;
93+ } ,
94+ } ;
95+
96+ const cronWithCheckIn = cron . instrumentNodeCron ( nodeCron ) ;
97+
98+ cronWithCheckIn . schedule (
99+ '* * * Jan,Sep Sun' ,
100+ ( ) => {
101+ expect ( withMonitorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
102+ expect ( withMonitorSpy ) . toHaveBeenLastCalledWith ( 'my-cron-job' , expect . anything ( ) , {
103+ schedule : { type : 'crontab' , value : '* * * 1,9 0' } ,
104+ } ) ;
105+ done ( ) ;
106+ } ,
107+ { name : 'my-cron-job' } ,
108+ ) ;
109+ } ) ;
110+
111+ test ( 'throws without supplied name' , ( ) => {
112+ const nodeCron : NodeCron = {
113+ schedule : ( ) : unknown => {
114+ return undefined ;
115+ } ,
116+ } ;
117+
118+ const cronWithCheckIn = cron . instrumentNodeCron ( nodeCron ) ;
119+
120+ expect ( ( ) => {
121+ cronWithCheckIn . schedule ( '* * * * *' , ( ) => {
122+ //
123+ } ) ;
124+ } ) . toThrowError ( 'Missing "name" for scheduled job. A name is required for Sentry check-in monitoring.' ) ;
125+ } ) ;
126+ } ) ;
81127} ) ;
0 commit comments