11import { test , expect } from "@playwright/test"
2+ import * as fs from "fs"
3+ import { tmpdir } from "os"
4+ import * as path from "path"
5+
26import { STORAGE } from "../utils/constants"
37import { CodeServer } from "./models/CodeServer"
48
59test . describe ( "Integrated Terminal" , ( ) => {
610 // Create a new context with the saved storage state
711 // so we don't have to logged in
812 const options : any = { }
9- const testFileName = "hello .txt"
13+ const testFileName = "test .txt"
1014 const testString = "new string test from e2e test"
1115 let codeServer : CodeServer
1216
@@ -25,36 +29,35 @@ test.describe("Integrated Terminal", () => {
2529 } )
2630
2731 test ( "should echo a string to a file" , options , async ( { page } ) => {
28- // Open the default folder
29- await codeServer . openFolder ( )
30-
32+ // TODO@jsjoeio
33+ // import tempdir from
34+ // src/node/util.ts
35+ // TODO use this
36+ // ${tmpdir}/tests/${testName}/
37+ const tmpFolderPath = fs . mkdtempSync ( path . join ( tmpdir ( ) , "code-server-test" ) )
38+ const tmpFile = `${ tmpFolderPath } ${ path . sep } ${ testFileName } `
3139 // Open terminal and type in value
32- await codeServer . viewTerminal ( )
40+ // await codeServer.viewTerminal()
3341 await codeServer . focusTerminal ( )
3442
35- await page . keyboard . type ( `echo '${ testString } ' >> ${ testFileName } ` )
43+ await page . keyboard . type ( `echo '${ testString } ' > ${ tmpFile } ` )
44+ // Wait for the typing to finish before hitting enter
45+ await page . waitForTimeout ( 500 )
3646 await page . keyboard . press ( "Enter" )
3747 await page . waitForTimeout ( 2000 )
38- // It should show up on the left sidebar as a new file
39- const isFileVisible = await page . isVisible ( `text="${ testFileName } "` )
40- expect ( isFileVisible ) . toBe ( true )
41-
42- if ( isFileVisible ) {
43- // Check that the file has the test string in it
44- await codeServer . quickOpen ( testFileName )
45- expect ( await page . isVisible ( `text="${ testString } "` ) ) . toBe ( true )
46-
47- // Clean up
48- // Remove file
49- await codeServer . focusTerminal ( )
50- await page . keyboard . type ( `rm ${ testFileName } ` )
51- await page . keyboard . press ( "Enter" )
52- await page . waitForTimeout ( 2000 )
53- // Close the file from workbench
54- // otherwise it will still be visible
55- // and our assertion will fail
56- await page . keyboard . press ( `Meta+W` )
57- expect ( await page . isVisible ( `text="${ testString } "` ) ) . toBe ( false )
48+
49+ let fileExists = false
50+
51+ try {
52+ // Check that the file exists
53+ await fs . promises . access ( tmpFile , fs . constants . F_OK )
54+ fileExists = true
55+ } catch ( error ) {
56+ console . error ( "Could not find file" )
5857 }
58+
59+ expect ( fileExists ) . toBe ( true )
60+
61+ // TODO delete tmpFolder
5962 } )
6063} )
0 commit comments