1
1
import { test , expect } from "@playwright/test"
2
+ import * as cp from "child_process"
2
3
import * as fs from "fs"
3
- import { tmpdir } from "os"
4
+ // import { tmpdir } from "os"
4
5
import * as path from "path"
5
6
import util from "util"
6
- import * as cp from "child_process"
7
- import { STORAGE } from "../utils/constants"
7
+ import { STORAGE , tmpdir } from "../utils/constants"
8
8
import { CodeServer } from "./models/CodeServer"
9
9
10
10
test . describe ( "Integrated Terminal" , ( ) => {
@@ -14,8 +14,8 @@ test.describe("Integrated Terminal", () => {
14
14
const testFileName = "pipe"
15
15
const testString = "new string test from e2e test"
16
16
let codeServer : CodeServer
17
- let tmpFolderPath : string = ""
18
- let tmpFile : string = ""
17
+ let tmpFolderPath = ""
18
+ let tmpFile = ""
19
19
20
20
// TODO@jsjoeio
21
21
// Fix this once https://github.com/microsoft/playwright-test/issues/240
@@ -26,20 +26,19 @@ test.describe("Integrated Terminal", () => {
26
26
storageState,
27
27
}
28
28
}
29
+ test . beforeAll ( async ( ) => {
30
+ tmpFolderPath = await tmpdir ( "integrated-terminal" )
31
+ tmpFile = path . join ( tmpFolderPath , testFileName )
32
+ } )
33
+
29
34
test . beforeEach ( async ( { page } ) => {
30
35
codeServer = new CodeServer ( page )
31
36
await codeServer . setup ( )
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
36
- tmpFolderPath = fs . mkdtempSync ( path . join ( tmpdir ( ) , "code-server-test" ) )
37
- tmpFile = path . join ( tmpFolderPath , testFileName )
38
37
} )
39
38
40
- test . afterEach ( async ( ) => {
39
+ test . afterAll ( async ( ) => {
41
40
// Ensure directory was removed
42
- fs . rmdirSync ( tmpFolderPath , { recursive : true } )
41
+ await fs . promises . rmdir ( tmpFolderPath , { recursive : true } )
43
42
} )
44
43
45
44
test ( "should echo a string to a file" , options , async ( { page } ) => {
@@ -56,22 +55,5 @@ test.describe("Integrated Terminal", () => {
56
55
57
56
const { stdout } = await output
58
57
expect ( stdout ) . toMatch ( testString )
59
-
60
- // .access checks if the file exists without opening it
61
- // it doesn't return anything hence why we expect it to
62
- // resolve to undefined
63
- // If the promise rejects (i.e. the file doesn't exist)
64
- // then the assertion will fail
65
- await expect ( fs . promises . access ( tmpFile ) ) . resolves . toBeUndefined ( )
66
-
67
- await fs . promises . rmdir ( tmpFolderPath , { recursive : true } )
68
- // Make sure neither file nor folder exist
69
- // Note: We have to use ts-ignore because of an upstream typing error
70
- // See: https://github.com/microsoft/folio/issues/230#event-4621948411
71
- /* eslint-disable @typescript-eslint/ban-ts-comment */
72
- // @ts -ignore
73
- expect ( fs . promises . access ( tmpFile ) ) . rejects . toThrowError ( / n o s u c h f i l e o r d i r e c t o r y / )
74
- // @ts -ignore
75
- expect ( fs . promises . access ( tmpFolderPath ) ) . rejects . toThrowError ( / n o s u c h f i l e o r d i r e c t o r y / )
76
58
} )
77
59
} )
0 commit comments