diff --git a/test/e2e/codeServer.test.ts b/test/e2e/codeServer.test.ts index 0e04742ea31a..199298a1495e 100644 --- a/test/e2e/codeServer.test.ts +++ b/test/e2e/codeServer.test.ts @@ -32,7 +32,7 @@ describe("code-server", ["--disable-workspace-trust"], {}, () => { test("should show the Integrated Terminal", async ({ codeServerPage }) => { await codeServerPage.focusTerminal() - expect(await codeServerPage.page.isVisible("#terminal")).toBe(true) + await expect(codeServerPage.page.locator("#terminal")).toBeVisible() }) test("should open a file", async ({ codeServerPage }) => { diff --git a/test/e2e/downloads.test.ts b/test/e2e/downloads.test.ts index 0adcd68ff83d..f08e13b74e0a 100644 --- a/test/e2e/downloads.test.ts +++ b/test/e2e/downloads.test.ts @@ -18,7 +18,7 @@ describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => { // Action await codeServerPage.openContextMenu("text=unique-file.txt") - expect(await codeServerPage.page.isVisible("text=Download...")).toBe(true) + await expect(codeServerPage.page.locator("text=Download...")).toBeVisible() }) test("should see the 'Show Local' button on Save As", async ({ codeServerPage }) => { @@ -37,7 +37,7 @@ describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => { await codeServerPage.page.keyboard.type("Making some edits.") await codeServerPage.navigateMenus(["File", "Save As..."]) await codeServerPage.page.waitForSelector(".quick-input-widget") - expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true) + await expect(codeServerPage.page.locator("text=Show Local")).toBeVisible() }) test("should see the 'Show Local' button on Save File", async ({ codeServerPage }) => { @@ -46,14 +46,14 @@ describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => { await codeServerPage.waitForTab("Untitled-1") await codeServerPage.navigateMenus(["File", "Save"]) await codeServerPage.page.waitForSelector(".quick-input-widget") - expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true) + await expect(codeServerPage.page.locator("text=Show Local")).toBeVisible() }) test("should see the 'Show Local' button on Save Workspace As", async ({ codeServerPage }) => { // Action await codeServerPage.navigateMenus(["File", "Save Workspace As..."]) await codeServerPage.page.waitForSelector(".quick-input-widget") - expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true) + await expect(codeServerPage.page.locator("text=Show Local")).toBeVisible() }) }) @@ -72,7 +72,7 @@ describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-d // Action await codeServerPage.openContextMenu("text=unique-file.txt") - expect(await codeServerPage.page.isVisible("text=Download...")).toBe(false) + await expect(codeServerPage.page.locator("text=Download...")).not.toBeVisible() }) 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 await codeServerPage.openFile(fileName) await codeServerPage.page.click(".tab") await codeServerPage.navigateMenus(["File", "Save As..."]) - expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false) + await expect(codeServerPage.page.locator("text=Show Local")).not.toBeVisible() }) 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 await codeServerPage.waitForTab("Untitled-1") await codeServerPage.navigateMenus(["File", "Save"]) await codeServerPage.page.waitForSelector(".quick-input-widget") - expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false) + await expect(codeServerPage.page.locator("text=Show Local")).not.toBeVisible() }) test("should not see the 'Show Local' button on Save Workspace As", async ({ codeServerPage }) => { // Action await codeServerPage.navigateMenus(["File", "Save Workspace As..."]) await codeServerPage.page.waitForSelector(".quick-input-widget") - expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false) + await expect(codeServerPage.page.locator("text=Show Local")).not.toBeVisible() }) }) diff --git a/test/e2e/extensions.test.ts b/test/e2e/extensions.test.ts index ac56fcfec059..9861e0004e7b 100644 --- a/test/e2e/extensions.test.ts +++ b/test/e2e/extensions.test.ts @@ -13,7 +13,7 @@ function runTestExtensionTests() { // Remove end slash in address. const normalizedAddress = address.replace(/\/+$/, "") - await codeServerPage.page.getByText(`Info: proxyUri: ${normalizedAddress}/proxy/{{port}}/`) + await expect(codeServerPage.page.getByText(`Info: proxyUri: ${normalizedAddress}/proxy/{{port}}/`)).toBeVisible() }) } diff --git a/test/e2e/github.test.ts b/test/e2e/github.test.ts index 403d3161a208..aa45886bd1f6 100644 --- a/test/e2e/github.test.ts +++ b/test/e2e/github.test.ts @@ -12,7 +12,7 @@ if (process.env.GITHUB_TOKEN) { await codeServerPage.page.click("text=Allow") // It should ask to select an account, one of which will be the one we // pre-injected. - expect(await codeServerPage.page.isVisible("text=Select an account")).toBe(false) + await expect(codeServerPage.page.locator("text=Select an account")).not.toBeVisible() }) }) @@ -26,7 +26,7 @@ if (process.env.GITHUB_TOKEN) { await codeServerPage.page.click("text=Allow") // Since there is no account it will ask directly for the token (because // we are on localhost; otherwise it would initiate the oauth flow). - expect(await codeServerPage.page.isVisible("text=GitHub Personal Access Token")).toBe(false) + await expect(codeServerPage.page.locator("text=GitHub Personal Access Token")).not.toBeVisible() }) }) } else { diff --git a/test/e2e/login.test.ts b/test/e2e/login.test.ts index 90ec1b8cdef9..2ce9ce8e8035 100644 --- a/test/e2e/login.test.ts +++ b/test/e2e/login.test.ts @@ -24,8 +24,8 @@ describe("login", ["--disable-workspace-trust", "--auth", "password"], {}, () => // Skip entering password // Click the submit button and login await codeServerPage.page.click(".submit") - await codeServerPage.page.waitForLoadState("networkidle") - expect(await codeServerPage.page.isVisible("text=Missing password")) + // The required input blocks empty submits, so the server-side error can't render. + await expect(codeServerPage.page.locator("input.password:invalid")).toBeVisible() }) test("should see an error message for incorrect password", async ({ codeServerPage }) => { @@ -34,28 +34,29 @@ describe("login", ["--disable-workspace-trust", "--auth", "password"], {}, () => // Click the submit button and login await codeServerPage.page.click(".submit") await codeServerPage.page.waitForLoadState("networkidle") - expect(await codeServerPage.page.isVisible("text=Incorrect password")) + await expect(codeServerPage.page.locator("text=Incorrect password")).toBeVisible() }) test("should hit the rate limiter for too many unsuccessful logins", async ({ codeServerPage }) => { - // Type in password - await codeServerPage.page.fill(".password", "password123") + test.slow() // Click the submit button and login // The current RateLimiter allows 2 logins per minute plus // 12 logins per hour for a total of 14 // See: src/node/routes/login.ts for (let i = 1; i <= 14; i++) { + await codeServerPage.page.fill(".password", "password123") await codeServerPage.page.click(".submit") await codeServerPage.page.waitForLoadState("networkidle") // We double-check that the correct error message shows // which should be for incorrect password - expect(await codeServerPage.page.isVisible("text=Incorrect password")) + await expect(codeServerPage.page.locator("text=Incorrect password")).toBeVisible() } // The 15th should fail for a different reason: // login rate + await codeServerPage.page.fill(".password", "password123") await codeServerPage.page.click(".submit") await codeServerPage.page.waitForLoadState("networkidle") - expect(await codeServerPage.page.isVisible("text=Login rate limited!")) + await expect(codeServerPage.page.locator("text=Login rate limited!")).toBeVisible() }) }) diff --git a/test/e2e/uploads.test.ts b/test/e2e/uploads.test.ts index 80df808a44e4..05bb9ffd98a3 100644 --- a/test/e2e/uploads.test.ts +++ b/test/e2e/uploads.test.ts @@ -18,14 +18,14 @@ describe("Uploads (enabled)", ["--disable-workspace-trust"], {}, () => { // Action await codeServerPage.openContextMenu('span:has-text("test-directory")') - expect(await codeServerPage.page.isVisible("text=Upload...")).toBe(true) + await expect(codeServerPage.page.locator("text=Upload...")).toBeVisible() }) test("should see the 'Show Local' button on Open File", async ({ codeServerPage }) => { // Action await codeServerPage.navigateMenus(["File", "Open File..."]) await codeServerPage.page.waitForSelector(".quick-input-widget") - expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true) + await expect(codeServerPage.page.locator("text=Show Local")).toBeVisible() }) }) @@ -44,13 +44,13 @@ describe("Uploads (disabled)", ["--disable-workspace-trust", "--disable-file-upl // Action await codeServerPage.openContextMenu('span:has-text("test-directory")') - expect(await codeServerPage.page.isVisible("text=Upload...")).toBe(false) + await expect(codeServerPage.page.locator("text=Upload...")).not.toBeVisible() }) test("should not see the 'Show Local' button on Open File", async ({ codeServerPage }) => { // Action await codeServerPage.navigateMenus(["File", "Open File..."]) await codeServerPage.page.waitForSelector(".quick-input-widget") - expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false) + await expect(codeServerPage.page.locator("text=Show Local")).not.toBeVisible() }) }) diff --git a/test/unit/node/heart.test.ts b/test/unit/node/heart.test.ts index 7ad0d21752f2..e7c7b166ca11 100644 --- a/test/unit/node/heart.test.ts +++ b/test/unit/node/heart.test.ts @@ -115,6 +115,9 @@ describe("heartbeatTimer", () => { const heart = new Heart(`${testDir}/shutdown.txt`, mockIsActive) await heart.beat() jest.advanceTimersByTime(60 * 1000) + // Yield a real macrotask so the callback's rejection handler can run first + // (fake timers stub the global setImmediate). + await new Promise((resolve) => jest.requireActual("timers").setImmediate(resolve)) expect(mockIsActive).toHaveBeenCalled() expect(logger.warn).toHaveBeenCalledWith(errorMsg) @@ -147,7 +150,7 @@ describe("stateChange", () => { expect(mockOnChange.mock.calls[0][0]).toBe("alive") }) - it.only("should change to expired when not active", async () => { + it("should change to expired when not active", async () => { jest.useFakeTimers() heart = new Heart(`${testDir}/shutdown.txt`, () => new Promise((resolve) => resolve(false))) const mockOnChange = jest.fn()