Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 37d2643

Browse files
committedApr 23, 2021
refactor: tmpdir and add to test utils
1 parent f2e49dd commit 37d2643

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed
 

‎test/e2e/terminal.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { test, expect } from "@playwright/test"
22
import * as fs from "fs"
3-
import { tmpdir } from "os"
3+
// import { tmpdir } from "os"
44
import * as path from "path"
55
import util from "util"
66
import * as cp from "child_process"
7-
import { STORAGE } from "../utils/constants"
7+
import { STORAGE, tmpdir } from "../utils/constants"
88
import { CodeServer } from "./models/CodeServer"
99

1010
test.describe("Integrated Terminal", () => {
@@ -33,7 +33,7 @@ test.describe("Integrated Terminal", () => {
3333
// We're not using tmpdir from src/node/constants
3434
// because Playwright doesn't fully support ES modules from
3535
// the erorrs I'm seeing
36-
tmpFolderPath = fs.mkdtempSync(path.join(tmpdir(), "code-server-test"))
36+
tmpFolderPath = await tmpdir("integrated-terminal")
3737
tmpFile = path.join(tmpFolderPath, testFileName)
3838
})
3939

‎test/unit/constants.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import * as fs from "fs"
12
import { commit, getPackageJson, version } from "../../src/node/constants"
3+
import { tmpdir } from "../../test/utils/constants"
24
import { loggerModule } from "../utils/helpers"
35

46
// jest.mock is hoisted above the imports so we must use `require` here.
@@ -51,3 +53,16 @@ describe("constants", () => {
5153
})
5254
})
5355
})
56+
57+
describe("test constants", () => {
58+
describe("tmpdir", () => {
59+
it("should return a temp directory", async () => {
60+
const testName = "temp-dir"
61+
const pathToTempDir = await tmpdir(testName)
62+
63+
expect(pathToTempDir).toContain(testName)
64+
65+
await fs.rmdir(pathToTempDir, () => {})
66+
})
67+
})
68+
})

‎test/utils/constants.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import * as os from "os"
2+
import * as path from "path"
3+
import * as fs from "fs"
4+
15
export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080"
26
export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab"
37
export const STORAGE = process.env.STORAGE || ""
8+
9+
export async function tmpdir(testName: string): Promise<string> {
10+
const dir = path.join(os.tmpdir(), "code-server")
11+
await fs.mkdir(dir, { recursive: true }, () => {})
12+
13+
return await fs.promises.mkdtemp(path.join(dir, `test-${testName}-`), { encoding: "utf8" })
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.