refactor: add constants.ts with PASSWORD, etc
This commit is contained in:
parent
5857b25079
commit
b0fd55463b
|
@ -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 || ""
|
|
@ -17,7 +17,7 @@ afterEach(async () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should see the login page", 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
|
// It should send us to the login page
|
||||||
expect(await page.title()).toBe("code-server login")
|
expect(await page.title()).toBe("code-server login")
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// so that it authenticates us into code-server
|
// so that it authenticates us into code-server
|
||||||
// ensuring that we're logged in before we run any tests
|
// ensuring that we're logged in before we run any tests
|
||||||
import { chromium } from "playwright"
|
import { chromium } from "playwright"
|
||||||
|
import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
|
||||||
|
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
console.log("🚨 Running Global Setup for Jest Tests")
|
console.log("🚨 Running Global Setup for Jest Tests")
|
||||||
|
@ -10,9 +11,9 @@ module.exports = async () => {
|
||||||
const context = await browser.newContext()
|
const context = await browser.newContext()
|
||||||
const page = await context.newPage()
|
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
|
// Type in password
|
||||||
await page.fill(".password", process.env.PASSWORD || "password")
|
await page.fill(".password", PASSWORD)
|
||||||
// Click the submit button and login
|
// Click the submit button and login
|
||||||
await page.click(".submit")
|
await page.click(".submit")
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright"
|
import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright"
|
||||||
import { createCookieIfDoesntExist } from "../src/common/util"
|
import { createCookieIfDoesntExist } from "../src/common/util"
|
||||||
import { hash } from "../src/node/util"
|
import { hash } from "../src/node/util"
|
||||||
|
import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE } from "./constants"
|
||||||
|
|
||||||
async function setTimeoutPromise(milliseconds: number): Promise<void> {
|
async function setTimeoutPromise(milliseconds: number): Promise<void> {
|
||||||
return new Promise((resolve, _) => {
|
return new Promise((resolve, _) => {
|
||||||
|
@ -18,12 +19,12 @@ describe("go home", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
browser = await chromium.launch()
|
browser = await chromium.launch()
|
||||||
// Create a new context with the saved storage state
|
// Create a new context with the saved storage state
|
||||||
const storageState = JSON.parse(process.env.STORAGE || "{}")
|
const storageState = JSON.parse(STORAGE) || {}
|
||||||
|
|
||||||
const cookieToStore = {
|
const cookieToStore = {
|
||||||
sameSite: "Lax" as const,
|
sameSite: "Lax" as const,
|
||||||
name: "key",
|
name: "key",
|
||||||
value: hash(process.env.PASSWORD || ""),
|
value: hash(PASSWORD),
|
||||||
domain: "localhost",
|
domain: "localhost",
|
||||||
path: "/",
|
path: "/",
|
||||||
expires: -1,
|
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 () => {
|
it("should see a 'Go Home' button in the Application Menu that goes to /healthz", async () => {
|
||||||
let requestedGoHomeUrl = false
|
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) => {
|
page.on("request", (request) => {
|
||||||
// This ensures that we did make a request to the GO_HOME_URL
|
// This ensures that we did make a request to the GO_HOME_URL
|
||||||
// Most reliable way to test button
|
// Most reliable way to test button
|
||||||
|
@ -89,7 +90,7 @@ describe("go home", () => {
|
||||||
|
|
||||||
// waitUntil: "domcontentloaded"
|
// waitUntil: "domcontentloaded"
|
||||||
// In case the page takes a long time to load
|
// 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
|
// Click the Home menu
|
||||||
await page.click(".home-bar ul[aria-label='Home'] li")
|
await page.click(".home-bar ul[aria-label='Home'] li")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
import { chromium, Page, Browser, BrowserContext } from "playwright"
|
||||||
|
import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
|
||||||
|
|
||||||
describe("login", () => {
|
describe("login", () => {
|
||||||
let browser: Browser
|
let browser: Browser
|
||||||
|
@ -25,9 +26,9 @@ describe("login", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to login", async () => {
|
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
|
// Type in password
|
||||||
await page.fill(".password", process.env.PASSWORD || "password")
|
await page.fill(".password", PASSWORD)
|
||||||
// Click the submit button and login
|
// Click the submit button and login
|
||||||
await page.click(".submit")
|
await page.click(".submit")
|
||||||
// See the editor
|
// See the editor
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {
|
||||||
} from "../src/common/util"
|
} from "../src/common/util"
|
||||||
import { Cookie as CookieEnum } from "../src/node/routes/login"
|
import { Cookie as CookieEnum } from "../src/node/routes/login"
|
||||||
import { hash } from "../src/node/util"
|
import { hash } from "../src/node/util"
|
||||||
|
import { PASSWORD } from "./constants"
|
||||||
|
|
||||||
const dom = new JSDOM()
|
const dom = new JSDOM()
|
||||||
global.document = dom.window.document
|
global.document = dom.window.document
|
||||||
|
@ -263,7 +264,6 @@ describe("util", () => {
|
||||||
|
|
||||||
describe("checkForCookie", () => {
|
describe("checkForCookie", () => {
|
||||||
it("should check if the cookie exists and has a value", () => {
|
it("should check if the cookie exists and has a value", () => {
|
||||||
const PASSWORD = "123supersecure!"
|
|
||||||
const fakeCookies: Cookie[] = [
|
const fakeCookies: Cookie[] = [
|
||||||
{
|
{
|
||||||
name: CookieEnum.Key,
|
name: CookieEnum.Key,
|
||||||
|
@ -286,7 +286,6 @@ describe("util", () => {
|
||||||
|
|
||||||
describe("createCookieIfDoesntExist", () => {
|
describe("createCookieIfDoesntExist", () => {
|
||||||
it("should create a cookie if it doesn't exist", () => {
|
it("should create a cookie if it doesn't exist", () => {
|
||||||
const PASSWORD = "123supersecure"
|
|
||||||
const cookies: Cookie[] = []
|
const cookies: Cookie[] = []
|
||||||
const cookieToStore = {
|
const cookieToStore = {
|
||||||
name: CookieEnum.Key,
|
name: CookieEnum.Key,
|
||||||
|
|
Loading…
Reference in New Issue