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