-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wrangler pages deployment (list|tail) env filtering (#7263)
Adds the --environment flag to `wrangler pages deployment list`, which should allow users to list deployments of a specific type. When the flag it's not provided it will list the latest 25 deployments regardless of type. Additionally, makes sure we're listing the correct type of deployments when attempting to tail.
- Loading branch information
Showing
5 changed files
with
214 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
Fix wrangler pages deployment (list|tail) environment filtering. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,63 @@ describe("pages deployment tail", () => { | |
); | ||
await api.closeHelper(); | ||
}); | ||
|
||
it("passes default environment to deployments list", async () => { | ||
api = mockTailAPIs(); | ||
expect(api.requests.creation.length).toStrictEqual(0); | ||
|
||
await runWrangler( | ||
"pages deployment tail --project-name mock-project mock-deployment-id" | ||
); | ||
|
||
await expect(api.ws.connected).resolves.toBeTruthy(); | ||
console.log(api.requests.deployments.queryParams[0]); | ||
expect(api.requests.deployments.count).toStrictEqual(1); | ||
expect( | ||
api.requests.deployments.queryParams[0].find(([key, _]) => { | ||
return key === "env"; | ||
}) | ||
).toStrictEqual(["env", "production"]); | ||
await api.closeHelper(); | ||
}); | ||
|
||
it("passes production environment to deployments list", async () => { | ||
api = mockTailAPIs(); | ||
expect(api.requests.creation.length).toStrictEqual(0); | ||
|
||
await runWrangler( | ||
"pages deployment tail --project-name mock-project mock-deployment-id --environment production" | ||
); | ||
|
||
await expect(api.ws.connected).resolves.toBeTruthy(); | ||
console.log(api.requests.deployments.queryParams[0]); | ||
expect(api.requests.deployments.count).toStrictEqual(1); | ||
expect( | ||
api.requests.deployments.queryParams[0].find(([key, _]) => { | ||
return key === "env"; | ||
}) | ||
).toStrictEqual(["env", "production"]); | ||
await api.closeHelper(); | ||
}); | ||
|
||
it("passes preview environment to deployments list", async () => { | ||
api = mockTailAPIs(); | ||
expect(api.requests.creation.length).toStrictEqual(0); | ||
|
||
await runWrangler( | ||
"pages deployment tail --project-name mock-project mock-deployment-id --environment preview" | ||
); | ||
|
||
await expect(api.ws.connected).resolves.toBeTruthy(); | ||
console.log(api.requests.deployments.queryParams[0]); | ||
expect(api.requests.deployments.count).toStrictEqual(1); | ||
expect( | ||
api.requests.deployments.queryParams[0].find(([key, _]) => { | ||
return key === "env"; | ||
}) | ||
).toStrictEqual(["env", "preview"]); | ||
await api.closeHelper(); | ||
}); | ||
}); | ||
|
||
describe("filtering", () => { | ||
|
@@ -783,7 +840,7 @@ function deserializeToJson(message: WebSocket.RawData): string { | |
*/ | ||
type MockAPI = { | ||
requests: { | ||
deployments: RequestCounter; | ||
deployments: RequestLogger; | ||
creation: RequestInit[]; | ||
deletion: RequestCounter; | ||
}; | ||
|
@@ -792,17 +849,29 @@ type MockAPI = { | |
closeHelper: () => Promise<void>; | ||
}; | ||
|
||
/** | ||
* A logger used to check how many times a mock API has been hit. | ||
* Useful as a helper in our testing to check if wrangler is making | ||
* the correct API calls without actually sending any web traffic. | ||
*/ | ||
type RequestLogger = { | ||
count: number; | ||
queryParams: [string, string][][]; | ||
}; | ||
|
||
/** | ||
* Mock out the API hit during Tail creation | ||
* | ||
* @returns a `RequestCounter` for counting how many times the API is hit | ||
*/ | ||
function mockListDeployments(): RequestCounter { | ||
const requests: RequestCounter = { count: 0 }; | ||
function mockListDeployments(): RequestLogger { | ||
const requests: RequestLogger = { count: 0, queryParams: [] }; | ||
msw.use( | ||
http.get( | ||
`*/accounts/:accountId/pages/projects/:projectName/deployments`, | ||
() => { | ||
({ request }) => { | ||
const url = new URL(request.url); | ||
requests.queryParams.push(Array.from(url.searchParams.entries())); | ||
requests.count++; | ||
return HttpResponse.json( | ||
{ | ||
|
@@ -839,15 +908,6 @@ function mockListDeployments(): RequestCounter { | |
return requests; | ||
} | ||
|
||
/** | ||
* A counter used to check how many times a mock API has been hit. | ||
* Useful as a helper in our testing to check if wrangler is making | ||
* the correct API calls without actually sending any web traffic | ||
*/ | ||
type RequestCounter = { | ||
count: number; | ||
}; | ||
|
||
/** | ||
* Mock out the API hit during Tail creation | ||
* | ||
|
@@ -911,6 +971,15 @@ const mockEmailEventTo = "[email protected]"; | |
*/ | ||
const mockEmailEventSize = 45416; | ||
|
||
/** | ||
* A counter used to check how many times a mock API has been hit. | ||
* Useful as a helper in our testing to check if wrangler is making | ||
* the correct API calls without actually sending any web traffic | ||
*/ | ||
type RequestCounter = { | ||
count: number; | ||
}; | ||
|
||
/** | ||
* Mock out the API hit during Tail deletion | ||
* | ||
|
@@ -950,7 +1019,7 @@ function mockTailAPIs(): MockAPI { | |
requests: { | ||
deletion: { count: 0 }, | ||
creation: [], | ||
deployments: { count: 0 }, | ||
deployments: { count: 0, queryParams: [] }, | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
ws: null!, // will be set in the `beforeEach()`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters