Skip to content

Commit 7dfd685

Browse files
authored
fix: re-enable skipped Heart tests and make non-asserting checks assert (#7845)
1 parent 72086ed commit 7dfd685

7 files changed

Lines changed: 28 additions & 24 deletions

File tree

test/e2e/codeServer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("code-server", ["--disable-workspace-trust"], {}, () => {
3232

3333
test("should show the Integrated Terminal", async ({ codeServerPage }) => {
3434
await codeServerPage.focusTerminal()
35-
expect(await codeServerPage.page.isVisible("#terminal")).toBe(true)
35+
await expect(codeServerPage.page.locator("#terminal")).toBeVisible()
3636
})
3737

3838
test("should open a file", async ({ codeServerPage }) => {

test/e2e/downloads.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => {
1818
// Action
1919
await codeServerPage.openContextMenu("text=unique-file.txt")
2020

21-
expect(await codeServerPage.page.isVisible("text=Download...")).toBe(true)
21+
await expect(codeServerPage.page.locator("text=Download...")).toBeVisible()
2222
})
2323

2424
test("should see the 'Show Local' button on Save As", async ({ codeServerPage }) => {
@@ -37,7 +37,7 @@ describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => {
3737
await codeServerPage.page.keyboard.type("Making some edits.")
3838
await codeServerPage.navigateMenus(["File", "Save As..."])
3939
await codeServerPage.page.waitForSelector(".quick-input-widget")
40-
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
40+
await expect(codeServerPage.page.locator("text=Show Local")).toBeVisible()
4141
})
4242

4343
test("should see the 'Show Local' button on Save File", async ({ codeServerPage }) => {
@@ -46,14 +46,14 @@ describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => {
4646
await codeServerPage.waitForTab("Untitled-1")
4747
await codeServerPage.navigateMenus(["File", "Save"])
4848
await codeServerPage.page.waitForSelector(".quick-input-widget")
49-
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
49+
await expect(codeServerPage.page.locator("text=Show Local")).toBeVisible()
5050
})
5151

5252
test("should see the 'Show Local' button on Save Workspace As", async ({ codeServerPage }) => {
5353
// Action
5454
await codeServerPage.navigateMenus(["File", "Save Workspace As..."])
5555
await codeServerPage.page.waitForSelector(".quick-input-widget")
56-
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
56+
await expect(codeServerPage.page.locator("text=Show Local")).toBeVisible()
5757
})
5858
})
5959

@@ -72,7 +72,7 @@ describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-d
7272
// Action
7373
await codeServerPage.openContextMenu("text=unique-file.txt")
7474

75-
expect(await codeServerPage.page.isVisible("text=Download...")).toBe(false)
75+
await expect(codeServerPage.page.locator("text=Download...")).not.toBeVisible()
7676
})
7777

7878
test("should not see the 'Show Local' button on Save as", async ({ codeServerPage }) => {
@@ -87,7 +87,7 @@ describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-d
8787
await codeServerPage.openFile(fileName)
8888
await codeServerPage.page.click(".tab")
8989
await codeServerPage.navigateMenus(["File", "Save As..."])
90-
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
90+
await expect(codeServerPage.page.locator("text=Show Local")).not.toBeVisible()
9191
})
9292

9393
test("should not see the 'Show Local' button on Save File", async ({ codeServerPage }) => {
@@ -96,13 +96,13 @@ describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-d
9696
await codeServerPage.waitForTab("Untitled-1")
9797
await codeServerPage.navigateMenus(["File", "Save"])
9898
await codeServerPage.page.waitForSelector(".quick-input-widget")
99-
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
99+
await expect(codeServerPage.page.locator("text=Show Local")).not.toBeVisible()
100100
})
101101

102102
test("should not see the 'Show Local' button on Save Workspace As", async ({ codeServerPage }) => {
103103
// Action
104104
await codeServerPage.navigateMenus(["File", "Save Workspace As..."])
105105
await codeServerPage.page.waitForSelector(".quick-input-widget")
106-
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
106+
await expect(codeServerPage.page.locator("text=Show Local")).not.toBeVisible()
107107
})
108108
})

test/e2e/extensions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function runTestExtensionTests() {
1313

1414
// Remove end slash in address.
1515
const normalizedAddress = address.replace(/\/+$/, "")
16-
await codeServerPage.page.getByText(`Info: proxyUri: ${normalizedAddress}/proxy/{{port}}/`)
16+
await expect(codeServerPage.page.getByText(`Info: proxyUri: ${normalizedAddress}/proxy/{{port}}/`)).toBeVisible()
1717
})
1818
}
1919

test/e2e/github.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (process.env.GITHUB_TOKEN) {
1212
await codeServerPage.page.click("text=Allow")
1313
// It should ask to select an account, one of which will be the one we
1414
// pre-injected.
15-
expect(await codeServerPage.page.isVisible("text=Select an account")).toBe(false)
15+
await expect(codeServerPage.page.locator("text=Select an account")).not.toBeVisible()
1616
})
1717
})
1818

