From 87b38244102d9bf3f76fdadd861df5ee00517c09 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 17 Feb 2022 23:02:35 +0000 Subject: [PATCH] Add test for colliding state --- test/e2e/codeServer.test.ts | 21 +++++++++++++++++++++ test/e2e/models/CodeServer.ts | 19 +++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/test/e2e/codeServer.test.ts b/test/e2e/codeServer.test.ts index 38a6fbaf..6a7d1ec1 100644 --- a/test/e2e/codeServer.test.ts +++ b/test/e2e/codeServer.test.ts @@ -33,4 +33,25 @@ describe("CodeServer", true, [], () => { await fs.writeFile(file, "bar") await codeServerPage.openFile(file) }) + + test("should not share state with other paths", async ({ codeServerPage }) => { + const dir = await codeServerPage.dir() + const file = path.join(dir, "foo") + await fs.writeFile(file, "bar") + + await codeServerPage.openFile(file) + + // If we reload now VS Code will be unable to save the state changes so wait + // until those have been written to the database. It flushes every five + // seconds so we need to wait at least that long. + await codeServerPage.page.waitForTimeout(5500) + + // The tab should re-open on refresh. + await codeServerPage.page.reload() + await codeServerPage.waitForTab(file) + + // The tab should not re-open on a different path. + await codeServerPage.setup(true, "/vscode") + expect(await codeServerPage.tabIsVisible(file)).toBe(false) + }) }) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index 25d36c85..f81d9ed3 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -203,11 +203,11 @@ export class CodeServerPage { } /** - * Navigate to code-server. + * Navigate to a code-server endpoint. By default go to the root. */ - async navigate() { - const address = await this.codeServer.address() - await this.page.goto(address, { waitUntil: "networkidle" }) + async navigate(path: string = "/") { + const to = new URL(path, await this.codeServer.address()) + await this.page.goto(to.toString(), { waitUntil: "networkidle" }) } /** @@ -308,6 +308,13 @@ export class CodeServerPage { return this.page.waitForSelector(`.tab :text("${path.basename(file)}")`) } + /** + * See if the specified tab is open. + */ + async tabIsVisible(file: string): Promise { + return this.page.isVisible(`.tab :text("${path.basename(file)}")`) + } + /** * Navigate to the command palette via menus then execute a command by typing * it then clicking the match from the results. @@ -426,8 +433,8 @@ export class CodeServerPage { * * It is recommended to run setup before using this model in any tests. */ - async setup(authenticated: boolean) { - await this.navigate() + async setup(authenticated: boolean, endpoint = "/") { + await this.navigate(endpoint) // If we aren't authenticated we'll see a login page so we can't wait until // the editor is ready. if (authenticated) {