File tree Expand file tree Collapse file tree 5 files changed +33
-29
lines changed Expand file tree Collapse file tree 5 files changed +33
-29
lines changed Original file line number Diff line number Diff line change 1- import { test , expect } from "@playwright/test"
1+ import { expect , test } from "@playwright/test"
22import * as cp from "child_process"
33import * as fs from "fs"
4- // import { tmpdir } from "os"
54import * as path from "path"
65import util from "util"
7- import { STORAGE , tmpdir } from "../utils/constants"
6+ import { STORAGE } from "../utils/constants"
7+ import { tmpdir } from "../utils/helpers"
88import { CodeServer } from "./models/CodeServer"
99
1010test . describe ( "Integrated Terminal" , ( ) => {
Original file line number Diff line number Diff line change 1- import * as fs from "fs"
2- import { tmpdir } from "../../test/utils/constants"
31import { loggerModule } from "../utils/helpers"
42
53// jest.mock is hoisted above the imports so we must use `require` here.
@@ -89,16 +87,3 @@ describe("constants", () => {
8987 } )
9088 } )
9189} )
92-
93- describe ( "test constants" , ( ) => {
94- describe ( "tmpdir" , ( ) => {
95- it ( "should return a temp directory" , async ( ) => {
96- const testName = "temp-dir"
97- const pathToTempDir = await tmpdir ( testName )
98-
99- expect ( pathToTempDir ) . toContain ( testName )
100-
101- await fs . promises . rmdir ( pathToTempDir )
102- } )
103- } )
104- } )
Original file line number Diff line number Diff line change 1+ import { promises as fs } from "fs"
2+ import { tmpdir } from "../../test/utils/helpers"
3+
4+ /**
5+ * This file is for testing test helpers (not core code).
6+ */
7+ describe ( "test helpers" , ( ) => {
8+ it ( "should return a temp directory" , async ( ) => {
9+ const testName = "temp-dir"
10+ const pathToTempDir = await tmpdir ( testName )
11+ expect ( pathToTempDir ) . toContain ( testName )
12+ expect ( fs . access ( pathToTempDir ) ) . resolves . toStrictEqual ( undefined )
13+ } )
14+ } )
Original file line number Diff line number Diff line change 1- import * as fs from "fs"
2- import * as os from "os"
3- import * as path from "path"
4-
51export const CODE_SERVER_ADDRESS = process . env . CODE_SERVER_ADDRESS || "http://localhost:8080"
62export const PASSWORD = process . env . PASSWORD || "e45432jklfdsab"
73export 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 . promises . mkdir ( dir , { recursive : true } )
12-
13- return await fs . promises . mkdtemp ( path . join ( dir , `test-${ testName } -` ) , { encoding : "utf8" } )
14- }
Original file line number Diff line number Diff line change 1+ import * as fs from "fs"
2+ import * as os from "os"
3+ import * as path from "path"
4+
15export const loggerModule = {
26 field : jest . fn ( ) ,
37 level : 2 ,
@@ -9,3 +13,15 @@ export const loggerModule = {
913 warn : jest . fn ( ) ,
1014 } ,
1115}
16+
17+ /**
18+ * Create a uniquely named temporary directory.
19+ *
20+ * These directories are placed under a single temporary code-server directory.
21+ */
22+ export async function tmpdir ( testName : string ) : Promise < string > {
23+ const dir = path . join ( os . tmpdir ( ) , "code-server" )
24+ await fs . promises . mkdir ( dir , { recursive : true } )
25+
26+ return await fs . promises . mkdtemp ( path . join ( dir , `test-${ testName } -` ) , { encoding : "utf8" } )
27+ }
You can’t perform that action at this time.
0 commit comments