Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/e2e/codeServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/downloads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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 }) => {
Expand All @@ -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()
})
})

Expand All @@ -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 }) => {
Expand All @@ -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 }) => {
Expand All @@ -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()
})
})
2 changes: 1 addition & 1 deletion test/e2e/extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

Expand All @@ -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 {
Expand Down
15 changes: 8 additions & 7 deletions test/e2e/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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()
})
})
8 changes: 4 additions & 4 deletions test/e2e/uploads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

Expand All @@ -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()
})
})
5 changes: 4 additions & 1 deletion test/unit/node/heart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down