@@ -2,15 +2,23 @@ import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright"
2
2
import { createCookieIfDoesntExist } from "../src/common/util"
3
3
import { hash } from "../src/node/util"
4
4
5
- describe ( "login" , ( ) => {
5
+ async function setTimeoutPromise ( milliseconds : number ) : Promise < void > {
6
+ return new Promise ( ( resolve , _ ) => {
7
+ setTimeout ( ( ) => {
8
+ resolve ( )
9
+ } , milliseconds )
10
+ } )
11
+ }
12
+
13
+ describe ( "go home" , ( ) => {
6
14
let browser : Browser
7
15
let page : Page
8
16
let context : BrowserContext
9
17
10
- beforeAll ( async ( done ) => {
18
+ beforeAll ( async ( ) => {
11
19
browser = await chromium . launch ( )
12
20
// Create a new context with the saved storage state
13
- const storageState = JSON . parse ( process . env . STORAGE || "" )
21
+ const storageState = JSON . parse ( process . env . STORAGE || "{} " )
14
22
15
23
const cookieToStore = {
16
24
sameSite : "Lax" as const ,
@@ -40,37 +48,23 @@ describe("login", () => {
40
48
storageState : { cookies : maybeUpdatedCookies } ,
41
49
recordVideo : { dir : "./test/videos/" } ,
42
50
} )
43
- done ( )
44
51
} )
45
52
46
- afterAll ( async ( done ) => {
53
+ afterAll ( async ( ) => {
47
54
// Remove password from local storage
48
55
await context . clearCookies ( )
49
56
50
57
await browser . close ( )
51
58
await context . close ( )
52
- done ( )
53
59
} )
54
60
55
- beforeEach ( async ( done ) => {
61
+ beforeEach ( async ( ) => {
56
62
page = await context . newPage ( )
57
- done ( )
58
63
} )
59
64
60
65
// NOTE: this test will fail if you do not run code-server with --home $CODE_SERVER_ADDRESS/healthz
61
- it ( "should see a 'Go Home' button in the Application Menu that goes to /healthz" , async ( done ) => {
66
+ it ( "should see a 'Go Home' button in the Application Menu that goes to /healthz" , async ( ) => {
62
67
let requestedGoHomeUrl = false
63
- // Ideally, this test should pass and finish before the timeout set in the Jest config
64
- // However, if it doesn't, we don't want a memory leak so we set this backup timeout
65
- // Otherwise Jest may throw this error
66
- // "Jest did not exit one second after the test run has completed.
67
- // This usually means that there are asynchronous operations that weren't stopped in your tests.
68
- // Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
69
- const backupTimeout = setTimeout ( ( ) => {
70
- // If it's not true by this point then the test should fail
71
- expect ( requestedGoHomeUrl ) . toBeTruthy ( )
72
- done ( )
73
- } , 20000 )
74
68
75
69
const GO_HOME_URL = `${ process . env . CODE_SERVER_ADDRESS } /healthz`
76
70
page . on ( "request" , ( request ) => {
@@ -80,11 +74,6 @@ describe("login", () => {
80
74
// only that it was made
81
75
if ( request . url ( ) === GO_HOME_URL ) {
82
76
requestedGoHomeUrl = true
83
- expect ( requestedGoHomeUrl ) . toBeTruthy ( )
84
- clearTimeout ( backupTimeout )
85
-
86
- // This ensures Jest knows we're done here.
87
- done ( )
88
77
}
89
78
} )
90
79
// Sometimes a dialog shows up when you navigate
@@ -105,6 +94,10 @@ describe("login", () => {
105
94
// Click it and navigate to /healthz
106
95
// NOTE: ran into issues of it failing intermittently
107
96
// without having button: "middle"
108
- await page . click ( goHomeButton , { button : "middle" } )
97
+ await Promise . all ( [
98
+ page . waitForNavigation ( ) ,
99
+ page . click ( goHomeButton , { button : "middle" } )
100
+ ] )
101
+ expect ( page . url ( ) ) . toBe ( GO_HOME_URL )
109
102
} )
110
103
} )
0 commit comments