@@ -2,7 +2,8 @@ import { test, expect } from "@playwright/test"
2
2
import * as fs from "fs"
3
3
import { tmpdir } from "os"
4
4
import * as path from "path"
5
-
5
+ import util from "util"
6
+ import * as cp from "child_process"
6
7
import { STORAGE } from "../utils/constants"
7
8
import { CodeServer } from "./models/CodeServer"
8
9
@@ -13,6 +14,8 @@ test.describe("Integrated Terminal", () => {
13
14
const testFileName = "test.txt"
14
15
const testString = "new string test from e2e test"
15
16
let codeServer : CodeServer
17
+ let tmpFolderPath : string = ""
18
+ let tmpFile : string = ""
16
19
17
20
// TODO@jsjoeio
18
21
// Fix this once https://github.com/microsoft/playwright-test/issues/240
@@ -26,25 +29,33 @@ test.describe("Integrated Terminal", () => {
26
29
test . beforeEach ( async ( { page } ) => {
27
30
codeServer = new CodeServer ( page )
28
31
await codeServer . setup ( )
29
- } )
30
-
31
- test ( "should echo a string to a file" , options , async ( { page } ) => {
32
32
// NOTE@jsjoeio
33
33
// We're not using tmpdir from src/node/constants
34
34
// because Playwright doesn't fully support ES modules from
35
35
// 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
+
38
50
// Open terminal and type in value
39
51
await codeServer . focusTerminal ( )
40
52
41
- // give the terminal a second to load
42
53
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 } '` )
46
55
await page . keyboard . press ( "Enter" )
47
- await page . waitForTimeout ( 2000 )
56
+
57
+ const { stdout } = await output
58
+ expect ( stdout ) . toMatch ( testString )
48
59
49
60
// .access checks if the file exists without opening it
50
61
// it doesn't return anything hence why we expect it to
0 commit comments