@@ -6534,6 +6534,109 @@ addEventListener('fetch', event => {});`
6534
6534
` ) ;
6535
6535
} ) ;
6536
6536
} ) ;
6537
+
6538
+ describe ( "dispatch namespaces" , ( ) => {
6539
+ it ( "should deploy all migrations on first deploy" , async ( ) => {
6540
+ writeWranglerToml ( {
6541
+ durable_objects : {
6542
+ bindings : [
6543
+ { name : "SOMENAME" , class_name : "SomeClass" } ,
6544
+ { name : "SOMEOTHERNAME" , class_name : "SomeOtherClass" } ,
6545
+ ] ,
6546
+ } ,
6547
+ migrations : [
6548
+ { tag : "v1" , new_classes : [ "SomeClass" ] } ,
6549
+ { tag : "v2" , new_classes : [ "SomeOtherClass" ] } ,
6550
+ ] ,
6551
+ } ) ;
6552
+ fs . writeFileSync (
6553
+ "index.js" ,
6554
+ `export class SomeClass{}; export class SomeOtherClass{}; export default {};`
6555
+ ) ;
6556
+ mockSubDomainRequest ( ) ;
6557
+ mockServiceScriptData ( {
6558
+ dispatchNamespace : "test-namespace" ,
6559
+ } ) ; // no scripts at all
6560
+ mockUploadWorkerRequest ( {
6561
+ expectedMigrations : {
6562
+ new_tag : "v2" ,
6563
+ steps : [
6564
+ { new_classes : [ "SomeClass" ] } ,
6565
+ { new_classes : [ "SomeOtherClass" ] } ,
6566
+ ] ,
6567
+ } ,
6568
+ useOldUploadApi : true ,
6569
+ expectedDispatchNamespace : "test-namespace" ,
6570
+ } ) ;
6571
+
6572
+ await runWrangler (
6573
+ "deploy index.js --dispatch-namespace test-namespace"
6574
+ ) ;
6575
+ expect ( std . out ) . toMatchInlineSnapshot ( `
6576
+ "Total Upload: xx KiB / gzip: xx KiB
6577
+ Worker Startup Time: 100 ms
6578
+ Your worker has access to the following bindings:
6579
+ - Durable Objects:
6580
+ - SOMENAME: SomeClass
6581
+ - SOMEOTHERNAME: SomeOtherClass
6582
+ Uploaded test-name (TIMINGS)
6583
+ Dispatch Namespace: test-namespace
6584
+ Current Version ID: Galaxy-Class"
6585
+ ` ) ;
6586
+ } ) ;
6587
+
6588
+ it ( "should use a script's current migration tag when publishing migrations" , async ( ) => {
6589
+ writeWranglerToml ( {
6590
+ durable_objects : {
6591
+ bindings : [
6592
+ { name : "SOMENAME" , class_name : "SomeClass" } ,
6593
+ { name : "SOMEOTHERNAME" , class_name : "SomeOtherClass" } ,
6594
+ ] ,
6595
+ } ,
6596
+ migrations : [
6597
+ { tag : "v1" , new_classes : [ "SomeClass" ] } ,
6598
+ { tag : "v2" , new_classes : [ "SomeOtherClass" ] } ,
6599
+ ] ,
6600
+ } ) ;
6601
+ fs . writeFileSync (
6602
+ "index.js" ,
6603
+ `export class SomeClass{}; export class SomeOtherClass{}; export default {};`
6604
+ ) ;
6605
+ mockSubDomainRequest ( ) ;
6606
+ mockServiceScriptData ( {
6607
+ script : { id : "test-name" , migration_tag : "v1" } ,
6608
+ dispatchNamespace : "test-namespace" ,
6609
+ } ) ;
6610
+ mockUploadWorkerRequest ( {
6611
+ expectedMigrations : {
6612
+ old_tag : "v1" ,
6613
+ new_tag : "v2" ,
6614
+ steps : [
6615
+ {
6616
+ new_classes : [ "SomeOtherClass" ] ,
6617
+ } ,
6618
+ ] ,
6619
+ } ,
6620
+ useOldUploadApi : true ,
6621
+ expectedDispatchNamespace : "test-namespace" ,
6622
+ } ) ;
6623
+
6624
+ await runWrangler (
6625
+ "deploy index.js --dispatch-namespace test-namespace"
6626
+ ) ;
6627
+ expect ( std . out ) . toMatchInlineSnapshot ( `
6628
+ "Total Upload: xx KiB / gzip: xx KiB
6629
+ Worker Startup Time: 100 ms
6630
+ Your worker has access to the following bindings:
6631
+ - Durable Objects:
6632
+ - SOMENAME: SomeClass
6633
+ - SOMEOTHERNAME: SomeOtherClass
6634
+ Uploaded test-name (TIMINGS)
6635
+ Dispatch Namespace: test-namespace
6636
+ Current Version ID: Galaxy-Class"
6637
+ ` ) ;
6638
+ } ) ;
6639
+ } ) ;
6537
6640
} ) ;
6538
6641
6539
6642
describe ( "tail consumers" , ( ) => {
@@ -11817,13 +11920,14 @@ function mockServiceScriptData(options: {
11817
11920
script ?: DurableScriptInfo ;
11818
11921
scriptName ?: string ;
11819
11922
env ?: string ;
11923
+ dispatchNamespace ?: string ;
11820
11924
} ) {
11821
11925
const { script } = options ;
11822
- if ( options . env ) {
11926
+ if ( options . dispatchNamespace ) {
11823
11927
if ( ! script ) {
11824
11928
msw . use (
11825
11929
http . get (
11826
- "*/accounts/:accountId/workers/services/:scriptName/environments/:envName " ,
11930
+ "*/accounts/:accountId/workers/dispatch/namespaces/:dispatchNamespace/scripts/:scriptName " ,
11827
11931
( ) => {
11828
11932
return HttpResponse . json ( {
11829
11933
success : false ,
@@ -11844,11 +11948,11 @@ function mockServiceScriptData(options: {
11844
11948
}
11845
11949
msw . use (
11846
11950
http . get (
11847
- "*/accounts/:accountId/workers/services/:scriptName/environments/:envName " ,
11951
+ "*/accounts/:accountId/workers/dispatch/namespaces/:dispatchNamespace/scripts/:scriptName " ,
11848
11952
( { params } ) => {
11849
11953
expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
11850
11954
expect ( params . scriptName ) . toEqual ( options . scriptName || "test-name" ) ;
11851
- expect ( params . envName ) . toEqual ( options . env ) ;
11955
+ expect ( params . dispatchNamespace ) . toEqual ( options . dispatchNamespace ) ;
11852
11956
return HttpResponse . json ( {
11853
11957
success : true ,
11854
11958
errors : [ ] ,
@@ -11860,44 +11964,90 @@ function mockServiceScriptData(options: {
11860
11964
)
11861
11965
) ;
11862
11966
} else {
11863
- if ( ! script ) {
11967
+ if ( options . env ) {
11968
+ if ( ! script ) {
11969
+ msw . use (
11970
+ http . get (
11971
+ "*/accounts/:accountId/workers/services/:scriptName/environments/:envName" ,
11972
+ ( ) => {
11973
+ return HttpResponse . json ( {
11974
+ success : false ,
11975
+ errors : [
11976
+ {
11977
+ code : 10092 ,
11978
+ message : "workers.api.error.environment_not_found" ,
11979
+ } ,
11980
+ ] ,
11981
+ messages : [ ] ,
11982
+ result : null ,
11983
+ } ) ;
11984
+ } ,
11985
+ { once : true }
11986
+ )
11987
+ ) ;
11988
+ return ;
11989
+ }
11990
+ msw . use (
11991
+ http . get (
11992
+ "*/accounts/:accountId/workers/services/:scriptName/environments/:envName" ,
11993
+ ( { params } ) => {
11994
+ expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
11995
+ expect ( params . scriptName ) . toEqual (
11996
+ options . scriptName || "test-name"
11997
+ ) ;
11998
+ expect ( params . envName ) . toEqual ( options . env ) ;
11999
+ return HttpResponse . json ( {
12000
+ success : true ,
12001
+ errors : [ ] ,
12002
+ messages : [ ] ,
12003
+ result : { script } ,
12004
+ } ) ;
12005
+ } ,
12006
+ { once : true }
12007
+ )
12008
+ ) ;
12009
+ } else {
12010
+ if ( ! script ) {
12011
+ msw . use (
12012
+ http . get (
12013
+ "*/accounts/:accountId/workers/services/:scriptName" ,
12014
+ ( ) => {
12015
+ return HttpResponse . json ( {
12016
+ success : false ,
12017
+ errors : [
12018
+ {
12019
+ code : 10090 ,
12020
+ message : "workers.api.error.service_not_found" ,
12021
+ } ,
12022
+ ] ,
12023
+ messages : [ ] ,
12024
+ result : null ,
12025
+ } ) ;
12026
+ } ,
12027
+ { once : true }
12028
+ )
12029
+ ) ;
12030
+ return ;
12031
+ }
11864
12032
msw . use (
11865
12033
http . get (
11866
12034
"*/accounts/:accountId/workers/services/:scriptName" ,
11867
- ( ) => {
12035
+ ( { params } ) => {
12036
+ expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
12037
+ expect ( params . scriptName ) . toEqual (
12038
+ options . scriptName || "test-name"
12039
+ ) ;
11868
12040
return HttpResponse . json ( {
11869
- success : false ,
11870
- errors : [
11871
- {
11872
- code : 10090 ,
11873
- message : "workers.api.error.service_not_found" ,
11874
- } ,
11875
- ] ,
12041
+ success : true ,
12042
+ errors : [ ] ,
11876
12043
messages : [ ] ,
11877
- result : null ,
12044
+ result : { default_environment : { script } } ,
11878
12045
} ) ;
11879
12046
} ,
11880
12047
{ once : true }
11881
12048
)
11882
12049
) ;
11883
- return ;
11884
12050
}
11885
- msw . use (
11886
- http . get (
11887
- "*/accounts/:accountId/workers/services/:scriptName" ,
11888
- ( { params } ) => {
11889
- expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
11890
- expect ( params . scriptName ) . toEqual ( options . scriptName || "test-name" ) ;
11891
- return HttpResponse . json ( {
11892
- success : true ,
11893
- errors : [ ] ,
11894
- messages : [ ] ,
11895
- result : { default_environment : { script } } ,
11896
- } ) ;
11897
- } ,
11898
- { once : true }
11899
- )
11900
- ) ;
11901
12051
}
11902
12052
}
11903
12053
0 commit comments