Archived
1
0

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.
This commit is contained in:
Asher 2021-02-12 13:43:11 -06:00 committed by Joe Previte
parent 6685b3a4ff
commit 47a05c998a
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
7 changed files with 30 additions and 32 deletions

View File

@ -143,9 +143,6 @@
"lines": 40 "lines": 40
} }
}, },
"modulePathIgnorePatterns": [
"<rootDir>/release"
],
"testTimeout": 30000, "testTimeout": 30000,
"globalSetup": "<rootDir>/test/globalSetup.ts", "globalSetup": "<rootDir>/test/globalSetup.ts",
"modulePathIgnorePatterns": [ "modulePathIgnorePatterns": [

View File

@ -1,5 +1,4 @@
import { logger, field } from "@coder/logger" import { logger, field } from "@coder/logger"
import { Cookie } from "../../test/helpers"
export interface Options { export interface Options {
base: string base: string
@ -121,24 +120,3 @@ export function logError(prefix: string, err: any): void {
logger.error(`${prefix}: ${err}`) logger.error(`${prefix}: ${err}`)
} }
} }
/**
* Checks if a cookie exists in array of cookies
*/
export function checkForCookie(cookies: Array<Cookie>, 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<Cookie>, cookieToStore: Cookie): Array<Cookie> {
const cookieName = cookieToStore.name
const doesCookieExist = checkForCookie(cookies, cookieName)
if (!doesCookieExist) {
const updatedCookies = [...cookies, cookieToStore]
return updatedCookies
}
return cookies
}

View File

@ -1,4 +1,5 @@
import { chromium, Page, Browser } from "playwright" import { chromium, Page, Browser } from "playwright"
import { CODE_SERVER_ADDRESS } from "./constants"
let browser: Browser let browser: Browser
let page: Page let page: Page
@ -17,7 +18,7 @@ afterEach(async () => {
}) })
it("should see the login page", 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 // It should send us to the login page
expect(await page.title()).toBe("code-server login") expect(await page.title()).toBe("code-server login")
}) })

View File

@ -6,13 +6,15 @@ import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
import * as wtfnode from "./wtfnode" import * as wtfnode from "./wtfnode"
module.exports = async () => { module.exports = async () => {
console.log("🚨 Running Global Setup for Jest Tests") console.log("\n🚨 Running Global Setup for Jest Tests")
console.log(" Please hang tight...") console.log(" Please hang tight...")
const browser = await chromium.launch() const browser = await chromium.launch()
const context = await browser.newContext() const context = await browser.newContext()
const page = await context.newPage() const page = await context.newPage()
wtfnode.setup() if (process.env.WTF_NODE) {
wtfnode.setup()
}
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" }) await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" })
// Type in password // Type in password

View File

@ -1,7 +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 { hash } from "../src/node/util" import { hash } from "../src/node/util"
import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE } from "./constants" import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE } from "./constants"
import { createCookieIfDoesntExist } from "./helpers"
describe("go home", () => { describe("go home", () => {
let browser: Browser let browser: Browser

View File

@ -12,3 +12,24 @@ export interface Cookie {
secure: boolean secure: boolean
sameSite: "Strict" | "Lax" | "None" sameSite: "Strict" | "Lax" | "None"
} }
/**
* Checks if a cookie exists in array of cookies
*/
export function checkForCookie(cookies: Array<Cookie>, 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<Cookie>, cookieToStore: Cookie): Array<Cookie> {
const cookieName = cookieToStore.name
const doesCookieExist = checkForCookie(cookies, cookieName)
if (!doesCookieExist) {
const updatedCookies = [...cookies, cookieToStore]
return updatedCookies
}
return cookies
}

View File

@ -13,13 +13,12 @@ import {
resolveBase, resolveBase,
split, split,
trimSlashes, trimSlashes,
checkForCookie,
createCookieIfDoesntExist,
normalize, normalize,
} 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" import { PASSWORD } from "./constants"
import { checkForCookie, createCookieIfDoesntExist } from "./helpers"
const dom = new JSDOM() const dom = new JSDOM()
global.document = dom.window.document global.document = dom.window.document