Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
ffbd0d63
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,发现更多精彩内容 >>
提交
ffbd0d63
编写于
6月 17, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
npmlog with timestamp doc, return code bugfix and test
上级
50ab45e9
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
78 addition
and
12 deletion
+78
-12
README.md
README.md
+25
-0
src/puppet-web-bridge.js
src/puppet-web-bridge.js
+7
-4
src/puppet-web-browser.js
src/puppet-web-browser.js
+2
-0
src/puppet-web-event.js
src/puppet-web-event.js
+1
-0
src/puppet-web.js
src/puppet-web.js
+2
-1
test/puppet-web-event-spec.js
test/puppet-web-event-spec.js
+30
-0
test/puppet-web-spec.js
test/puppet-web-spec.js
+11
-7
未找到文件。
README.md
浏览文件 @
ffbd0d63
...
...
@@ -158,6 +158,31 @@ mode con lines=32766
```
> http://stackoverflow.com/a/8775884/1123955
### NpmLog with Timestamp ###
Here's a quick and dirty patch, to npmlog/log.js
```
javascript
m
.
message
.
split
(
/
\r?\n
/
).
forEach
(
function
(
line
)
{
var
date
=
new
Date
();
var
min
=
date
.
getMinutes
()
var
sec
=
date
.
getSeconds
()
var
hour
=
date
.
getHours
()
if
(
sec
<
10
)
{
sec
=
'
0
'
+
sec
}
if
(
min
<
10
)
{
min
=
'
0
'
+
min
}
if
(
hour
<
10
)
{
hour
=
'
0
'
+
hour
}
this
.
write
(
hour
+
'
:
'
+
min
+
'
:
'
+
sec
+
'
'
)
if
(
this
.
heading
)
{
this
.
write
(
this
.
heading
,
this
.
headingStyle
)
this
.
write
(
'
'
)
}
```
And we can looking forward the official support from npmlog: https://github.com/npm/npmlog/pull/24
# Requirement
ECMAScript2015(ES6). I develop and test wechaty with Node.js v6.0.
...
...
src/puppet-web-bridge.js
浏览文件 @
ffbd0d63
...
...
@@ -64,7 +64,7 @@ class Bridge {
const
injectio
=
this
.
getInjectio
()
let
retObj
=
yield
this
.
execute
(
injectio
,
this
.
port
)
if
(
retObj
&&
/^
2|3
/
.
test
(
retObj
.
code
))
{
// HTTP Code 2XX & 3XX
if
(
retObj
&&
/^
(
2|3
)
/
.
test
(
retObj
.
code
))
{
// HTTP Code 2XX & 3XX
log
.
verbose
(
'
PuppetWebBridge
'
,
'
inject() eval(Wechaty) return code[%d] message[%s] port[%d]
'
,
retObj
.
code
,
retObj
.
message
,
retObj
.
port
)
}
else
{
// HTTP Code 4XX & 5XX
...
...
@@ -72,15 +72,18 @@ class Bridge {
}
retObj
=
yield
this
.
proxyWechaty
(
'
init
'
)
if
(
retObj
&&
/^
2|3
/
.
test
(
retObj
.
code
))
{
// HTTP Code 2XX & 3XX
if
(
retObj
&&
/^
(
2|3
)
/
.
test
(
retObj
.
code
))
{
// HTTP Code 2XX & 3XX
log
.
verbose
(
'
PuppetWebBridge
'
,
'
inject() Wechaty.init() return code[%d] message[%s] port[%d]
'
,
retObj
.
code
,
retObj
.
message
,
retObj
.
port
)
}
else
{
// HTTP Code 4XX & 5XX
throw
new
Error
(
'
execute proxyWechaty(init) error:
'
+
retObj
.
code
+
'
,
'
+
retObj
.
message
)
}
// const r = yield this.proxyWechaty('initClog')
// log.warn('PuppetWebBridge', 'initClog(): %s', r)
const
r
=
yield
this
.
ding
(
'
inject()
'
)
if
(
r
!==
'
inject()
'
)
{
throw
new
Error
(
'
fail to get right return from call ding()
'
)
}
log
.
verbose
(
'
PuppetWebBridge
'
,
'
inject() ding success
'
)
return
true
...
...
src/puppet-web-browser.js
浏览文件 @
ffbd0d63
...
...
@@ -146,6 +146,7 @@ class Browser extends EventEmitter {
,
'
NoSuchWindowError: no such window: target window already closed
'
]
const
crashRegex
=
new
RegExp
(
crashMsgs
.
join
(
'
|
'
),
'
i
'
)
if
(
crashRegex
.
test
(
e
.
message
))
{
log
.
warn
(
'
PuppetWebBrowser
'
,
'
driver.quit() browser crashed
'
)
}
else
{
log
.
warn
(
'
PuppetWebBrowser
'
,
'
driver.quit() exception: %s
'
,
e
.
message
)
}
})
...
...
@@ -316,6 +317,7 @@ class Browser extends EventEmitter {
this
.
live
=
false
// must use nextTick here, or promise will hang... 2016/6/10
process
.
nextTick
(()
=>
{
log
.
verbose
(
'
PuppetWebBrowser
'
,
'
dead() emit a `dead` event
'
)
this
.
emit
(
'
dead
'
,
errMsg
)
})
}
...
...
src/puppet-web-event.js
浏览文件 @
ffbd0d63
...
...
@@ -51,6 +51,7 @@ const PuppetWebEvent = {
}
function
onBrowserDead
(
e
)
{
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead()
'
)
// because this function is async, so maybe entry more than one times.
// guard by variable: onBrowserBirthing to prevent the 2nd time entrance.
if
(
this
.
onBrowserBirthing
)
{
...
...
src/puppet-web.js
浏览文件 @
ffbd0d63
...
...
@@ -186,7 +186,7 @@ class PuppetWeb extends Puppet {
watchDog
(
data
,
options
)
{
log
.
silly
(
'
PuppetWeb
'
,
'
watchDog(%s)
'
,
data
)
options
=
options
||
{}
const
timeout
=
options
.
timeout
||
60000
// 60s default. can be override in options
const
timeout
=
options
.
timeout
||
60000
// 60s default. can be override in options
but be careful about the number zero(0)
const
type
=
options
.
type
||
'
food
'
// just a name
if
(
this
.
watchDogTimer
)
{
clearTimeout
(
this
.
watchDogTimer
)
}
...
...
@@ -229,6 +229,7 @@ class PuppetWeb extends Puppet {
}
watchDogReset
(
timeout
)
{
log
.
warn
(
'
PuppetWeb
'
,
'
watchDogReset() timeout %d
'
,
timeout
)
const
e
=
new
Error
(
'
watchdog reset after
'
+
Math
.
floor
(
timeout
/
1000
)
+
'
seconds
'
)
this
.
emit
(
'
error
'
,
e
)
return
Event
.
onBrowserDead
.
call
(
this
,
e
)
...
...
test/puppet-web-event-spec.js
0 → 100644
浏览文件 @
ffbd0d63
const
co
=
require
(
'
co
'
)
const
util
=
require
(
'
util
'
)
const
test
=
require
(
'
tap
'
).
test
const
retryPromise
=
require
(
'
retry-promise
'
).
default
const
log
=
require
(
'
../src/npmlog-env
'
)
const
PORT
=
process
.
env
.
WECHATY_PORT
||
58788
const
HEAD
=
process
.
env
.
WECHATY_HEAD
||
false
const
SESSION
=
'
unit-test-session.wechaty.json
'
const
PuppetWeb
=
require
(
'
../src/puppet-web
'
)
const
PuppetWebEvent
=
require
(
'
../src/puppet-web-event
'
)
test
(
'
Puppet Web Event smoking test
'
,
function
(
t
)
{
let
pw
=
new
PuppetWeb
({
port
:
PORT
,
head
:
HEAD
,
session
:
SESSION
})
t
.
ok
(
pw
,
'
should instantiated a PuppetWeb
'
)
co
(
function
*
()
{
yield
pw
.
init
()
t
.
pass
(
'
should be inited
'
)
yield
PuppetWebEvent
.
onBrowserDead
.
call
(
pw
,
'
test
'
)
})
.
catch
(
e
=>
t
.
fail
(
e
))
// Reject
.
then
(
r
=>
{
// Finally 1
pw
.
quit
().
then
(
t
.
end
)
})
.
catch
(
e
=>
t
.
fail
(
e
))
// Exception
})
test/puppet-web-spec.js
浏览文件 @
ffbd0d63
...
...
@@ -125,13 +125,16 @@ test('Puppet Web watchdog timer', function(t) {
t
.
pass
(
'
should kill both browser & bridge
'
)
pw
.
once
(
'
error
'
,
e
=>
{
t
.
ok
(
/watchdog
timeout/i
.
test
(
e
),
'
should emit error
after watchdog timeout
'
)
t
.
ok
(
/watchdog
reset/i
.
test
(
e
.
message
),
'
should get event[error]
after watchdog timeout
'
)
})
pw
.
watchDog
(
'
feed_and_active_it
'
,
{
timeout
:
1
})
yield
new
Promise
((
resolve
)
=>
setTimeout
(()
=>
resolve
(),
2
))
// wait untill reset
t
.
pass
(
'
should feed the watchdog and had already fireed a reset above
'
)
pw
.
watchDog
(
'
feed_and_active_it
'
,
{
timeout
:
10
})
t
.
pass
(
'
should feed the watchdog and set timeout
'
)
pw
.
once
(
'
error
'
,
e
=>
t
.
fail
(
'
waitDing() triggered watchDogReset()
'
))
const
EXPECTED_DING_DATA
=
'
dingdong
'
pw
.
watchDog
(
'
feed to extend the dog life
'
)
const
dong
=
yield
waitDing
(
EXPECTED_DING_DATA
)
t
.
equal
(
dong
,
EXPECTED_DING_DATA
,
'
should get EXPECTED_DING_DATA from ding after watchdog reset
'
)
})
...
...
@@ -146,12 +149,13 @@ test('Puppet Web watchdog timer', function(t) {
return
/////////////////////////////////////////////////////////////////////////////
function
waitDing
(
data
)
{
const
max
=
30
const
backoff
=
1
00
const
max
=
7
const
backoff
=
20
00
// max = (2*totalTime/backoff) ^ (1/2)
// timeout = 11250 for {max: 15, backoff: 100}
// timeout = 45000 for {max: 30, backoff: 100}
// timeout = 11,250 for {max: 15, backoff: 100}
// timeout = 45,000 for {max: 30, backoff: 100}
// timeout = 49,000 for {max: 7, backoff: 2000}
const
timeout
=
max
*
(
backoff
*
max
)
/
2
return
retryPromise
({
max
:
max
,
backoff
:
backoff
},
function
(
attempt
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录