@@ -166,6 +166,63 @@ describe("pages deployment tail", () => {
166
166
) ;
167
167
await api . closeHelper ( ) ;
168
168
} ) ;
169
+
170
+ it ( "passes default environment to deployments list" , async ( ) => {
171
+ api = mockTailAPIs ( ) ;
172
+ expect ( api . requests . creation . length ) . toStrictEqual ( 0 ) ;
173
+
174
+ await runWrangler (
175
+ "pages deployment tail --project-name mock-project mock-deployment-id"
176
+ ) ;
177
+
178
+ await expect ( api . ws . connected ) . resolves . toBeTruthy ( ) ;
179
+ console . log ( api . requests . deployments . queryParams [ 0 ] ) ;
180
+ expect ( api . requests . deployments . count ) . toStrictEqual ( 1 ) ;
181
+ expect (
182
+ api . requests . deployments . queryParams [ 0 ] . find ( ( [ key , _ ] ) => {
183
+ return key === "env" ;
184
+ } )
185
+ ) . toStrictEqual ( [ "env" , "production" ] ) ;
186
+ await api . closeHelper ( ) ;
187
+ } ) ;
188
+
189
+ it ( "passes production environment to deployments list" , async ( ) => {
190
+ api = mockTailAPIs ( ) ;
191
+ expect ( api . requests . creation . length ) . toStrictEqual ( 0 ) ;
192
+
193
+ await runWrangler (
194
+ "pages deployment tail --project-name mock-project mock-deployment-id --environment production"
195
+ ) ;
196
+
197
+ await expect ( api . ws . connected ) . resolves . toBeTruthy ( ) ;
198
+ console . log ( api . requests . deployments . queryParams [ 0 ] ) ;
199
+ expect ( api . requests . deployments . count ) . toStrictEqual ( 1 ) ;
200
+ expect (
201
+ api . requests . deployments . queryParams [ 0 ] . find ( ( [ key , _ ] ) => {
202
+ return key === "env" ;
203
+ } )
204
+ ) . toStrictEqual ( [ "env" , "production" ] ) ;
205
+ await api . closeHelper ( ) ;
206
+ } ) ;
207
+
208
+ it ( "passes preview environment to deployments list" , async ( ) => {
209
+ api = mockTailAPIs ( ) ;
210
+ expect ( api . requests . creation . length ) . toStrictEqual ( 0 ) ;
211
+
212
+ await runWrangler (
213
+ "pages deployment tail --project-name mock-project mock-deployment-id --environment preview"
214
+ ) ;
215
+
216
+ await expect ( api . ws . connected ) . resolves . toBeTruthy ( ) ;
217
+ console . log ( api . requests . deployments . queryParams [ 0 ] ) ;
218
+ expect ( api . requests . deployments . count ) . toStrictEqual ( 1 ) ;
219
+ expect (
220
+ api . requests . deployments . queryParams [ 0 ] . find ( ( [ key , _ ] ) => {
221
+ return key === "env" ;
222
+ } )
223
+ ) . toStrictEqual ( [ "env" , "preview" ] ) ;
224
+ await api . closeHelper ( ) ;
225
+ } ) ;
169
226
} ) ;
170
227
171
228
describe ( "filtering" , ( ) => {
@@ -783,7 +840,7 @@ function deserializeToJson(message: WebSocket.RawData): string {
783
840
*/
784
841
type MockAPI = {
785
842
requests : {
786
- deployments : RequestCounter ;
843
+ deployments : RequestLogger ;
787
844
creation : RequestInit [ ] ;
788
845
deletion : RequestCounter ;
789
846
} ;
@@ -792,17 +849,29 @@ type MockAPI = {
792
849
closeHelper : ( ) => Promise < void > ;
793
850
} ;
794
851
852
+ /**
853
+ * A logger used to check how many times a mock API has been hit.
854
+ * Useful as a helper in our testing to check if wrangler is making
855
+ * the correct API calls without actually sending any web traffic.
856
+ */
857
+ type RequestLogger = {
858
+ count : number ;
859
+ queryParams : [ string , string ] [ ] [ ] ;
860
+ } ;
861
+
795
862
/**
796
863
* Mock out the API hit during Tail creation
797
864
*
798
865
* @returns a `RequestCounter` for counting how many times the API is hit
799
866
*/
800
- function mockListDeployments ( ) : RequestCounter {
801
- const requests : RequestCounter = { count : 0 } ;
867
+ function mockListDeployments ( ) : RequestLogger {
868
+ const requests : RequestLogger = { count : 0 , queryParams : [ ] } ;
802
869
msw . use (
803
870
http . get (
804
871
`*/accounts/:accountId/pages/projects/:projectName/deployments` ,
805
- ( ) => {
872
+ ( { request } ) => {
873
+ const url = new URL ( request . url ) ;
874
+ requests . queryParams . push ( Array . from ( url . searchParams . entries ( ) ) ) ;
806
875
requests . count ++ ;
807
876
return HttpResponse . json (
808
877
{
@@ -839,15 +908,6 @@ function mockListDeployments(): RequestCounter {
839
908
return requests ;
840
909
}
841
910
842
- /**
843
- * A counter used to check how many times a mock API has been hit.
844
- * Useful as a helper in our testing to check if wrangler is making
845
- * the correct API calls without actually sending any web traffic
846
- */
847
- type RequestCounter = {
848
- count : number ;
849
- } ;
850
-
851
911
/**
852
912
* Mock out the API hit during Tail creation
853
913
*
911
971
*/
912
972
const mockEmailEventSize = 45416 ;
913
973
974
+ /**
975
+ * A counter used to check how many times a mock API has been hit.
976
+ * Useful as a helper in our testing to check if wrangler is making
977
+ * the correct API calls without actually sending any web traffic
978
+ */
979
+ type RequestCounter = {
980
+ count : number ;
981
+ } ;
982
+
914
983
/**
915
984
* Mock out the API hit during Tail deletion
916
985
*
@@ -950,7 +1019,7 @@ function mockTailAPIs(): MockAPI {
950
1019
requests : {
951
1020
deletion : { count : 0 } ,
952
1021
creation : [ ] ,
953
- deployments : { count : 0 } ,
1022
+ deployments : { count : 0 , queryParams : [ ] } ,
954
1023
} ,
955
1024
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
956
1025
ws : null ! , // will be set in the `beforeEach()`.
0 commit comments