Skip to content

Commit e3daf1f

Browse files
committed
refactor: update goHome test
1 parent fff52b3 commit e3daf1f

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

test/goHome.test.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ describe("login", () => {
77

88
beforeAll(async () => {
99
browser = await chromium.launch()
10-
context = await browser.newContext()
10+
// Create a new context with the saved storage state
11+
const storageState = JSON.parse(process.env.STORAGE || "")
12+
context = await browser.newContext({ storageState })
1113
})
1214

1315
afterAll(async () => {
16+
// Remove password from local storage
17+
await context.clearCookies()
18+
1419
await browser.close()
1520
await context.close()
1621
})
@@ -19,12 +24,6 @@ describe("login", () => {
1924
page = await context.newPage()
2025
})
2126

22-
afterEach(async () => {
23-
await page.close()
24-
// Remove password from local storage
25-
await context.clearCookies()
26-
})
27-
2827
it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
2928
const GO_HOME_URL = `${process.env.CODE_SERVER_ADDRESS}/healthz`
3029
let requestedGoHomeUrl = false
@@ -35,15 +34,13 @@ describe("login", () => {
3534
// only that it was made
3635
if (request.url() === GO_HOME_URL) {
3736
requestedGoHomeUrl = true
37+
console.log("woooo =>>>", requestedGoHomeUrl)
3838
}
3939
})
40-
// waitUntil: "networkidle"
40+
41+
// waitUntil: "domcontentloaded"
4142
// In case the page takes a long time to load
42-
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "networkidle" })
43-
// Type in password
44-
await page.fill(".password", process.env.PASSWORD || "password")
45-
// Click the submit button and login
46-
await page.click(".submit")
43+
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "domcontentloaded" })
4744
// Click the Application menu
4845
await page.click(".menubar-menu-button[title='Application Menu']")
4946
// See the Go Home button
@@ -56,10 +53,17 @@ describe("login", () => {
5653

5754
// If there are unsaved changes it will show a dialog
5855
// asking if you're sure you want to leave
59-
page.on("dialog", (dialog) => dialog.accept())
56+
await page.on("dialog", (dialog) => dialog.accept())
6057

61-
// We make sure to wait on a request to the GO_HOME_URL
62-
await page.waitForRequest(GO_HOME_URL)
58+
// If it takes longer than 3 seconds to navigate, something is wrong
59+
await page.waitForRequest(GO_HOME_URL, { timeout: 10000 })
6360
expect(requestedGoHomeUrl).toBeTruthy()
61+
62+
// // Make sure the response for GO_HOME_URL was successful
63+
// const response = await page.waitForResponse(
64+
// (response) => response.url() === GO_HOME_URL && response.status() === 200,
65+
// )
66+
// We make sure a request was made to the GO_HOME_URL
67+
// expect(response.ok()).toBeTruthy()
6468
})
6569
})

0 commit comments

Comments
 (0)