@@ -26,7 +26,7 @@ if (process.env.GITHUB_TOKEN) {
2626
await codeServerPage.page.click("text=Allow")
2727
// Since there is no account it will ask directly for the token (because
2828
// we are on localhost; otherwise it would initiate the oauth flow).
29-
expect(await codeServerPage.page.isVisible("text=GitHub Personal Access Token")).toBe(false)
29+
await expect(codeServerPage.page.locator("text=GitHub Personal Access Token")).not.toBeVisible()
3030
})
3131
})
3232
} else {

test/e2e/login.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ describe("login", ["--disable-workspace-trust", "--auth", "password"], {}, () =>
2424
// Skip entering password
2525
// Click the submit button and login
2626
await codeServerPage.page.click(".submit")
27-
await codeServerPage.page.waitForLoadState("networkidle")
28-
expect(await codeServerPage.page.isVisible("text=Missing password"))
27+
// The required input blocks empty submits, so the server-side error can't render.
28+
await expect(codeServerPage.page.locator("input.password:invalid")).toBeVisible()
2929
})
3030

3131
test("should see an error message for incorrect password", async ({ codeServerPage }) => {
@@ -34,28 +34,29 @@ describe("login", ["--disable-workspace-trust", "--auth", "password"], {}, () =>
3434
// Click the submit button and login
3535
await codeServerPage.page.click(".submit")
3636
await codeServerPage.page.waitForLoadState("networkidle")
37-
expect(await codeServerPage.page.isVisible("text=Incorrect password"))
37+
await expect(codeServerPage.page.locator("text=Incorrect password")).toBeVisible()
3838
})
3939

4040
test("should hit the rate limiter for too many unsuccessful logins", async ({ codeServerPage }) => {
41-
// Type in password
42-
await codeServerPage.page.fill(".password", "password123")
41+
test.slow()
4342
// Click the submit button and login
4443
// The current RateLimiter allows 2 logins per minute plus
4544
// 12 logins per hour for a total of 14
4645
// See: src/node/routes/login.ts
4746
for (let i = 1; i <= 14; i++) {
47+
await codeServerPage.page.fill(".password", "password123")
4848
await codeServerPage.page.click(".submit")
4949
await codeServerPage.page.waitForLoadState("networkidle")
5050
// We double-check that the correct error message shows
5151
// which should be for incorrect password
52-
expect(await codeServerPage.page.isVisible("text=Incorrect password"))
52+
await expect(codeServerPage.page.locator("text=Incorrect password")).toBeVisible()
5353
}
5454

5555
// The 15th should fail for a different reason:
5656
// login rate
57+
await codeServerPage.page.fill(".password", "password123")
5758
await codeServerPage.page.click(".submit")
5859
await codeServerPage.page.waitForLoadState("networkidle")
59-
expect(await codeServerPage.page.isVisible("text=Login rate limited!"))
60+
await expect(codeServerPage.page.locator("text=Login rate limited!")).toBeVisible()
6061
})
6162
})

test/e2e/uploads.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ describe("Uploads (enabled)", ["--disable-workspace-trust"], {}, () => {
1818
// Action
1919
await codeServerPage.openContextMenu('span:has-text("test-directory")')
2020

21-
expect(await codeServerPage.page.isVisible("text=Upload...")).toBe(true)
21+
await expect(codeServerPage.page.locator("text=Upload...")).toBeVisible()
2222
})
2323

2424
test("should see the 'Show Local' button on Open File", async ({ codeServerPage }) => {
2525
// Action
2626
await codeServerPage.navigateMenus(["File", "Open File..."])
2727
await codeServerPage.page.waitForSelector(".quick-input-widget")
28-
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
28+
await expect(codeServerPage.page.locator("text=Show Local")).toBeVisible()
2929
})
3030
})
3131

@@ -44,13 +44,13 @@ describe("Uploads (disabled)", ["--disable-workspace-trust", "--disable-file-upl
4444
// Action
4545
await codeServerPage.openContextMenu('span:has-text("test-directory")')
4646

47-
expect(await codeServerPage.page.isVisible("text=Upload...")).toBe(false)
47+
await expect(codeServerPage.page.locator("text=Upload...")).not.toBeVisible()
4848
})
4949

5050
test("should not see the 'Show Local' button on Open File", async ({ codeServerPage }) => {
5151
// Action
5252
await codeServerPage.navigateMenus(["File", "Open File..."])
5353
await codeServerPage.page.waitForSelector(".quick-input-widget")
54-
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
54+
await expect(codeServerPage.page.locator("text=Show Local")).not.toBeVisible()
5555
})
5656
})

test/unit/node/heart.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ describe("heartbeatTimer", () => {
115115
const heart = new Heart(`${testDir}/shutdown.txt`, mockIsActive)
116116
await heart.beat()
117117
jest.advanceTimersByTime(60 * 1000)
118+
// Yield a real macrotask so the callback's rejection handler can run first
119+
// (fake timers stub the global setImmediate).
120+
await new Promise((resolve) => jest.requireActual("timers").setImmediate(resolve))
118121

119122
expect(mockIsActive).toHaveBeenCalled()
120123
expect(logger.warn).toHaveBeenCalledWith(errorMsg)
@@ -147,7 +150,7 @@ describe("stateChange", () => {
147150

148151
expect(mockOnChange.mock.calls[0][0]).toBe("alive")
149152
})
150-
it.only("should change to expired when not active", async () => {
153+
it("should change to expired when not active", async () => {
151154
jest.useFakeTimers()
152155
heart = new Heart(`${testDir}/shutdown.txt`, () => new Promise((resolve) => resolve(false)))
153156
const mockOnChange = jest.fn()

0 commit comments

Comments
 (0)