Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
988dce8c
W
wechaty
项目概览
.Veneno.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
988dce8c
编写于
11月 06, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more strict check for browser & driver
上级
0aaa07b4
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
62 addition
and
44 deletion
+62
-44
src/puppet-web/browser-driver.ts
src/puppet-web/browser-driver.ts
+17
-5
src/puppet-web/browser.ts
src/puppet-web/browser.ts
+10
-4
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+24
-26
src/puppet.ts
src/puppet.ts
+1
-1
test/puppet-web/watchdog.spec.ts
test/puppet-web/watchdog.spec.ts
+10
-8
未找到文件。
src/puppet-web/browser-driver.ts
浏览文件 @
988dce8c
...
...
@@ -237,11 +237,23 @@ export class BrowserDriver {
const
session
=
await
driver
.
getSession
()
if
(
!
session
)
{
log
.
verbose
(
'
PuppetWebBrowserDriver
'
,
'
valid() found an invalid driver
'
)
}
else
{
log
.
silly
(
'
PuppetWebBrowserDriver
'
,
'
valid() driver ok
'
)
return
false
}
return
!!
session
let
two
try
{
two
=
await
this
.
executeScript
(
'
return 1+1
'
)
}
catch
(
e
)
{
two
=
e
log
.
warn
(
'
BrowserDriver
'
,
'
valid() fail: %s
'
,
e
.
message
)
}
if
(
two
!==
2
)
{
return
false
}
log
.
silly
(
'
PuppetWebBrowserDriver
'
,
'
valid() driver ok
'
)
return
true
}
// public driver1(): WebDriver
...
...
@@ -286,8 +298,8 @@ export class BrowserDriver {
// }
public
close
()
{
return
this
.
driver
.
close
()
}
public
executeAsyncScript
(
)
{
return
this
.
driver
.
executeAsyncScript
.
apply
(
this
.
driver
,
arguments
)
}
public
executeScript
()
{
return
this
.
driver
.
executeScript
.
apply
(
this
.
driver
,
arguments
)
}
public
executeAsyncScript
(
script
:
string
|
Function
,
...
args
:
any
[])
{
return
this
.
driver
.
executeAsyncScript
.
apply
(
this
.
driver
,
arguments
)
}
public
executeScript
(
script
:
string
|
Function
,
...
args
:
any
[])
{
return
this
.
driver
.
executeScript
.
apply
(
this
.
driver
,
arguments
)
}
public
get
(
url
:
string
)
{
return
this
.
driver
.
get
(
url
)
}
public
getSession
()
{
return
this
.
driver
.
getSession
()
}
public
manage
()
{
return
this
.
driver
.
manage
()
}
...
...
src/puppet-web/browser.ts
浏览文件 @
988dce8c
...
...
@@ -133,10 +133,16 @@ export class Browser extends EventEmitter {
public
async
quit
():
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWebBrowser
'
,
'
quit()
'
)
if
(
this
.
state
.
current
()
===
'
close
'
&&
this
.
state
.
inprocess
())
{
const
e
=
new
Error
(
'
quit() be called when state.current() is close with inprocess()?
'
)
if
(
this
.
state
.
current
()
===
'
close
'
)
{
if
(
this
.
state
.
inprocess
())
{
const
e
=
new
Error
(
'
quit() on a browser with state.current():`close` and inprocess():`true` ?
'
)
log
.
warn
(
'
PuppetWebBrowser
'
,
e
.
message
)
throw
e
}
else
{
// stable
const
e
=
new
Error
(
'
quit() on a already quit-ed browser
'
)
log
.
warn
(
'
PuppetWebBrowser
'
,
e
.
message
)
throw
e
}
}
this
.
state
.
current
(
'
close
'
,
false
)
...
...
src/puppet-web/puppet-web.ts
浏览文件 @
988dce8c
...
...
@@ -135,39 +135,37 @@ export class PuppetWeb extends Puppet {
try
{
if
(
this
.
bridge
)
{
// TODO use StateMonitor
await
this
.
bridge
.
quit
()
.
catch
(
e
=>
{
// fail safe
log
.
warn
(
'
PuppetWeb
'
,
'
quit() bridge.quit() exception: %s
'
,
e
.
message
)
})
log
.
verbose
(
'
PuppetWeb
'
,
'
quit() bridge.quit() this.bridge = null
'
)
//
log.verbose('PuppetWeb', 'quit() bridge.quit() this.bridge = null')
// this.bridge = null
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
quit() without a bridge
'
)
}
if
(
this
.
server
)
{
// TODO use StateMonitor
await
this
.
server
.
quit
()
.
catch
(
e
=>
{
// fail safe
log
.
warn
(
'
PuppetWeb
'
,
'
quit() server.quit() exception: %s
'
,
e
.
message
)
})
// this.server = null
log
.
verbose
(
'
PuppetWeb
'
,
'
quit() server.quit() this.server = null
'
)
}
else
{
log
.
verbose
(
'
PuppetWeb
'
,
'
quit() without a server
'
)
}
// log.verbose('PuppetWeb', 'quit() server.quit() this.server = null')
if
(
this
.
browser
)
{
// TODO use StateMonitor
await
this
.
browser
.
quit
()
.
catch
(
e
=>
{
// fail safe
log
.
warn
(
'
PuppetWeb
'
,
'
quit() browser.quit() exception: %s
'
,
e
.
message
)
})
log
.
verbose
(
'
PuppetWeb
'
,
'
quit() server.quit() this.browser = null
'
)
//
log.verbose('PuppetWeb', 'quit() server.quit() this.browser = null')
// this.browser = null
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
quit() without a browser
'
)
}
this
.
state
.
current
(
'
dead
'
)
log
.
silly
(
'
PuppetWeb
'
,
'
quit() done
'
)
return
}
catch
(
e
)
{
log
.
error
(
'
PuppetWeb
'
,
'
quit() exception: %s
'
,
e
.
message
)
this
.
state
.
current
(
'
dead
'
)
throw
e
}
log
.
silly
(
'
PuppetWeb
'
,
'
quit() done
'
)
this
.
state
.
current
(
'
dead
'
)
}
public
createBrowser
()
{
...
...
src/puppet.ts
浏览文件 @
988dce8c
test/puppet-web/watchdog.spec.ts
浏览文件 @
988dce8c
...
...
@@ -6,6 +6,7 @@
*
*/
import
{
test
}
from
'
ava
'
import
*
as
sinon
from
'
sinon
'
/* tslint:disable:no-var-requires */
const
retryPromise
=
require
(
'
retry-promise
'
).
default
...
...
@@ -21,7 +22,7 @@ import {
const
PROFILE
=
'
unit-test-session.wechaty.json
'
test
(
'
Puppet Web watchdog
timer
'
,
async
t
=>
{
test
(
'
timer
'
,
async
t
=>
{
const
pw
=
new
PuppetWeb
({
profile
:
PROFILE
})
t
.
truthy
(
pw
,
'
should instantiate a PuppetWeb
'
)
...
...
@@ -31,7 +32,7 @@ test('Puppet Web watchdog timer', async t => {
Watchdog
.
onFeed
.
call
(
pw
,
{
data
:
'
initing directly
'
})
t
.
pass
(
'
should ok with default food type
'
)
const
origLog
Level
=
log
.
level
()
const
saved
Level
=
log
.
level
()
if
(
log
.
level
()
===
'
info
'
)
{
log
.
level
(
'
silent
'
)
t
.
pass
(
'
set log.level = silent to mute log when watchDog reset wechaty temporary
'
)
...
...
@@ -43,19 +44,20 @@ test('Puppet Web watchdog timer', async t => {
{
pw
.
removeListener
(
'
error
'
,
failOnUnexpectedErrorEvent
)
let
errorCounter
=
0
pw
.
once
(
'
error
'
,
e
=>
errorCounter
++
)
// let errorCounter = 0
const
spy
=
sinon
.
spy
()
pw
.
once
(
'
error
'
,
spy
)
pw
.
emit
(
'
watchdog
'
,
{
data
:
'
active_for_timeout_1ms
'
,
timeout
:
1
})
await
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
10
))
// wait until
l
reset
t
.
is
(
errorCounter
,
1
,
'
should get event[error] after watchdog timeout
'
)
await
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
10
))
// wait until reset
t
.
truthy
(
spy
.
calledOnce
,
'
should get event[error] after watchdog timeout
'
)
pw
.
addListener
(
'
error
'
,
failOnUnexpectedErrorEvent
)
}
//
pw.once('error', e => t.fail('waitDing() triggered watchDogReset()'))
pw
.
once
(
'
error
'
,
e
=>
t
.
fail
(
'
waitDing() triggered watchDogReset()
'
))
const
EXPECTED_DING_DATA
=
'
dingdong
'
pw
.
emit
(
'
watchdog
'
,
{
data
:
'
feed to extend the dog life
'
,
timeout
:
120000
})
...
...
@@ -63,7 +65,7 @@ test('Puppet Web watchdog timer', async t => {
const
dong
=
await
waitDing
(
EXPECTED_DING_DATA
)
t
.
is
(
dong
,
EXPECTED_DING_DATA
,
'
should get EXPECTED_DING_DATA from ding after watchdog reset, and restored log level
'
)
log
.
level
(
origLog
Level
)
log
.
level
(
saved
Level
)
await
pw
.
quit
()
return
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录