@@ -5,26 +5,29 @@ describe("login", () => {
5
5
let page : Page
6
6
let context : BrowserContext
7
7
8
- beforeAll ( async ( ) => {
8
+ beforeAll ( async ( done ) => {
9
9
browser = await chromium . launch ( )
10
10
// Create a new context with the saved storage state
11
11
const storageState = JSON . parse ( process . env . STORAGE || "" )
12
- context = await browser . newContext ( { storageState } )
12
+ context = await browser . newContext ( { storageState, recordVideo : { dir : "./test/videos/" } } )
13
+ done ( )
13
14
} )
14
15
15
- afterAll ( async ( ) => {
16
+ afterAll ( async ( done ) => {
16
17
// Remove password from local storage
17
18
await context . clearCookies ( )
18
19
19
20
await browser . close ( )
20
21
await context . close ( )
22
+ done ( )
21
23
} )
22
24
23
- beforeEach ( async ( ) => {
25
+ beforeEach ( async ( done ) => {
24
26
page = await context . newPage ( )
27
+ done ( )
25
28
} )
26
29
27
- it ( "should see a 'Go Home' button in the Application Menu that goes to coder.com " , async ( ) => {
30
+ it ( "should see a 'Go Home' button in the Application Menu that goes to /healthz " , async ( done ) => {
28
31
const GO_HOME_URL = `${ process . env . CODE_SERVER_ADDRESS } /healthz`
29
32
let requestedGoHomeUrl = false
30
33
page . on ( "request" , ( request ) => {
@@ -34,36 +37,43 @@ describe("login", () => {
34
37
// only that it was made
35
38
if ( request . url ( ) === GO_HOME_URL ) {
36
39
requestedGoHomeUrl = true
37
- console . log ( "woooo =>>>" , requestedGoHomeUrl )
40
+ expect ( requestedGoHomeUrl ) . toBeTruthy ( )
41
+
42
+ // This ensures Jest knows we're done here.
43
+ done ( )
38
44
}
39
45
} )
46
+ // Sometimes a dialog shows up when you navigate
47
+ // asking if you're sure you want to leave
48
+ // so we listen if it comes, we accept it
49
+ page . on ( "dialog" , ( dialog ) => dialog . accept ( ) )
40
50
41
51
// waitUntil: "domcontentloaded"
42
52
// In case the page takes a long time to load
43
53
await page . goto ( process . env . CODE_SERVER_ADDRESS || "http://localhost:8080" , { waitUntil : "domcontentloaded" } )
54
+
55
+ // For some odd reason, the login method used in globalSetup.ts
56
+ // I don't know if it's on playwright clearing our cookies by accident
57
+ // or if it's our cookies disappearing.
58
+ // This means we need an additional check to make sure we're logged in
59
+ // otherwise this test will hang and fail.
60
+ const currentPageURL = await page . url ( )
61
+ const isLoginPage = currentPageURL . includes ( "login" )
62
+ if ( isLoginPage ) {
63
+ await page . fill ( ".password" , process . env . PASSWORD || "password" )
64
+ // Click the submit button and login
65
+ await page . click ( ".submit" )
66
+ }
67
+
44
68
// Click the Application menu
45
69
await page . click ( ".menubar-menu-button[title='Application Menu']" )
46
70
// See the Go Home button
47
71
const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
48
72
expect ( await page . isVisible ( goHomeButton ) )
49
- // Click it and navigate to coder.com
73
+
74
+ // Click it and navigate to /healthz
50
75
// NOTE: ran into issues of it failing intermittently
51
76
// without having button: "middle"
52
77
await page . click ( goHomeButton , { button : "middle" } )
53
-
54
- // If there are unsaved changes it will show a dialog
55
- // asking if you're sure you want to leave
56
- await page . on ( "dialog" , ( dialog ) => dialog . accept ( ) )
57
-
58
- // If it takes longer than 3 seconds to navigate, something is wrong
59
- await page . waitForRequest ( GO_HOME_URL , { timeout : 10000 } )
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()
68
78
} )
69
79
} )
0 commit comments