Skip to content

Commit 47a05c9

Browse files
code-asherjsjoeio
authored andcommitted
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.
1 parent 6685b3a commit 47a05c9

File tree

7 files changed

+30
-32
lines changed

7 files changed

+30
-32
lines changed

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@
143143
"lines": 40
144144
}
145145
},
146-
"modulePathIgnorePatterns": [
147-
"<rootDir>/release"
148-
],
149146
"testTimeout": 30000,
150147
"globalSetup": "<rootDir>/test/globalSetup.ts",
151148
"modulePathIgnorePatterns": [

src/common/util.ts

-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { logger, field } from "@coder/logger"
2-
import { Cookie } from "../../test/helpers"
32

43
export interface Options {
54
base: string
@@ -121,24 +120,3 @@ export function logError(prefix: string, err: any): void {
121120
logger.error(`${prefix}: ${err}`)
122121
}
123122
}
124-
125-
/**
126-
* Checks if a cookie exists in array of cookies
127-
*/
128-
export function checkForCookie(cookies: Array<Cookie>, key: string): boolean {
129-
// Check for a cookie where the name is equal to key
130-
return Boolean(cookies.find((cookie) => cookie.name === key))
131-
}
132-
133-
/**
134-
* Creates a login cookie if one doesn't already exist
135-
*/
136-
export function createCookieIfDoesntExist(cookies: Array<Cookie>, cookieToStore: Cookie): Array<Cookie> {
137-
const cookieName = cookieToStore.name
138-
const doesCookieExist = checkForCookie(cookies, cookieName)
139-
if (!doesCookieExist) {
140-
const updatedCookies = [...cookies, cookieToStore]
141-
return updatedCookies
142-
}
143-
return cookies
144-
}

test/e2e.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { chromium, Page, Browser } from "playwright"
2+
import { CODE_SERVER_ADDRESS } from "./constants"
23

34
let browser: Browser
45
let page: Page
@@ -17,7 +18,7 @@ afterEach(async () => {
1718
})
1819

1920
it("should see the login page", async () => {
20-
await page.goto(process.env)
21+
await page.goto(CODE_SERVER_ADDRESS)
2122
// It should send us to the login page
2223
expect(await page.title()).toBe("code-server login")
2324
})

test/globalSetup.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
66
import * as wtfnode from "./wtfnode"
77

88
module.exports = async () => {
9-
console.log("🚨 Running Global Setup for Jest Tests")
10-
console.log(" Please hang tight...")
9+
console.log("\n🚨 Running Global Setup for Jest Tests")
10+
console.log(" Please hang tight...")
1111
const browser = await chromium.launch()
1212
const context = await browser.newContext()
1313
const page = await context.newPage()
1414

15-
wtfnode.setup()
15+
if (process.env.WTF_NODE) {
16+
wtfnode.setup()
17+
}
1618

1719
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" })
1820
// Type in password

test/goHome.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright"
2-
import { createCookieIfDoesntExist } from "../src/common/util"
32
import { hash } from "../src/node/util"
43
import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE } from "./constants"
4+
import { createCookieIfDoesntExist } from "./helpers"
55

66
describe("go home", () => {
77
let browser: Browser

test/helpers.ts

+21
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,24 @@ export interface Cookie {
1212
secure: boolean
1313
sameSite: "Strict" | "Lax" | "None"
1414
}
15+
16+
/**
17+
* Checks if a cookie exists in array of cookies
18+
*/
19+
export function checkForCookie(cookies: Array<Cookie>, key: string): boolean {
20+
// Check for a cookie where the name is equal to key
21+
return Boolean(cookies.find((cookie) => cookie.name === key))
22+
}
23+
24+
/**
25+
* Creates a login cookie if one doesn't already exist
26+
*/
27+
export function createCookieIfDoesntExist(cookies: Array<Cookie>, cookieToStore: Cookie): Array<Cookie> {
28+
const cookieName = cookieToStore.name
29+
const doesCookieExist = checkForCookie(cookies, cookieName)
30+
if (!doesCookieExist) {
31+
const updatedCookies = [...cookies, cookieToStore]
32+
return updatedCookies
33+
}
34+
return cookies
35+
}

test/util.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ import {
1313
resolveBase,
1414
split,
1515
trimSlashes,
16-
checkForCookie,
17-
createCookieIfDoesntExist,
1816
normalize,
1917
} from "../src/common/util"
2018
import { Cookie as CookieEnum } from "../src/node/routes/login"
2119
import { hash } from "../src/node/util"
2220
import { PASSWORD } from "./constants"
21+
import { checkForCookie, createCookieIfDoesntExist } from "./helpers"
2322

2423
const dom = new JSDOM()
2524
global.document = dom.window.document

0 commit comments

Comments
 (0)