11import { test , expect } from "@playwright/test"
2+ import * as cp from "child_process"
23import * as fs from "fs"
3- import { tmpdir } from "os"
4+ // import { tmpdir } from "os"
45import * as path from "path"
56import util from "util"
6- import * as cp from "child_process"
7- import { STORAGE } from "../utils/constants"
7+ import { STORAGE , tmpdir } from "../utils/constants"
88import { CodeServer } from "./models/CodeServer"
99
1010test . describe ( "Integrated Terminal" , ( ) => {
@@ -14,8 +14,8 @@ test.describe("Integrated Terminal", () => {
1414 const testFileName = "pipe"
1515 const testString = "new string test from e2e test"
1616 let codeServer : CodeServer
17- let tmpFolderPath : string = ""
18- let tmpFile : string = ""
17+ let tmpFolderPath = ""
18+ let tmpFile = ""
1919
2020 // TODO@jsjoeio
2121 // Fix this once https://github.com/microsoft/playwright-test/issues/240
@@ -26,20 +26,19 @@ test.describe("Integrated Terminal", () => {
2626 storageState,
2727 }
2828 }
29+ test . beforeAll ( async ( ) => {
30+ tmpFolderPath = await tmpdir ( "integrated-terminal" )
31+ tmpFile = path . join ( tmpFolderPath , testFileName )
32+ } )
33+
2934 test . beforeEach ( async ( { page } ) => {
3035 codeServer = new CodeServer ( page )
3136 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 )
3837 } )
3938
40- test . afterEach ( async ( ) => {
39+ test . afterAll ( async ( ) => {
4140 // Ensure directory was removed
42- fs . rmdirSync ( tmpFolderPath , { recursive : true } )
41+ await fs . promises . rmdir ( tmpFolderPath , { recursive : true } )
4342 } )
4443
4544 test ( "should echo a string to a file" , options , async ( { page } ) => {
@@ -56,22 +55,5 @@ test.describe("Integrated Terminal", () => {
5655
5756 const { stdout } = await output
5857 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 / )
7658 } )
7759} )
0 commit comments