@@ -7,10 +7,15 @@ describe("login", () => {
7
7
8
8
beforeAll ( async ( ) => {
9
9
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 } )
11
13
} )
12
14
13
15
afterAll ( async ( ) => {
16
+ // Remove password from local storage
17
+ await context . clearCookies ( )
18
+
14
19
await browser . close ( )
15
20
await context . close ( )
16
21
} )
@@ -19,12 +24,6 @@ describe("login", () => {
19
24
page = await context . newPage ( )
20
25
} )
21
26
22
- afterEach ( async ( ) => {
23
- await page . close ( )
24
- // Remove password from local storage
25
- await context . clearCookies ( )
26
- } )
27
-
28
27
it ( "should see a 'Go Home' button in the Application Menu that goes to coder.com" , async ( ) => {
29
28
const GO_HOME_URL = `${ process . env . CODE_SERVER_ADDRESS } /healthz`
30
29
let requestedGoHomeUrl = false
@@ -35,15 +34,13 @@ describe("login", () => {
35
34
// only that it was made
36
35
if ( request . url ( ) === GO_HOME_URL ) {
37
36
requestedGoHomeUrl = true
37
+ console . log ( "woooo =>>>" , requestedGoHomeUrl )
38
38
}
39
39
} )
40
- // waitUntil: "networkidle"
40
+
41
+ // waitUntil: "domcontentloaded"
41
42
// 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" } )
47
44
// Click the Application menu
48
45
await page . click ( ".menubar-menu-button[title='Application Menu']" )
49
46
// See the Go Home button
@@ -56,10 +53,17 @@ describe("login", () => {
56
53
57
54
// If there are unsaved changes it will show a dialog
58
55
// asking if you're sure you want to leave
59
- page . on ( "dialog" , ( dialog ) => dialog . accept ( ) )
56
+ await page . on ( "dialog" , ( dialog ) => dialog . accept ( ) )
60
57
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 } )
63
60
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()
64
68
} )
65
69
} )
0 commit comments