Skip to content

Commit b0fd554

Browse files
committed
refactor: add constants.ts with PASSWORD, etc
1 parent 5857b25 commit b0fd554

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

test/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080"
2+
export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab"
3+
export const STORAGE = process.env.STORAGE || ""

test/e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ afterEach(async () => {
1717
})
1818

1919
it("should see the login page", async () => {
20-
await page.goto("http://localhost:8080")
20+
await page.goto(process.env)
2121
// It should send us to the login page
2222
expect(await page.title()).toBe("code-server login")
2323
})

test/globalSetup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// so that it authenticates us into code-server
33
// ensuring that we're logged in before we run any tests
44
import { chromium } from "playwright"
5+
import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
56

67
module.exports = async () => {
78
console.log("🚨 Running Global Setup for Jest Tests")
@@ -10,9 +11,9 @@ module.exports = async () => {
1011
const context = await browser.newContext()
1112
const page = await context.newPage()
1213

13-
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "domcontentloaded" })
14+
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" })
1415
// Type in password
15-
await page.fill(".password", process.env.PASSWORD || "password")
16+
await page.fill(".password", PASSWORD)
1617
// Click the submit button and login
1718
await page.click(".submit")
1819

test/goHome.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright"
22
import { createCookieIfDoesntExist } from "../src/common/util"
33
import { hash } from "../src/node/util"
4+
import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE } from "./constants"
45

56
async function setTimeoutPromise(milliseconds: number): Promise<void> {
67
return new Promise((resolve, _) => {
@@ -18,12 +19,12 @@ describe("go home", () => {
1819
beforeAll(async () => {
1920
browser = await chromium.launch()
2021
// Create a new context with the saved storage state
21-
const storageState = JSON.parse(process.env.STORAGE || "{}")
22+
const storageState = JSON.parse(STORAGE) || {}
2223

2324
const cookieToStore = {
2425
sameSite: "Lax" as const,
2526
name: "key",
26-
value: hash(process.env.PASSWORD || ""),
27+
value: hash(PASSWORD),
2728
domain: "localhost",
2829
path: "/",
2930
expires: -1,
@@ -72,7 +73,7 @@ describe("go home", () => {
7273
it("should see a 'Go Home' button in the Application Menu that goes to /healthz", async () => {
7374
let requestedGoHomeUrl = false
7475

75-
const GO_HOME_URL = `${process.env.CODE_SERVER_ADDRESS}/healthz`
76+
const GO_HOME_URL = `${CODE_SERVER_ADDRESS}/healthz`
7677
page.on("request", (request) => {
7778
// This ensures that we did make a request to the GO_HOME_URL
7879
// Most reliable way to test button
@@ -89,7 +90,7 @@ describe("go home", () => {
8990

9091
// waitUntil: "domcontentloaded"
9192
// In case the page takes a long time to load
92-
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "domcontentloaded" })
93+
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" })
9394

9495
// Click the Home menu
9596
await page.click(".home-bar ul[aria-label='Home'] li")

test/login.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { chromium, Page, Browser, BrowserContext } from "playwright"
2+
import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
23

34
describe("login", () => {
45
let browser: Browser
@@ -25,9 +26,9 @@ describe("login", () => {
2526
})
2627

2728
it("should be able to login", async () => {
28-
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080")
29+
await page.goto(CODE_SERVER_ADDRESS)
2930
// Type in password
30-
await page.fill(".password", process.env.PASSWORD || "password")
31+
await page.fill(".password", PASSWORD)
3132
// Click the submit button and login
3233
await page.click(".submit")
3334
// See the editor

test/util.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "../src/common/util"
2020
import { Cookie as CookieEnum } from "../src/node/routes/login"
2121
import { hash } from "../src/node/util"
22+
import { PASSWORD } from "./constants"
2223

2324
const dom = new JSDOM()
2425
global.document = dom.window.document
@@ -263,7 +264,6 @@ describe("util", () => {
263264

264265
describe("checkForCookie", () => {
265266
it("should check if the cookie exists and has a value", () => {
266-
const PASSWORD = "123supersecure!"
267267
const fakeCookies: Cookie[] = [
268268
{
269269
name: CookieEnum.Key,
@@ -286,7 +286,6 @@ describe("util", () => {
286286

287287
describe("createCookieIfDoesntExist", () => {
288288
it("should create a cookie if it doesn't exist", () => {
289-
const PASSWORD = "123supersecure"
290289
const cookies: Cookie[] = []
291290
const cookieToStore = {
292291
name: CookieEnum.Key,

0 commit comments

Comments
 (0)