From 47a05c998a2a81d7d6ef9ce876dcfd8e0c26a0d8 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 12 Feb 2021 13:43:11 -0600 Subject: [PATCH] Gate wtfnode behind WTF_NODE env var After thinking about it some more it's probably mostly only useful to see the output when the tests are hanging. Otherwise there's a lot of noise about Jest child processes and pipes. --- package.json | 3 --- src/common/util.ts | 22 ---------------------- test/e2e.test.ts | 3 ++- test/globalSetup.ts | 8 +++++--- test/goHome.test.ts | 2 +- test/helpers.ts | 21 +++++++++++++++++++++ test/util.test.ts | 3 +-- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 1df87c1ac..7f427a78e 100644 --- a/package.json +++ b/package.json @@ -143,9 +143,6 @@ "lines": 40 } }, - "modulePathIgnorePatterns": [ - "/release" - ], "testTimeout": 30000, "globalSetup": "/test/globalSetup.ts", "modulePathIgnorePatterns": [ diff --git a/src/common/util.ts b/src/common/util.ts index e8edc13bb..87ca6f596 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -1,5 +1,4 @@ import { logger, field } from "@coder/logger" -import { Cookie } from "../../test/helpers" export interface Options { base: string @@ -121,24 +120,3 @@ export function logError(prefix: string, err: any): void { logger.error(`${prefix}: ${err}`) } } - -/** - * Checks if a cookie exists in array of cookies - */ -export function checkForCookie(cookies: Array, key: string): boolean { - // Check for a cookie where the name is equal to key - return Boolean(cookies.find((cookie) => cookie.name === key)) -} - -/** - * Creates a login cookie if one doesn't already exist - */ -export function createCookieIfDoesntExist(cookies: Array, cookieToStore: Cookie): Array { - const cookieName = cookieToStore.name - const doesCookieExist = checkForCookie(cookies, cookieName) - if (!doesCookieExist) { - const updatedCookies = [...cookies, cookieToStore] - return updatedCookies - } - return cookies -} diff --git a/test/e2e.test.ts b/test/e2e.test.ts index 915b111cb..21df386ba 100644 --- a/test/e2e.test.ts +++ b/test/e2e.test.ts @@ -1,4 +1,5 @@ import { chromium, Page, Browser } from "playwright" +import { CODE_SERVER_ADDRESS } from "./constants" let browser: Browser let page: Page @@ -17,7 +18,7 @@ afterEach(async () => { }) it("should see the login page", async () => { - await page.goto(process.env) + await page.goto(CODE_SERVER_ADDRESS) // 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 a3cd485eb..5ef45faac 100644 --- a/test/globalSetup.ts +++ b/test/globalSetup.ts @@ -6,13 +6,15 @@ import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants" import * as wtfnode from "./wtfnode" module.exports = async () => { - console.log("🚨 Running Global Setup for Jest Tests") - console.log(" Please hang tight...") + console.log("\n🚨 Running Global Setup for Jest Tests") + console.log(" Please hang tight...") const browser = await chromium.launch() const context = await browser.newContext() const page = await context.newPage() - wtfnode.setup() + if (process.env.WTF_NODE) { + wtfnode.setup() + } await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" }) // Type in password diff --git a/test/goHome.test.ts b/test/goHome.test.ts index dde204752..31cd773c6 100644 --- a/test/goHome.test.ts +++ b/test/goHome.test.ts @@ -1,7 +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" +import { createCookieIfDoesntExist } from "./helpers" describe("go home", () => { let browser: Browser diff --git a/test/helpers.ts b/test/helpers.ts index 07a859964..193fd0cad 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -12,3 +12,24 @@ export interface Cookie { secure: boolean sameSite: "Strict" | "Lax" | "None" } + +/** + * Checks if a cookie exists in array of cookies + */ +export function checkForCookie(cookies: Array, key: string): boolean { + // Check for a cookie where the name is equal to key + return Boolean(cookies.find((cookie) => cookie.name === key)) +} + +/** + * Creates a login cookie if one doesn't already exist + */ +export function createCookieIfDoesntExist(cookies: Array, cookieToStore: Cookie): Array { + const cookieName = cookieToStore.name + const doesCookieExist = checkForCookie(cookies, cookieName) + if (!doesCookieExist) { + const updatedCookies = [...cookies, cookieToStore] + return updatedCookies + } + return cookies +} diff --git a/test/util.test.ts b/test/util.test.ts index 535b60a13..0de2d7eaa 100644 --- a/test/util.test.ts +++ b/test/util.test.ts @@ -13,13 +13,12 @@ import { resolveBase, split, trimSlashes, - checkForCookie, - createCookieIfDoesntExist, normalize, } from "../src/common/util" import { Cookie as CookieEnum } from "../src/node/routes/login" import { hash } from "../src/node/util" import { PASSWORD } from "./constants" +import { checkForCookie, createCookieIfDoesntExist } from "./helpers" const dom = new JSDOM() global.document = dom.window.document