Move tmpdir test helper to test helpers file
This commit is contained in:
parent
0e4672f6b9
commit
52cf2fcf29
@ -1,10 +1,10 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
import { expect, test } from "@playwright/test"
|
||||
import * as cp from "child_process"
|
||||
import * as fs from "fs"
|
||||
// import { tmpdir } from "os"
|
||||
import * as path from "path"
|
||||
import util from "util"
|
||||
import { STORAGE, tmpdir } from "../utils/constants"
|
||||
import { STORAGE } from "../utils/constants"
|
||||
import { tmpdir } from "../utils/helpers"
|
||||
import { CodeServer } from "./models/CodeServer"
|
||||
|
||||
test.describe("Integrated Terminal", () => {
|
||||
|
@ -1,5 +1,3 @@
|
||||
import * as fs from "fs"
|
||||
import { tmpdir } from "../../test/utils/constants"
|
||||
import { loggerModule } from "../utils/helpers"
|
||||
|
||||
// jest.mock is hoisted above the imports so we must use `require` here.
|
||||
@ -89,16 +87,3 @@ describe("constants", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("test constants", () => {
|
||||
describe("tmpdir", () => {
|
||||
it("should return a temp directory", async () => {
|
||||
const testName = "temp-dir"
|
||||
const pathToTempDir = await tmpdir(testName)
|
||||
|
||||
expect(pathToTempDir).toContain(testName)
|
||||
|
||||
await fs.promises.rmdir(pathToTempDir)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
14
test/unit/helpers.test.ts
Normal file
14
test/unit/helpers.test.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { promises as fs } from "fs"
|
||||
import { tmpdir } from "../../test/utils/helpers"
|
||||
|
||||
/**
|
||||
* This file is for testing test helpers (not core code).
|
||||
*/
|
||||
describe("test helpers", () => {
|
||||
it("should return a temp directory", async () => {
|
||||
const testName = "temp-dir"
|
||||
const pathToTempDir = await tmpdir(testName)
|
||||
expect(pathToTempDir).toContain(testName)
|
||||
expect(fs.access(pathToTempDir)).resolves.toStrictEqual(undefined)
|
||||
})
|
||||
})
|
@ -1,14 +1,3 @@
|
||||
import * as fs from "fs"
|
||||
import * as os from "os"
|
||||
import * as path from "path"
|
||||
|
||||
export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080"
|
||||
export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab"
|
||||
export const STORAGE = process.env.STORAGE || ""
|
||||
|
||||
export async function tmpdir(testName: string): Promise<string> {
|
||||
const dir = path.join(os.tmpdir(), "code-server")
|
||||
await fs.promises.mkdir(dir, { recursive: true })
|
||||
|
||||
return await fs.promises.mkdtemp(path.join(dir, `test-${testName}-`), { encoding: "utf8" })
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
import * as fs from "fs"
|
||||
import * as os from "os"
|
||||
import * as path from "path"
|
||||
|
||||
export const loggerModule = {
|
||||
field: jest.fn(),
|
||||
level: 2,
|
||||
@ -9,3 +13,15 @@ export const loggerModule = {
|
||||
warn: jest.fn(),
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a uniquely named temporary directory.
|
||||
*
|
||||
* These directories are placed under a single temporary code-server directory.
|
||||
*/
|
||||
export async function tmpdir(testName: string): Promise<string> {
|
||||
const dir = path.join(os.tmpdir(), "code-server")
|
||||
await fs.promises.mkdir(dir, { recursive: true })
|
||||
|
||||
return await fs.promises.mkdtemp(path.join(dir, `test-${testName}-`), { encoding: "utf8" })
|
||||
}
|
||||
|
Reference in New Issue
Block a user