@@ -2,17 +2,20 @@ 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
910test . describe ( "Integrated Terminal" , ( ) => {
1011 // Create a new context with the saved storage state
1112 // so we don't have to logged in
1213 const options : any = { }
13- const testFileName = "test.txt "
14+ const testFileName = "pipe "
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
@@ -25,26 +28,34 @@ test.describe("Integrated Terminal", () => {
2528 }
2629 test . beforeEach ( async ( { page } ) => {
2730 codeServer = new CodeServer ( page )
28- await codeServer . navigate ( )
29- } )
30-
31- test ( "should echo a string to a file" , options , async ( { page } ) => {
31+ await codeServer . setup ( )
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 = path . join ( tmpFolderPath , 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
42- await page . waitForTimeout ( 3000 )
43- await page . keyboard . type ( `echo '${ testString } ' > ${ tmpFile } ` )
44- // Wait for the typing to finish before hitting enter
45- await page . waitForTimeout ( 500 )
53+ await page . waitForLoadState ( "load" )
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