diff --git a/test/constants.ts b/test/constants.ts new file mode 100644 index 000000000..ac2250e1c --- /dev/null +++ b/test/constants.ts @@ -0,0 +1,3 @@ +export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080" +export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab" +export const STORAGE = process.env.STORAGE || "" diff --git a/test/e2e.test.ts b/test/e2e.test.ts index b7cf3739e..915b111cb 100644 --- a/test/e2e.test.ts +++ b/test/e2e.test.ts @@ -17,7 +17,7 @@ afterEach(async () => { }) it("should see the login page", async () => { - await page.goto("http://localhost:8080") + await page.goto(process.env) // It should send us to the login page expect(await page.title()).toBe("code-server login") }) diff --git a/test/globalSetup.ts b/test/globalSetup.ts index dcf5047dd..8a9746884 100644 --- a/test/globalSetup.ts +++ b/test/globalSetup.ts @@ -2,6 +2,7 @@ // so that it authenticates us into code-server // ensuring that we're logged in before we run any tests import { chromium } from "playwright" +import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants" module.exports = async () => { console.log("🚨 Running Global Setup for Jest Tests") @@ -10,9 +11,9 @@ module.exports = async () => { const context = await browser.newContext() const page = await context.newPage() - await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "domcontentloaded" }) + await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" }) // Type in password - await page.fill(".password", process.env.PASSWORD || "password") + await page.fill(".password", PASSWORD) // Click the submit button and login await page.click(".submit") diff --git a/test/goHome.test.ts b/test/goHome.test.ts index 86431c56f..e9a56dd57 100644 --- a/test/goHome.test.ts +++ b/test/goHome.test.ts @@ -1,6 +1,7 @@ import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright" import { createCookieIfDoesntExist } from "../src/common/util" import { hash } from "../src/node/util" +import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE } from "./constants" async function setTimeoutPromise(milliseconds: number): Promise { return new Promise((resolve, _) => { @@ -18,12 +19,12 @@ describe("go home", () => { beforeAll(async () => { browser = await chromium.launch() // Create a new context with the saved storage state - const storageState = JSON.parse(process.env.STORAGE || "{}") + const storageState = JSON.parse(STORAGE) || {} const cookieToStore = { sameSite: "Lax" as const, name: "key", - value: hash(process.env.PASSWORD || ""), + value: hash(PASSWORD), domain: "localhost", path: "/", expires: -1, @@ -72,7 +73,7 @@ describe("go home", () => { it("should see a 'Go Home' button in the Application Menu that goes to /healthz", async () => { let requestedGoHomeUrl = false - const GO_HOME_URL = `${process.env.CODE_SERVER_ADDRESS}/healthz` + const GO_HOME_URL = `${CODE_SERVER_ADDRESS}/healthz` page.on("request", (request) => { // This ensures that we did make a request to the GO_HOME_URL // Most reliable way to test button @@ -89,7 +90,7 @@ describe("go home", () => { // waitUntil: "domcontentloaded" // In case the page takes a long time to load - await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "domcontentloaded" }) + await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" }) // Click the Home menu await page.click(".home-bar ul[aria-label='Home'] li") diff --git a/test/login.test.ts b/test/login.test.ts index 5358adaa9..b269acbd8 100644 --- a/test/login.test.ts +++ b/test/login.test.ts @@ -1,4 +1,5 @@ import { chromium, Page, Browser, BrowserContext } from "playwright" +import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants" describe("login", () => { let browser: Browser @@ -25,9 +26,9 @@ describe("login", () => { }) it("should be able to login", async () => { - await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080") + await page.goto(CODE_SERVER_ADDRESS) // Type in password - await page.fill(".password", process.env.PASSWORD || "password") + await page.fill(".password", PASSWORD) // Click the submit button and login await page.click(".submit") // See the editor diff --git a/test/util.test.ts b/test/util.test.ts index 91a4315f6..535b60a13 100644 --- a/test/util.test.ts +++ b/test/util.test.ts @@ -19,6 +19,7 @@ import { } from "../src/common/util" import { Cookie as CookieEnum } from "../src/node/routes/login" import { hash } from "../src/node/util" +import { PASSWORD } from "./constants" const dom = new JSDOM() global.document = dom.window.document @@ -263,7 +264,6 @@ describe("util", () => { describe("checkForCookie", () => { it("should check if the cookie exists and has a value", () => { - const PASSWORD = "123supersecure!" const fakeCookies: Cookie[] = [ { name: CookieEnum.Key, @@ -286,7 +286,6 @@ describe("util", () => { describe("createCookieIfDoesntExist", () => { it("should create a cookie if it doesn't exist", () => { - const PASSWORD = "123supersecure" const cookies: Cookie[] = [] const cookieToStore = { name: CookieEnum.Key,