diff --git a/ci/dev/test.sh b/ci/dev/test.sh index 70434db1..6520176d 100755 --- a/ci/dev/test.sh +++ b/ci/dev/test.sh @@ -17,7 +17,8 @@ main() { echo " \$PASSWORD" echo " \$CODE_SERVER_ADDRESS" echo -e "\n" - echo "Please make sure you have code-server running locally." + echo "Please make sure you have code-server running locally with the flag:" + echo " --home \$CODE_SERVER_ADDRESS/healthz " echo -e "\n" exit 1 fi diff --git a/src/common/util.ts b/src/common/util.ts index d0e03ab3..9b6418da 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -140,8 +140,8 @@ export interface Cookie { * Checks if a cookie exists in array of cookies */ export function checkForCookie(cookies: Array, key: string): boolean { - // Check for at least one cookie where the name is equal to key - return cookies.filter((cookie) => cookie.name === key).length > 0 + // Check for a cookie where the name is equal to key + return Boolean(cookies.find((cookie) => cookie.name === key)) } /** diff --git a/test/goHome.test.ts b/test/goHome.test.ts index b8646bc3..57712e5a 100644 --- a/test/goHome.test.ts +++ b/test/goHome.test.ts @@ -12,7 +12,6 @@ describe("login", () => { // Create a new context with the saved storage state const storageState = JSON.parse(process.env.STORAGE || "") - // const cookieToStore = { sameSite: "Lax" as const, name: "key", @@ -61,16 +60,20 @@ describe("login", () => { // NOTE: this test will fail if you do not run code-server with --home $CODE_SERVER_ADDRESS/healthz it("should see a 'Go Home' button in the Application Menu that goes to /healthz", async (done) => { + let requestedGoHomeUrl = false // Ideally, this test should pass and finish before the timeout set in the Jest config // However, if it doesn't, we don't want a memory leak so we set this backup timeout // Otherwise Jest may throw this error // "Jest did not exit one second after the test run has completed. // This usually means that there are asynchronous operations that weren't stopped in your tests. // Consider running Jest with `--detectOpenHandles` to troubleshoot this issue." - const backupTimeout = setTimeout(() => done(), 20000) + const backupTimeout = setTimeout(() => { + // If it's not true by this point then the test should fail + expect(requestedGoHomeUrl).toBeTruthy() + done() + }, 20000) const GO_HOME_URL = `${process.env.CODE_SERVER_ADDRESS}/healthz` - let requestedGoHomeUrl = false page.on("request", (request) => { // This ensures that we did make a request to the GO_HOME_URL // Most reliable way to test button