Skip to content

Commit c417ef4

Browse files
committed
Add test for colliding state
1 parent e5b47f7 commit c417ef4

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

test/e2e/codeServer.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,25 @@ describe("CodeServer", true, [], () => {
3333
await fs.writeFile(file, "bar")
3434
await codeServerPage.openFile(file)
3535
})
36+
37+
test("should not share state with other paths", async ({ codeServerPage }) => {
38+
const dir = await codeServerPage.dir()
39+
const file = path.join(dir, "foo")
40+
await fs.writeFile(file, "bar")
41+
42+
await codeServerPage.openFile(file)
43+
44+
// If we reload now VS Code will be unable to save the state changes so wait
45+
// until those have been written to the database. It flushes every five
46+
// seconds so we need to wait at least that long.
47+
await codeServerPage.page.waitForTimeout(5500)
48+
49+
// The tab should re-open on refresh.
50+
await codeServerPage.page.reload()
51+
await codeServerPage.waitForTab(file)
52+
53+
// The tab should not re-open on a different path.
54+
await codeServerPage.setup(true, "/vscode")
55+
expect(await codeServerPage.tabIsVisible(file)).toBe(false)
56+
})
3657
})

test/e2e/models/CodeServer.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ export class CodeServerPage {
203203
}
204204

205205
/**
206-
* Navigate to code-server.
206+
* Navigate to a code-server endpoint. By default go to the root.
207207
*/
208-
async navigate() {
209-
const address = await this.codeServer.address()
210-
await this.page.goto(address, { waitUntil: "networkidle" })
208+
async navigate(path: string = "/") {
209+
const to = new URL(path, await this.codeServer.address())
210+
await this.page.goto(to.toString(), { waitUntil: "networkidle" })
211211
}
212212

213213
/**
@@ -309,6 +309,13 @@ export class CodeServerPage {
309309
return this.page.waitForSelector(`.tab :text("${path.basename(file)}")`)
310310
}
311311

312+
/**
313+
* See if the specified tab is open.
314+
*/
315+
async tabIsVisible(file: string): Promise<void> {
316+
return this.page.isVisible(`.tab :text("${path.basename(file)}")`)
317+
}
318+
312319
/**
313320
* Navigate to the command palette via menus then execute a command by typing
314321
* it then clicking the match from the results.
@@ -427,8 +434,8 @@ export class CodeServerPage {
427434
*
428435
* It is recommended to run setup before using this model in any tests.
429436
*/
430-
async setup(authenticated: boolean) {
431-
await this.navigate()
437+
async setup(authenticated: boolean, endpoint = "/") {
438+
await this.navigate(endpoint)
432439
// If we aren't authenticated we'll see a login page so we can't wait until
433440
// the editor is ready.
434441
if (authenticated) {

0 commit comments

Comments
 (0)