Add test for colliding state

This commit is contained in:
Asher 2022-02-17 23:02:35 +00:00
parent 8ce6730810
commit 87b3824410
2 changed files with 34 additions and 6 deletions

View File

@ -33,4 +33,25 @@ describe("CodeServer", true, [], () => {
await fs.writeFile(file, "bar") await fs.writeFile(file, "bar")
await codeServerPage.openFile(file) 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)
})
}) })

View File

@ -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() { async navigate(path: string = "/") {
const address = await this.codeServer.address() const to = new URL(path, await this.codeServer.address())
await this.page.goto(address, { waitUntil: "networkidle" }) await this.page.goto(to.toString(), { waitUntil: "networkidle" })
} }
/** /**
@ -308,6 +308,13 @@ export class CodeServerPage {
return this.page.waitForSelector(`.tab :text("${path.basename(file)}")`) return this.page.waitForSelector(`.tab :text("${path.basename(file)}")`)
} }
/**
* See if the specified tab is open.
*/
async tabIsVisible(file: string): Promise<void> {
return this.page.isVisible(`.tab :text("${path.basename(file)}")`)
}
/** /**
* Navigate to the command palette via menus then execute a command by typing * Navigate to the command palette via menus then execute a command by typing
* it then clicking the match from the results. * 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. * It is recommended to run setup before using this model in any tests.
*/ */
async setup(authenticated: boolean) { async setup(authenticated: boolean, endpoint = "/") {
await this.navigate() await this.navigate(endpoint)
// If we aren't authenticated we'll see a login page so we can't wait until // If we aren't authenticated we'll see a login page so we can't wait until
// the editor is ready. // the editor is ready.
if (authenticated) { if (authenticated) {