Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
fb02f7c3
W
wechaty
项目概览
weixin_46011646
/
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,发现更多精彩内容 >>
提交
fb02f7c3
编写于
5月 08, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
finish smoking tests
上级
b6db59a7
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
80 addition
and
79 deletion
+80
-79
lib/puppet-web-browser.js
lib/puppet-web-browser.js
+3
-3
lib/puppet-web-injectio.js
lib/puppet-web-injectio.js
+8
-7
lib/puppet-web-server.js
lib/puppet-web-server.js
+34
-29
tests/puppet-web-browser-tests.js
tests/puppet-web-browser-tests.js
+27
-31
tests/puppet-web-tests.js
tests/puppet-web-tests.js
+1
-3
tests/webdriver-tests.js
tests/webdriver-tests.js
+7
-6
未找到文件。
lib/puppet-web-browser.js
浏览文件 @
fb02f7c3
...
...
@@ -29,7 +29,7 @@ class Browser {
}
open
()
{
const
WX_URL
=
'
http
://zixia.net/~zixia/dl/
'
// 'http
s://wx.qq.com'
const
WX_URL
=
'
https://wx.qq.com
'
console
.
error
(
`browser init
${
this
.
browser
}
:
${
this
.
port
}
`
)
this
.
driver
=
new
WebDriver
.
Builder
().
forBrowser
(
this
.
browser
).
build
()
...
...
@@ -44,7 +44,7 @@ class Browser {
)
}
inject
()
{
const
injectio
=
getInjectio
()
const
injectio
=
this
.
getInjectio
()
console
.
error
(
'
injecting
'
)
return
this
.
execute
(
injectio
,
this
.
port
)
.
then
(()
=>
{
...
...
lib/puppet-web-injectio.js
浏览文件 @
fb02f7c3
...
...
@@ -53,12 +53,12 @@
,
send
:
send
,
clog
:
clog
// Console log
,
slog
:
slog
// Socket IO log
,
ping
:
p
ing
,
ding
:
d
ing
,
quit
:
quit
}
function
isReady
()
{
return
(
typeof
angular
)
!==
'
undefined
'
&&
angular
.
element
&&
angular
.
element
(
"
body
"
)
return
!!
((
typeof
angular
)
!==
'
undefined
'
&&
angular
.
element
&&
angular
.
element
(
"
body
"
)
)
}
function
init
()
{
// XXX
...
...
@@ -108,7 +108,7 @@
clog
(
'
quit()
'
)
}
function
slog
(
data
)
{
return
Wechaty
.
socket
&&
Wechaty
.
socket
.
emit
(
'
log
'
,
data
)
}
function
ping
()
{
return
'
p
ong
'
}
function
ding
()
{
return
'
d
ong
'
}
function
send
(
ToUserName
,
Content
)
{
var
c
=
Wechaty
.
glue
.
chatFactory
var
m
=
c
.
createMessage
({
...
...
@@ -157,10 +157,11 @@
Wechaty
.
glue
.
rootScope
.
$on
(
"
message:add:success
"
,
function
(
event
,
data
)
{
socket
.
emit
(
'
message
'
,
data
)
})
// ping -> pong. for test & live check purpose
socket
.
on
(
'
ping
'
,
function
(
e
)
{
clog
(
'
received socket io event: ping. emit pong...
'
)
socket
.
emit
(
'
pong
'
,
'
pong
'
)
// ding -> dong. for test & live check purpose
// ping/pong are reserved by socket.io https://github.com/socketio/socket.io/issues/2414
socket
.
on
(
'
ding
'
,
function
(
e
)
{
clog
(
'
received socket io event: ding. emit dong...
'
)
socket
.
emit
(
'
dong
'
,
'
dong
'
)
})
// re-connect XXX will socketio library auto re-connect by itself???
// socket.on('disconnect', function(e) {
...
...
lib/puppet-web-server.js
浏览文件 @
fb02f7c3
...
...
@@ -92,9 +92,9 @@ class Server extends EventEmitter {
next
()
})
app
.
get
(
'
/
p
ing
'
,
function
(
req
,
res
)
{
console
.
error
(
new
Date
()
+
'
GET /
p
ing
'
)
res
.
send
(
'
p
ong
'
)
app
.
get
(
'
/
d
ing
'
,
function
(
req
,
res
)
{
console
.
error
(
new
Date
()
+
'
GET /
d
ing
'
)
res
.
send
(
'
d
ong
'
)
})
// app.post('/', function (req, res) {
...
...
@@ -138,6 +138,7 @@ class Server extends EventEmitter {
,
'
login
'
,
'
logout
'
,
'
unload
'
,
'
zixia
'
]
events
.
map
(
e
=>
{
s
.
on
(
e
,
data
=>
{
...
...
@@ -146,6 +147,10 @@ class Server extends EventEmitter {
})
})
s
.
on
(
'
dong
'
,
data
=>
{
console
.
log
(
`recv event[dong] from browser:`
+
data
)
})
/**
* prevent lost event: buffer new event received when socket disconnected
while (buff.length) {
...
...
@@ -167,15 +172,15 @@ class Server extends EventEmitter {
this
.
browser
.
quit
()
delete
this
.
browser
}
if
(
this
.
socketClient
)
{
this
.
socketClient
.
disconnect
(
0
)
delete
this
.
socketClient
}
if
(
this
.
socketServer
)
{
socketServer
.
httpsServer
.
close
()
socketServer
.
close
()
delete
this
.
socketServer
}
if
(
this
.
socketClient
)
{
this
.
socketClient
.
disconnect
(
0
)
delete
this
.
socketClient
}
if
(
this
.
server
)
{
this
.
server
.
close
()
delete
this
.
server
...
...
tests/puppet-web-browser-tests.js
浏览文件 @
fb02f7c3
...
...
@@ -4,42 +4,38 @@ const Browser = require('../lib/puppet-web-browser')
test
(
'
Browser class smoking tests
'
,
function
(
t
)
{
//t.plan(5)
const
PORT
=
58788
const
b
=
new
Browser
(
'
firefox
'
,
PORT
)
const
b
=
new
Browser
(
'
chrome
'
,
PORT
)
t
.
ok
(
b
,
'
Browser instance created
'
)
b
.
open
()
.
then
(()
=>
{
t
.
ok
(
true
,
'
url opened
'
)
b
.
execute
(
'
return 1+1
'
)
.
then
(
n
=>
{
t
.
equal
(
n
,
2
,
'
exec 1+1 in browser, equal 2
'
)
// b.inject().then( r => {
// console.log('injected: ' + r)
b
.
quit
()
t
.
end
()
// })
b
.
inject
()
.
then
(()
=>
{
t
.
ok
(
true
,
'
wechaty injected
'
)
Promise
.
all
([
b
.
execute
(
'
return Wechaty && Wechaty.ding()
'
)
// ret_ding
,
b
.
execute
(
'
return Wechaty && Wechaty.isReady()
'
)
// ret_ready
]).
then
(([
ret_ding
,
ret_ready
])
=>
{
t
.
equal
(
ret_ding
,
'
dong
'
,
'
Wechaty.ding() returns dong
'
)
t
.
equal
(
typeof
ret_ready
,
'
boolean
'
,
'
Wechaty.isReady() returns boollean
'
)
b
.
quit
()
+
t
.
end
()
}).
catch
((
e
)
=>
{
// Promise.all
t
.
ok
(
false
,
'
Promise.all promise rejected:
'
+
e
)
b
.
quit
()
+
t
.
end
()
})
// b.inject()
// .then(() => {
// t.ok(true, 'wechaty injected')
// b.execute('return Wechaty && Wechaty.ping()')
// .then(r => t.equal(r, 'pong', 'Wechaty.ping() returns pong'))
// b.execute('return Wechaty && Wechaty.isReady()')
// .then(r => t.notEqual(typeof r, 'bool', 'Wechaty.isReady() returns bool'))
// b.quit(true)
// t.end()
// })
}).
catch
((
e
)
=>
{
// b.inject
t
.
ok
(
false
,
'
b.inject promise rejected:
'
+
e
)
b
.
quit
()
+
t
.
end
()
})
}).
catch
((
e
)
=>
{
// b.open
t
.
ok
(
false
,
'
open promise rejected:
'
+
e
)
t
.
end
()
+
b
.
quit
()
})
})
tests/puppet-web-tests.js
浏览文件 @
fb02f7c3
...
...
@@ -4,7 +4,5 @@ const PuppetWeb = require('../lib/puppet-web')
test
(
'
test
'
,
function
(
t
)
{
t
.
plan
(
1
)
t
.
ok
(
ret
,
'
test
'
)
t
.
pass
(
'
test
'
)
})
console
.
log
(
'
ok
'
)
tests/webdriver-tests.js
浏览文件 @
fb02f7c3
...
...
@@ -29,15 +29,16 @@ test('WebDriver smoking test', function(t) {
t
.
end
()
driver
.
quit
()
}).
catch
(
e
=>
{
t
.
ok
(
false
,
'
promise rejected. e:
'
+
e
)
t
.
end
()
driver
.
quit
()
})
/* .finally(() => {
console.log('final')
})
*/
})
function
verifyJson
(
expected
)
{
return
function
(
actual
)
{
assert
(
JSON
.
stringify
(
actual
)).
equalTo
(
JSON
.
stringify
(
expected
))
};
}
function
execute
()
{
return
driver
.
executeScript
.
apply
(
driver
,
arguments
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录