@@ -2,7 +2,8 @@ import { test, expect } from "@playwright/test"
22import * as fs from "fs"
33import { tmpdir } from "os"
44import * as path from "path"
5-
5+ import util from "util"
6+ import * as cp from "child_process"
67import { STORAGE } from "../utils/constants"
78import { CodeServer } from "./models/CodeServer"
89
@@ -13,6 +14,8 @@ test.describe("Integrated Terminal", () => {
1314 const testFileName = "test.txt"
1415 const testString = "new string test from e2e test"
1516 let codeServer : CodeServer
17+ let tmpFolderPath : string = ""
18+ let tmpFile : string = ""
1619
1720 // TODO@jsjoeio
1821 // Fix this once https://github.com/microsoft/playwright-test/issues/240
@@ -26,25 +29,33 @@ test.describe("Integrated Terminal", () => {
2629 test . beforeEach ( async ( { page } ) => {
2730 codeServer = new CodeServer ( page )
2831 await codeServer . setup ( )
29- } )
30-
31- test ( "should echo a string to a file" , options , async ( { page } ) => {
3232 // NOTE@jsjoeio
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- const tmpFolderPath = fs . mkdtempSync ( path . join ( tmpdir ( ) , "code-server-test" ) )
37- const tmpFile = `${ tmpFolderPath } ${ path . sep } ${ testFileName } `
36+ tmpFolderPath = fs . mkdtempSync ( path . join ( tmpdir ( ) , "code-server-test" ) )
37+ tmpFile = `${ tmpFolderPath } ${ path . sep } ${ testFileName } `
38+ } )
39+
40+ test . afterEach ( async ( ) => {
41+ // Ensure directory was removed
42+ fs . rmdirSync ( tmpFolderPath , { recursive : true } )
43+ } )
44+
45+ test ( "should echo a string to a file" , options , async ( { page } ) => {
46+ const command = `mkfifo '${ tmpFile } ' && cat '${ tmpFile } '`
47+ const exec = util . promisify ( cp . exec )
48+ const output = exec ( command , { encoding : "utf8" } )
49+
3850 // Open terminal and type in value
3951 await codeServer . focusTerminal ( )
4052
41- // give the terminal a second to load
4253 await page . waitForLoadState ( "load" )
43- await page . keyboard . type ( `echo '${ testString } ' > ${ tmpFile } ` )
44- // Wait for the typing to finish before hitting enter
45- await page . waitForTimeout ( 500 )
54+ await page . keyboard . type ( `echo '${ testString } ' > '${ tmpFile } '` )
4655 await page . keyboard . press ( "Enter" )
47- await page . waitForTimeout ( 2000 )
56+
57+ const { stdout } = await output
58+ expect ( stdout ) . toMatch ( testString )
4859
4960 // .access checks if the file exists without opening it
5061 // it doesn't return anything hence why we expect it to
0 commit comments