@@ -2069,6 +2069,43 @@ Update them to point to this script instead?`,
20692069 it . todo ( "should error if it's a workers.dev route" ) ;
20702070 } ) ;
20712071
2072+ describe ( "triggers" , ( ) => {
2073+ it ( "should deploy the worker with a scheduled trigger" , async ( ) => {
2074+ const crons = [ "*/5 * * * *" , "0 18 * * 6L" ] ;
2075+ writeWranglerConfig ( {
2076+ triggers : { crons } ,
2077+ } ) ;
2078+ writeWorkerSource ( ) ;
2079+ mockSubDomainRequest ( ) ;
2080+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
2081+ mockPublishSchedulesRequest ( { crons } ) ;
2082+ await runWrangler ( "deploy ./index" ) ;
2083+ } ) ;
2084+
2085+ it ( "should deploy the worker with an empty array of scheduled triggers" , async ( ) => {
2086+ const crons : string [ ] = [ ] ;
2087+ writeWranglerConfig ( {
2088+ triggers : { crons } ,
2089+ } ) ;
2090+ writeWorkerSource ( ) ;
2091+ mockSubDomainRequest ( ) ;
2092+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
2093+ mockPublishSchedulesRequest ( { crons } ) ;
2094+ await runWrangler ( "deploy ./index" ) ;
2095+ } ) ;
2096+
2097+ it . each ( [ { triggers : { crons : undefined } } , { triggers : undefined } , { } ] ) (
2098+ "should deploy the worker without updating the scheduled triggers" ,
2099+ async ( config ) => {
2100+ writeWranglerConfig ( config ) ;
2101+ writeWorkerSource ( ) ;
2102+ mockSubDomainRequest ( ) ;
2103+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
2104+ await runWrangler ( "deploy ./index" ) ;
2105+ }
2106+ ) ;
2107+ } ) ;
2108+
20722109 describe ( "entry-points" , ( ) => {
20732110 it ( "should be able to use `index` with no extension as the entry-point (esm)" , async ( ) => {
20742111 writeWranglerConfig ( ) ;
@@ -12943,6 +12980,38 @@ function mockLastDeploymentRequest() {
1294312980 msw . use ( ...mswSuccessDeploymentScriptMetadata ) ;
1294412981}
1294512982
12983+ function mockPublishSchedulesRequest ( {
12984+ crons = [ ] ,
12985+ env = undefined ,
12986+ legacyEnv = false ,
12987+ } : {
12988+ crons : Config [ "triggers" ] [ "crons" ] ;
12989+ env ?: string | undefined ;
12990+ legacyEnv ?: boolean | undefined ;
12991+ } ) {
12992+ const servicesOrScripts = env && ! legacyEnv ? "services" : "scripts" ;
12993+ const environment = env && ! legacyEnv ? "/environments/:envName" : "" ;
12994+
12995+ msw . use (
12996+ http . put (
12997+ `*/accounts/:accountId/workers/${ servicesOrScripts } /:scriptName${ environment } /schedules` ,
12998+ async ( { request, params } ) => {
12999+ expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
13000+ expect ( params . scriptName ) . toEqual (
13001+ legacyEnv && env ? `test-name-${ env } ` : "test-name"
13002+ ) ;
13003+ if ( ! legacyEnv ) {
13004+ expect ( params . envName ) . toEqual ( env ) ;
13005+ }
13006+ const body = ( await request . json ( ) ) as [ { cron : string } ] ;
13007+ expect ( body ) . toEqual ( crons . map ( ( cron ) => ( { cron } ) ) ) ;
13008+ return HttpResponse . json ( createFetchResult ( null ) ) ;
13009+ } ,
13010+ { once : true }
13011+ )
13012+ ) ;
13013+ }
13014+
1294613015function mockPublishRoutesRequest ( {
1294713016 routes = [ ] ,
1294813017 env = undefined ,
0 commit comments