Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gzupanda
code-server
提交
2dc56ad4
C
code-server
项目概览
gzupanda
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2dc56ad4
编写于
2月 04, 2021
作者:
J
Joe Previte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: manually add cookie goHome
上级
b02d2fb3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
15 deletion
+44
-15
test/goHome.test.ts
test/goHome.test.ts
+44
-15
未找到文件。
test/goHome.test.ts
浏览文件 @
2dc56ad4
import
{
chromium
,
Page
,
Browser
,
BrowserContext
}
from
"
playwright
"
import
{
chromium
,
Page
,
Browser
,
BrowserContext
,
Cookie
}
from
"
playwright
"
import
{
createCookieIfDoesntExist
}
from
"
../src/common/util
"
import
{
hash
}
from
"
../src/node/util
"
describe
(
"
login
"
,
()
=>
{
let
browser
:
Browser
...
...
@@ -9,7 +11,37 @@ describe("login", () => {
browser
=
await
chromium
.
launch
()
// Create a new context with the saved storage state
const
storageState
=
JSON
.
parse
(
process
.
env
.
STORAGE
||
""
)
context
=
await
browser
.
newContext
({
storageState
,
recordVideo
:
{
dir
:
"
./test/videos/
"
}
})
//
const
cookieToStore
=
{
sameSite
:
"
Lax
"
as
const
,
name
:
"
key
"
,
value
:
hash
(
process
.
env
.
PASSWORD
||
""
),
domain
:
"
localhost
"
,
path
:
"
/
"
,
expires
:
-
1
,
httpOnly
:
false
,
secure
:
false
,
}
// For some odd reason, the login method used in globalSetup.ts doesn't always work
// I don't know if it's on playwright clearing our cookies by accident
// or if it's our cookies disappearing.
// This means we need an additional check to make sure we're logged in.
// We do this by manually adding the cookie to the browser environment
// if it's not there at the time the test starts
const
cookies
:
Cookie
[]
=
storageState
.
cookies
||
[]
// If the cookie exists in cookies then
// this will return the cookies with no changes
// otherwise if it doesn't exist, it will create it
// hence the name maybeUpdatedCookies
const
maybeUpdatedCookies
=
createCookieIfDoesntExist
(
cookies
,
cookieToStore
)
console
.
log
(
"
here are the cookies
"
,
maybeUpdatedCookies
)
context
=
await
browser
.
newContext
({
storageState
:
{
cookies
:
maybeUpdatedCookies
},
recordVideo
:
{
dir
:
"
./test/videos/
"
},
})
done
()
})
...
...
@@ -27,7 +59,16 @@ describe("login", () => {
done
()
})
// NOTE: this test will fail if you do not run code-server with --home $CODE_SERVER_ADDRESS/healthz
it
(
"
should see a 'Go Home' button in the Application Menu that goes to /healthz
"
,
async
(
done
)
=>
{
// Ideally, this test should pass and finish before the timeout set in the Jest config
// However, if it doesn't, we don't want a memory leak so we set this backup timeout
// Otherwise Jest may throw this error
// "Jest did not exit one second after the test run has completed.
// This usually means that there are asynchronous operations that weren't stopped in your tests.
// Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
const
backupTimeout
=
setTimeout
(()
=>
done
(),
20000
)
const
GO_HOME_URL
=
`
${
process
.
env
.
CODE_SERVER_ADDRESS
}
/healthz`
let
requestedGoHomeUrl
=
false
page
.
on
(
"
request
"
,
(
request
)
=>
{
...
...
@@ -38,6 +79,7 @@ describe("login", () => {
if
(
request
.
url
()
===
GO_HOME_URL
)
{
requestedGoHomeUrl
=
true
expect
(
requestedGoHomeUrl
).
toBeTruthy
()
clearTimeout
(
backupTimeout
)
// This ensures Jest knows we're done here.
done
()
...
...
@@ -52,19 +94,6 @@ describe("login", () => {
// In case the page takes a long time to load
await
page
.
goto
(
process
.
env
.
CODE_SERVER_ADDRESS
||
"
http://localhost:8080
"
,
{
waitUntil
:
"
domcontentloaded
"
})
// For some odd reason, the login method used in globalSetup.ts
// I don't know if it's on playwright clearing our cookies by accident
// or if it's our cookies disappearing.
// This means we need an additional check to make sure we're logged in
// otherwise this test will hang and fail.
const
currentPageURL
=
await
page
.
url
()
const
isLoginPage
=
currentPageURL
.
includes
(
"
login
"
)
if
(
isLoginPage
)
{
await
page
.
fill
(
"
.password
"
,
process
.
env
.
PASSWORD
||
"
password
"
)
// Click the submit button and login
await
page
.
click
(
"
.submit
"
)
}
// Click the Application menu
await
page
.
click
(
"
.menubar-menu-button[title='Application Menu']
"
)
// See the Go Home button
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录