Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Coder
code-server
提交
2665a4f6
C
code-server
项目概览
镜像
/
Coder
/
code-server
2022-09-21 03:15:05同步失败
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2665a4f6
编写于
4月 19, 2021
作者:
J
Joe Previte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add CodeServer page object for e2e tests
上级
5ad8e686
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
167 addition
and
0 deletion
+167
-0
test/e2e/codeServer.test.ts
test/e2e/codeServer.test.ts
+46
-0
test/e2e/models/CodeServer.ts
test/e2e/models/CodeServer.ts
+61
-0
test/e2e/terminal.test.ts
test/e2e/terminal.test.ts
+60
-0
未找到文件。
test/e2e/codeServer.test.ts
0 → 100644
浏览文件 @
2665a4f6
import
{
test
,
expect
}
from
"
@playwright/test
"
import
{
STORAGE
}
from
"
../utils/constants
"
import
{
CodeServer
}
from
"
./models/CodeServer
"
test
.
describe
(
"
CodeServer
"
,
()
=>
{
// Create a new context with the saved storage state
// so we don't have to logged in
const
options
:
any
=
{}
let
codeServer
:
CodeServer
// TODO@jsjoeio
// Fix this once https://github.com/microsoft/playwright-test/issues/240
// is fixed
if
(
STORAGE
)
{
const
storageState
=
JSON
.
parse
(
STORAGE
)
||
{}
options
.
contextOptions
=
{
storageState
,
}
}
test
.
beforeEach
(
async
({
page
})
=>
{
codeServer
=
new
CodeServer
(
page
)
await
codeServer
.
navigate
()
})
test
(
"
should open the default folder if not open
"
,
options
,
async
({
page
})
=>
{
await
codeServer
.
openFolder
()
// find workspaceStorage in the Explorer menu, which would be open in the User folder
// which is the default folder that opens
expect
(
await
page
.
isVisible
(
"
text=workspaceStorage
"
)).
toBe
(
true
)
})
test
(
"
should show the Integrated Terminal
"
,
options
,
async
({
page
})
=>
{
await
codeServer
.
viewTerminal
()
expect
(
await
page
.
isVisible
(
"
#terminal
"
)).
toBe
(
true
)
})
test
(
"
should open a file with quickOpen
"
,
options
,
async
({
page
})
=>
{
await
codeServer
.
openFolder
()
await
codeServer
.
quickOpen
(
"
extensions.json
"
)
// If the file is open, we will see an empty array
// assuming no extensions are installed
expect
(
await
page
.
isVisible
(
"
text=[]
"
))
})
})
test/e2e/models/CodeServer.ts
0 → 100644
浏览文件 @
2665a4f6
import
{
Page
}
from
"
playwright
"
import
{
CODE_SERVER_ADDRESS
}
from
"
../../utils/constants
"
// This is a Page Object Model
// We use these to simplify e2e test authoring
// See Playwright docs: https://playwright.dev/docs/pom/
export
class
CodeServer
{
page
:
Page
constructor
(
page
:
Page
)
{
this
.
page
=
page
}
async
navigate
()
{
await
this
.
page
.
goto
(
CODE_SERVER_ADDRESS
,
{
waitUntil
:
"
networkidle
"
})
// Make sure the editor actually loaded
await
this
.
page
.
isVisible
(
"
div.monaco-workbench
"
)
}
/**
* Opens the default folder /User if no arg passed
* @param absolutePath Example: /Users/jp/.local/share/code-server/User/
*
*/
async
openFolder
(
absolutePath
?:
string
)
{
// Check if no folder is opened
const
folderIsNotOpen
=
await
this
.
page
.
isVisible
(
"
text=You have not yet opened
"
)
if
(
folderIsNotOpen
)
{
// Open the default folder
await
this
.
page
.
keyboard
.
press
(
"
Meta+O
"
)
await
this
.
page
.
keyboard
.
press
(
"
Enter
"
)
await
this
.
page
.
waitForLoadState
(
"
networkidle
"
)
}
}
/**
* Toggles the integrated terminal if not already in view
* and focuses it
*/
async
viewTerminal
()
{
// Check if Terminal is already in view
const
isTerminalInView
=
await
this
.
page
.
isVisible
(
"
#terminal
"
)
if
(
!
isTerminalInView
)
{
// Open using default keyboard shortcut
await
this
.
focusTerminal
()
await
this
.
page
.
waitForSelector
(
"
#terminal
"
)
}
}
async
focusTerminal
()
{
await
this
.
page
.
keyboard
.
press
(
"
Control+Backquote
"
)
}
async
quickOpen
(
input
:
string
)
{
await
this
.
page
.
keyboard
.
press
(
"
Meta+P
"
)
await
this
.
page
.
waitForSelector
(
'
[aria-describedby="quickInput_message"]
'
)
await
this
.
page
.
keyboard
.
type
(
input
)
await
this
.
page
.
waitForTimeout
(
2000
)
await
this
.
page
.
keyboard
.
press
(
"
Enter
"
)
await
this
.
page
.
waitForTimeout
(
2000
)
}
}
test/e2e/terminal.test.ts
0 → 100644
浏览文件 @
2665a4f6
import
{
test
,
expect
}
from
"
@playwright/test
"
import
{
STORAGE
}
from
"
../utils/constants
"
import
{
CodeServer
}
from
"
./models/CodeServer
"
test
.
describe
(
"
Integrated Terminal
"
,
()
=>
{
// Create a new context with the saved storage state
// so we don't have to logged in
const
options
:
any
=
{}
const
testFileName
=
"
hello.txt
"
const
testString
=
"
new string test from e2e test
"
let
codeServer
:
CodeServer
// TODO@jsjoeio
// Fix this once https://github.com/microsoft/playwright-test/issues/240
// is fixed
if
(
STORAGE
)
{
const
storageState
=
JSON
.
parse
(
STORAGE
)
||
{}
options
.
contextOptions
=
{
storageState
,
}
}
test
.
beforeEach
(
async
({
page
})
=>
{
codeServer
=
new
CodeServer
(
page
)
await
codeServer
.
navigate
()
})
test
(
"
should echo a string to a file
"
,
options
,
async
({
page
})
=>
{
// Open the default folder
await
codeServer
.
openFolder
()
// Open terminal and type in value
await
codeServer
.
viewTerminal
()
await
codeServer
.
focusTerminal
()
await
page
.
keyboard
.
type
(
`echo '
${
testString
}
' >>
${
testFileName
}
`
)
await
page
.
keyboard
.
press
(
"
Enter
"
)
await
page
.
waitForTimeout
(
2000
)
// It should show up on the left sidebar as a new file
const
isFileVisible
=
await
page
.
isVisible
(
`text="
${
testFileName
}
"`
)
expect
(
isFileVisible
).
toBe
(
true
)
if
(
isFileVisible
)
{
// Check that the file has the test string in it
await
codeServer
.
quickOpen
(
testFileName
)
expect
(
await
page
.
isVisible
(
`text="
${
testString
}
"`
)).
toBe
(
true
)
// Clean up
// Remove file
await
codeServer
.
focusTerminal
()
await
page
.
keyboard
.
type
(
`rm
${
testFileName
}
`
)
await
page
.
keyboard
.
press
(
"
Enter
"
)
await
page
.
waitForTimeout
(
2000
)
// Close the file from workbench
// otherwise it will still be visible
// and our assertion will fail
await
page
.
keyboard
.
press
(
`Meta+W`
)
expect
(
await
page
.
isVisible
(
`text="
${
testString
}
"`
)).
toBe
(
false
)
}
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录