@@ -5,26 +5,29 @@ describe("login", () => {
55 let page : Page
66 let context : BrowserContext
77
8- beforeAll ( async ( ) => {
8+ beforeAll ( async ( done ) => {
99 browser = await chromium . launch ( )
1010 // Create a new context with the saved storage state
1111 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 ( )
1314 } )
1415
15- afterAll ( async ( ) => {
16+ afterAll ( async ( done ) => {
1617 // Remove password from local storage
1718 await context . clearCookies ( )
1819
1920 await browser . close ( )
2021 await context . close ( )
22+ done ( )
2123 } )
2224
23- beforeEach ( async ( ) => {
25+ beforeEach ( async ( done ) => {
2426 page = await context . newPage ( )
27+ done ( )
2528 } )
2629
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 ) => {
2831 const GO_HOME_URL = `${ process . env . CODE_SERVER_ADDRESS } /healthz`
2932 let requestedGoHomeUrl = false
3033 page . on ( "request" , ( request ) => {
@@ -34,36 +37,43 @@ describe("login", () => {
3437 // only that it was made
3538 if ( request . url ( ) === GO_HOME_URL ) {
3639 requestedGoHomeUrl = true
37- console . log ( "woooo =>>>" , requestedGoHomeUrl )
40+ expect ( requestedGoHomeUrl ) . toBeTruthy ( )
41+
42+ // This ensures Jest knows we're done here.
43+ done ( )
3844 }
3945 } )
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 ( ) )
4050
4151 // waitUntil: "domcontentloaded"
4252 // In case the page takes a long time to load
4353 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+
4468 // Click the Application menu
4569 await page . click ( ".menubar-menu-button[title='Application Menu']" )
4670 // See the Go Home button
4771 const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
4872 expect ( await page . isVisible ( goHomeButton ) )
49- // Click it and navigate to coder.com
73+
74+ // Click it and navigate to /healthz
5075 // NOTE: ran into issues of it failing intermittently
5176 // without having button: "middle"
5277 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()
6878 } )
6979} )
0 commit comments