Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit900cb05

Browse files
committed
Improve resilience of e2e test
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent8a98fad commit900cb05

File tree

2 files changed

+65
-21
lines changed

2 files changed

+65
-21
lines changed

‎site/e2e/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default defineConfig({
3131
],
3232
reporter:[["./reporter.ts"]],
3333
use:{
34-
actionTimeout:5000,
34+
actionTimeout:60_000,
3535
baseURL:`http://localhost:${coderPort}`,
3636
video:"retain-on-failure",
3737
...(wsEndpoint

‎site/e2e/tests/presets/prebuilds.spec.ts

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
importpathfrom"node:path";
2-
import{expect,test}from"@playwright/test";
2+
import{typeLocator,expect,test}from"@playwright/test";
33
import{
44
currentUser,
55
importTemplate,
@@ -14,18 +14,22 @@ test.beforeEach(async ({ page }) => {
1414
awaitlogin(page);
1515
});
1616

17+
constwaitForBuildTimeout=120_000;// Builds can take a while, let's give them at most 2m.
18+
19+
consttemplateFiles=[
20+
path.join(__dirname,"basic-presets-with-prebuild/main.tf"),
21+
path.join(__dirname,"basic-presets-with-prebuild/.terraform.lock.hcl"),
22+
];
23+
24+
constexpectedPrebuilds=2;
25+
1726
// NOTE: requires the `workspace-prebuilds` experiment enabled!
1827
test("create template with desired prebuilds",async({ page, baseURL})=>{
1928
requiresLicense();
2029

21-
constexpectedPrebuilds=2;
22-
2330
// Create new template.
2431
consttemplateName=randomName();
25-
awaitimportTemplate(page,templateName,[
26-
path.join(__dirname,"basic-presets-with-prebuild/main.tf"),
27-
path.join(__dirname,"basic-presets-with-prebuild/.terraform.lock.hcl"),
28-
]);
32+
awaitimportTemplate(page,templateName,templateFiles);
2933

3034
awaitpage.goto(
3135
`/workspaces?filter=owner:prebuilds%20template:${templateName}&page=1`,
@@ -34,13 +38,13 @@ test("create template with desired prebuilds", async ({ page, baseURL }) => {
3438

3539
// Wait for prebuilds to show up.
3640
constprebuilds=page.getByTestId(/^workspace-.+$/);
37-
awaitprebuilds.first().waitFor({state:"visible",timeout:120_000});
38-
expect((awaitprebuilds.all()).length).toEqual(expectedPrebuilds);
41+
awaitwaitForExpectedCount(prebuilds,expectedPrebuilds);
3942

4043
// Wait for prebuilds to start.
41-
construnningPrebuilds=page.getByTestId("build-status").getByText("Running");
42-
awaitrunningPrebuilds.first().waitFor({state:"visible",timeout:120_000});
43-
expect((awaitrunningPrebuilds.all()).length).toEqual(expectedPrebuilds);
44+
construnningPrebuilds=page
45+
.getByTestId("build-status")
46+
.getByText("Running");
47+
awaitwaitForExpectedCount(runningPrebuilds,expectedPrebuilds);
4448
});
4549

4650
// NOTE: requires the `workspace-prebuilds` experiment enabled!
@@ -51,10 +55,7 @@ test("claim prebuild matching selected preset", async ({ page, baseURL }) => {
5155

5256
// Create new template.
5357
consttemplateName=randomName();
54-
awaitimportTemplate(page,templateName,[
55-
path.join(__dirname,"basic-presets-with-prebuild/main.tf"),
56-
path.join(__dirname,"basic-presets-with-prebuild/.terraform.lock.hcl"),
57-
]);
58+
awaitimportTemplate(page,templateName,templateFiles);
5859

5960
awaitpage.goto(
6061
`/workspaces?filter=owner:prebuilds%20template:${templateName}&page=1`,
@@ -63,11 +64,17 @@ test("claim prebuild matching selected preset", async ({ page, baseURL }) => {
6364

6465
// Wait for prebuilds to show up.
6566
constprebuilds=page.getByTestId(/^workspace-.+$/);
66-
awaitprebuilds.first().waitFor({state:"visible",timeout:120_000});
67+
awaitwaitForExpectedCount(prebuilds,expectedPrebuilds);
68+
69+
constpreviousWorkspaceNames=awaitPromise.all(
70+
(awaitprebuilds.all()).map((value)=>{
71+
returnvalue.getByText(/prebuild-.+/).textContent();
72+
}),
73+
);
6774

6875
// Wait for prebuilds to start.
69-
construnningPrebuilds=page.getByTestId("build-status").getByText("Running");
70-
awaitrunningPrebuilds.first().waitFor({state:"visible",timeout:120_000});
76+
letrunningPrebuilds=page.getByTestId("build-status").getByText("Running");
77+
awaitwaitForExpectedCount(runningPrebuilds,expectedPrebuilds);
7178

7279
// Open the first prebuild.
7380
awaitrunningPrebuilds.first().click();
@@ -101,12 +108,49 @@ test("claim prebuild matching selected preset", async ({ page, baseURL }) => {
101108
// Wait for the workspace build display to be navigated to.
102109
constuser=currentUser(page);
103110
awaitpage.waitForURL(`/@${user.username}/${workspaceName}`,{
104-
timeout:120_000,// Account for workspace build time.
111+
timeout:waitForBuildTimeout,// Account for workspace build time.
105112
});
106113

107114
// Validate the workspace metadata that it was indeed a claimed prebuild.
108115
constindicator=page.getByText("Was Prebuild");
109116
awaitindicator.waitFor({timeout:60_000});
110117
consttext=indicator.locator("xpath=..").getByText("Yes");
111118
awaittext.waitFor({timeout:30_000});
119+
120+
// Navigate back to prebuilds page to see that a new prebuild replaced the claimed one.
121+
awaitpage.goto(
122+
`/workspaces?filter=owner:prebuilds%20template:${templateName}&page=1`,
123+
{waitUntil:"domcontentloaded"},
124+
);
125+
126+
// Wait for prebuilds to show up.
127+
constnewPrebuilds=page.getByTestId(/^workspace-.+$/);
128+
awaitwaitForExpectedCount(newPrebuilds,expectedPrebuilds);
129+
130+
constcurrentWorkspaceNames=awaitPromise.all(
131+
(awaitnewPrebuilds.all()).map((value)=>{
132+
returnvalue.getByText(/prebuild-.+/).textContent();
133+
}),
134+
);
135+
136+
// Ensure the prebuilds have changed.
137+
expect(currentWorkspaceNames).not.toEqual(previousWorkspaceNames);
138+
139+
// Wait for prebuilds to start.
140+
runningPrebuilds=page.getByTestId("build-status").getByText("Running");
141+
awaitwaitForExpectedCount(runningPrebuilds,expectedPrebuilds);
112142
});
143+
144+
functionwaitForExpectedCount(prebuilds:Locator,expectedCount:number){
145+
returnexpect
146+
.poll(
147+
async()=>{
148+
return(awaitprebuilds.all()).length===expectedCount;
149+
},
150+
{
151+
intervals:[100],
152+
timeout:waitForBuildTimeout,
153+
},
154+
)
155+
.toBe(true);
156+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp