1
1
import { test , expect } from "@playwright/test"
2
+ import * as fs from "fs"
3
+ import { tmpdir } from "os"
4
+ import * as path from "path"
5
+
2
6
import { STORAGE } from "../utils/constants"
3
7
import { CodeServer } from "./models/CodeServer"
4
8
5
9
test . describe ( "Integrated Terminal" , ( ) => {
6
10
// Create a new context with the saved storage state
7
11
// so we don't have to logged in
8
12
const options : any = { }
9
- const testFileName = "hello .txt"
13
+ const testFileName = "test .txt"
10
14
const testString = "new string test from e2e test"
11
15
let codeServer : CodeServer
12
16
@@ -25,36 +29,35 @@ test.describe("Integrated Terminal", () => {
25
29
} )
26
30
27
31
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 } `
31
39
// Open terminal and type in value
32
- await codeServer . viewTerminal ( )
40
+ // await codeServer.viewTerminal()
33
41
await codeServer . focusTerminal ( )
34
42
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 )
36
46
await page . keyboard . press ( "Enter" )
37
47
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" )
58
57
}
58
+
59
+ expect ( fileExists ) . toBe ( true )
60
+
61
+ // TODO delete tmpFolder
59
62
} )
60
63
} )
0 commit comments