Skip to content

Commit 8124acd

Browse files
committed
feat: add e2e test for terminal
1 parent 6c1139c commit 8124acd

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/e2e/terminal.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { test, expect } from "@playwright/test"
2+
import { STORAGE } from "../utils/constants"
3+
import { CodeServer } from "./models/CodeServer"
4+
5+
test.describe("Integrated Terminal", () => {
6+
// Create a new context with the saved storage state
7+
// so we don't have to logged in
8+
const options: any = {}
9+
const testFileName = "hello.txt"
10+
const testString = "new string test from e2e test"
11+
let codeServer: CodeServer
12+
13+
// TODO@jsjoeio
14+
// Fix this once https://github.com/microsoft/playwright-test/issues/240
15+
// is fixed
16+
if (STORAGE) {
17+
const storageState = JSON.parse(STORAGE) || {}
18+
options.contextOptions = {
19+
storageState,
20+
}
21+
}
22+
test.beforeEach(async ({ page }) => {
23+
codeServer = new CodeServer(page)
24+
await codeServer.navigate()
25+
})
26+
27+
test("should echo a string to a file", options, async ({ page }) => {
28+
// Open the default folder
29+
await codeServer.openFolder()
30+
31+
// Open terminal and type in value
32+
await codeServer.viewTerminal()
33+
await codeServer.focusTerminal()
34+
35+
await page.keyboard.type(`echo '${testString}' >> ${testFileName}`)
36+
await page.keyboard.press("Enter")
37+
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)
58+
}
59+
})
60+
})

0 commit comments

Comments
 (0)