Skip to content

Commit cb65590

Browse files
committed
refactor: move tmpdir into src/node/constants
1 parent cc99fdd commit cb65590

File tree

8 files changed

+20
-13
lines changed

8 files changed

+20
-13
lines changed

src/node/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { logger } from "@coder/logger"
22
import { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package"
3+
import * as os from "os"
34
import * as path from "path"
45

56
export function getPackageJson(relativePath: string): JSONSchemaForNPMPackageJsonFiles {
@@ -18,3 +19,4 @@ const pkg = getPackageJson("../../package.json")
1819
export const version = pkg.version || "development"
1920
export const commit = pkg.commit || "development"
2021
export const rootPath = path.resolve(__dirname, "../..")
22+
export const tmpdir = path.join(os.tmpdir(), "code-server")

src/node/socket.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import * as path from "path"
44
import * as tls from "tls"
55
import { Emitter } from "../common/emitter"
66
import { generateUuid } from "../common/util"
7-
import { canConnect, tmpdir } from "./util"
7+
import { tmpdir } from "./constants"
8+
import { canConnect } from "./util"
89

910
/**
1011
* Provides a way to proxy a TLS socket. Can be used when you need to pass a

src/node/util.ts

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import * as path from "path"
88
import * as util from "util"
99
import xdgBasedir from "xdg-basedir"
1010

11-
export const tmpdir = path.join(os.tmpdir(), "code-server")
12-
1311
interface Paths {
1412
data: string
1513
config: string

test/e2e/models/CodeServer.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ export class CodeServer {
1616
async navigate() {
1717
await this.page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
1818

19-
let editorIsVisible = await this.isEditorVisible()
19+
const editorIsVisible = await this.isEditorVisible()
2020
let reloadCount = 0
2121

2222
// Occassionally code-server timeouts in Firefox
2323
// we're not sure why
2424
// but usually a reload or two fixes it
2525
// TODO@jsjoeio @oxy look into Firefox reconnection/timeout issues
26-
// TODO@jsjoeio sometimes it's 2 reloads, othertimes it's 9
27-
// double-check this logic
2826
while (!editorIsVisible) {
2927
reloadCount += 1
30-
editorIsVisible = await this.isEditorVisible()
31-
if (editorIsVisible) {
32-
console.log(`Editor became visible after ${reloadCount} reloads`)
28+
if (await this.isEditorVisible()) {
29+
console.log(` Editor became visible after ${reloadCount} reloads`)
3330
break
3431
}
35-
await this.page.reload({ waitUntil: "networkidle" })
32+
// When a reload happens, we want to wait for all resources to be
33+
// loaded completely. Hence why we use that instead of DOMContentLoaded
34+
// Read more: https://thisthat.dev/dom-content-loaded-vs-load/
35+
await this.page.reload({ waitUntil: "load" })
3636
}
3737
}
3838

test/e2e/terminal.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ test.describe("Integrated Terminal", () => {
2929
})
3030

3131
test("should echo a string to a file", options, async ({ page }) => {
32+
// NOTE@jsjoeio
33+
// We're not using tmpdir from src/node/constants
34+
// because Playwright doesn't fully support ES modules from
35+
// the erorrs I'm seeing
3236
const tmpFolderPath = fs.mkdtempSync(path.join(tmpdir(), "code-server-test"))
3337
const tmpFile = `${tmpFolderPath}${path.sep}${testFileName}`
3438
// Open terminal and type in value

test/unit/cli.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import * as net from "net"
44
import * as os from "os"
55
import * as path from "path"
66
import { Args, parse, setDefaults, shouldOpenInExistingInstance } from "../../src/node/cli"
7-
import { paths, tmpdir } from "../../src/node/util"
7+
import { tmpdir } from "../../src/node/constants"
8+
import { paths } from "../../src/node/util"
89

910
type Mutable<T> = {
1011
-readonly [P in keyof T]: T[P]

test/unit/socket.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import * as net from "net"
44
import * as path from "path"
55
import * as tls from "tls"
66
import { Emitter } from "../../src/common/emitter"
7+
import { tmpdir } from "../../src/node/constants"
78
import { SocketProxyProvider } from "../../src/node/socket"
8-
import { generateCertificate, tmpdir } from "../../src/node/util"
9+
import { generateCertificate } from "../../src/node/util"
910

1011
describe("SocketProxyProvider", () => {
1112
const provider = new SocketProxyProvider()

test/unit/update.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { promises as fs } from "fs"
22
import * as http from "http"
33
import * as path from "path"
4+
import { tmpdir } from "../../src/node/constants"
45
import { SettingsProvider, UpdateSettings } from "../../src/node/settings"
56
import { LatestResponse, UpdateProvider } from "../../src/node/update"
6-
import { tmpdir } from "../../src/node/util"
77

88
describe.skip("update", () => {
99
let version = "1.0.0"

0 commit comments

Comments
 (0)