@@ -2051,6 +2051,43 @@ Update them to point to this script instead?`,
20512051 it . todo ( "should error if it's a workers.dev route" ) ;
20522052 } ) ;
20532053
2054+ describe ( "triggers" , ( ) => {
2055+ it ( "should deploy the worker with a scheduled trigger" , async ( ) => {
2056+ const crons = [ "*/5 * * * *" , "0 18 * * 6L" ] ;
2057+ writeWranglerConfig ( {
2058+ triggers : { crons } ,
2059+ } ) ;
2060+ writeWorkerSource ( ) ;
2061+ mockSubDomainRequest ( ) ;
2062+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
2063+ mockPublishSchedulesRequest ( { crons } ) ;
2064+ await runWrangler ( "deploy ./index" ) ;
2065+ } ) ;
2066+
2067+ it ( "should deploy the worker with an empty array of scheduled triggers" , async ( ) => {
2068+ const crons : string [ ] = [ ] ;
2069+ writeWranglerConfig ( {
2070+ triggers : { crons } ,
2071+ } ) ;
2072+ writeWorkerSource ( ) ;
2073+ mockSubDomainRequest ( ) ;
2074+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
2075+ mockPublishSchedulesRequest ( { crons } ) ;
2076+ await runWrangler ( "deploy ./index" ) ;
2077+ } ) ;
2078+
2079+ it . each ( [ { triggers : { crons : undefined } } , { triggers : undefined } , { } ] ) (
2080+ "should deploy the worker without updating the scheduled triggers" ,
2081+ async ( config ) => {
2082+ writeWranglerConfig ( config ) ;
2083+ writeWorkerSource ( ) ;
2084+ mockSubDomainRequest ( ) ;
2085+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
2086+ await runWrangler ( "deploy ./index" ) ;
2087+ }
2088+ ) ;
2089+ } ) ;
2090+
20542091 describe ( "entry-points" , ( ) => {
20552092 it ( "should be able to use `index` with no extension as the entry-point (esm)" , async ( ) => {
20562093 writeWranglerConfig ( ) ;
@@ -13225,6 +13262,38 @@ function mockLastDeploymentRequest() {
1322513262 msw . use ( ...mswSuccessDeploymentScriptMetadata ) ;
1322613263}
1322713264
13265+ function mockPublishSchedulesRequest ( {
13266+ crons = [ ] ,
13267+ env = undefined ,
13268+ legacyEnv = false ,
13269+ } : {
13270+ crons : Config [ "triggers" ] [ "crons" ] ;
13271+ env ?: string | undefined ;
13272+ legacyEnv ?: boolean | undefined ;
13273+ } ) {
13274+ const servicesOrScripts = env && ! legacyEnv ? "services" : "scripts" ;
13275+ const environment = env && ! legacyEnv ? "/environments/:envName" : "" ;
13276+
13277+ msw . use (
13278+ http . put (
13279+ `*/accounts/:accountId/workers/${ servicesOrScripts } /:scriptName${ environment } /schedules` ,
13280+ async ( { request, params } ) => {
13281+ expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
13282+ expect ( params . scriptName ) . toEqual (
13283+ legacyEnv && env ? `test-name-${ env } ` : "test-name"
13284+ ) ;
13285+ if ( ! legacyEnv ) {
13286+ expect ( params . envName ) . toEqual ( env ) ;
13287+ }
13288+ const body = ( await request . json ( ) ) as [ { cron : string } ] ;
13289+ expect ( body ) . toEqual ( crons . map ( ( cron ) => ( { cron } ) ) ) ;
13290+ return HttpResponse . json ( createFetchResult ( null ) ) ;
13291+ } ,
13292+ { once : true }
13293+ )
13294+ ) ;
13295+ }
13296+
1322813297function mockPublishRoutesRequest ( {
1322913298 routes = [ ] ,
1323013299 env = undefined ,
0 commit comments