diff --git a/src/node/constants.ts b/src/node/constants.ts index c39beb05e..c198f8fb3 100644 --- a/src/node/constants.ts +++ b/src/node/constants.ts @@ -1,5 +1,6 @@ import { logger } from "@coder/logger" import { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package" +import * as os from "os" import * as path from "path" export function getPackageJson(relativePath: string): JSONSchemaForNPMPackageJsonFiles { @@ -18,3 +19,4 @@ const pkg = getPackageJson("../../package.json") export const version = pkg.version || "development" export const commit = pkg.commit || "development" export const rootPath = path.resolve(__dirname, "../..") +export const tmpdir = path.join(os.tmpdir(), "code-server") diff --git a/src/node/socket.ts b/src/node/socket.ts index 5885f7fde..9c937bbb5 100644 --- a/src/node/socket.ts +++ b/src/node/socket.ts @@ -4,7 +4,8 @@ import * as path from "path" import * as tls from "tls" import { Emitter } from "../common/emitter" import { generateUuid } from "../common/util" -import { canConnect, tmpdir } from "./util" +import { tmpdir } from "./constants" +import { canConnect } from "./util" /** * Provides a way to proxy a TLS socket. Can be used when you need to pass a diff --git a/src/node/util.ts b/src/node/util.ts index e8ec311ed..380e32b9b 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -8,8 +8,6 @@ import * as path from "path" import * as util from "util" import xdgBasedir from "xdg-basedir" -export const tmpdir = path.join(os.tmpdir(), "code-server") - interface Paths { data: string config: string diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index 7fbf37060..8e2de3161 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -16,23 +16,23 @@ export class CodeServer { async navigate() { await this.page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) - let editorIsVisible = await this.isEditorVisible() + const editorIsVisible = await this.isEditorVisible() let reloadCount = 0 // Occassionally code-server timeouts in Firefox // we're not sure why // but usually a reload or two fixes it // TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues - // TODO@jsjoeio sometimes it's 2 reloads, othertimes it's 9 - // double-check this logic while (!editorIsVisible) { reloadCount += 1 - editorIsVisible = await this.isEditorVisible() - if (editorIsVisible) { - console.log(`Editor became visible after ${reloadCount} reloads`) + if (await this.isEditorVisible()) { + console.log(` Editor became visible after ${reloadCount} reloads`) break } - await this.page.reload({ waitUntil: "networkidle" }) + // When a reload happens, we want to wait for all resources to be + // loaded completely. Hence why we use that instead of DOMContentLoaded + // Read more: https://thisthat.dev/dom-content-loaded-vs-load/ + await this.page.reload({ waitUntil: "load" }) } } diff --git a/test/e2e/terminal.test.ts b/test/e2e/terminal.test.ts index 9fb31bcfd..0e1af1e48 100644 --- a/test/e2e/terminal.test.ts +++ b/test/e2e/terminal.test.ts @@ -29,6 +29,10 @@ test.describe("Integrated Terminal", () => { }) test("should echo a string to a file", options, async ({ page }) => { + // NOTE@jsjoeio + // We're not using tmpdir from src/node/constants + // because Playwright doesn't fully support ES modules from + // the erorrs I'm seeing const tmpFolderPath = fs.mkdtempSync(path.join(tmpdir(), "code-server-test")) const tmpFile = `${tmpFolderPath}${path.sep}${testFileName}` // Open terminal and type in value diff --git a/test/unit/cli.test.ts b/test/unit/cli.test.ts index 27498cf00..38d8dc7b9 100644 --- a/test/unit/cli.test.ts +++ b/test/unit/cli.test.ts @@ -4,7 +4,8 @@ import * as net from "net" import * as os from "os" import * as path from "path" import { Args, parse, setDefaults, shouldOpenInExistingInstance } from "../../src/node/cli" -import { paths, tmpdir } from "../../src/node/util" +import { tmpdir } from "../../src/node/constants" +import { paths } from "../../src/node/util" type Mutable = { -readonly [P in keyof T]: T[P] diff --git a/test/unit/socket.test.ts b/test/unit/socket.test.ts index 4fedf5a84..9b8749f53 100644 --- a/test/unit/socket.test.ts +++ b/test/unit/socket.test.ts @@ -4,8 +4,9 @@ import * as net from "net" import * as path from "path" import * as tls from "tls" import { Emitter } from "../../src/common/emitter" +import { tmpdir } from "../../src/node/constants" import { SocketProxyProvider } from "../../src/node/socket" -import { generateCertificate, tmpdir } from "../../src/node/util" +import { generateCertificate } from "../../src/node/util" describe("SocketProxyProvider", () => { const provider = new SocketProxyProvider() diff --git a/test/unit/update.test.ts b/test/unit/update.test.ts index 2f73f80df..394371201 100644 --- a/test/unit/update.test.ts +++ b/test/unit/update.test.ts @@ -1,9 +1,9 @@ import { promises as fs } from "fs" import * as http from "http" import * as path from "path" +import { tmpdir } from "../../src/node/constants" import { SettingsProvider, UpdateSettings } from "../../src/node/settings" import { LatestResponse, UpdateProvider } from "../../src/node/update" -import { tmpdir } from "../../src/node/util" describe.skip("update", () => { let version = "1.0.0"