Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
818c513a
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 接近 3 年
通知
298
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
818c513a
编写于
11月 04, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
export default can lead to problems, get rid of them
#40
上级
8d67d6f5
变更
55
隐藏空白更改
内联
并排
Showing
55 changed file
with
453 addition
and
344 deletion
+453
-344
README.md
README.md
+1
-1
bin/client.ts
bin/client.ts
+7
-0
bin/doctor.ts
bin/doctor.ts
+7
-0
bin/version.ts
bin/version.ts
+7
-0
example/gist-bot/index.ts
example/gist-bot/index.ts
+3
-3
example/gist-bot/on-friend.ts
example/gist-bot/on-friend.ts
+8
-1
example/gist-bot/on-message.ts
example/gist-bot/on-message.ts
+8
-1
example/gist-bot/on-room-join.ts
example/gist-bot/on-room-join.ts
+8
-1
index.ts
index.ts
+12
-31
src/brolog-env.ts
src/brolog-env.ts
+0
-2
src/config.spec.ts
src/config.spec.ts
+17
-15
src/config.ts
src/config.ts
+2
-3
src/contact.ts
src/contact.ts
+4
-6
src/friend-request.ts
src/friend-request.ts
+3
-5
src/io-client.ts
src/io-client.ts
+6
-8
src/io.ts
src/io.ts
+3
-5
src/message-media.ts
src/message-media.ts
+5
-9
src/message.spec.ts
src/message.spec.ts
+9
-2
src/message.ts
src/message.ts
+5
-6
src/puppet-web/bridge.ts
src/puppet-web/bridge.ts
+2
-4
src/puppet-web/browser-cookie.ts
src/puppet-web/browser-cookie.ts
+6
-8
src/puppet-web/browser-driver.ts
src/puppet-web/browser-driver.ts
+2
-4
src/puppet-web/browser.ts
src/puppet-web/browser.ts
+6
-8
src/puppet-web/event.ts
src/puppet-web/event.ts
+7
-9
src/puppet-web/firer.spec.ts
src/puppet-web/firer.spec.ts
+6
-7
src/puppet-web/firer.ts
src/puppet-web/firer.ts
+7
-9
src/puppet-web/friend-request.spec.ts
src/puppet-web/friend-request.spec.ts
+12
-5
src/puppet-web/friend-request.ts
src/puppet-web/friend-request.ts
+8
-8
src/puppet-web/index.ts
src/puppet-web/index.ts
+7
-10
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+30
-24
src/puppet-web/server.ts
src/puppet-web/server.ts
+2
-4
src/puppet-web/ssl-pem.ts
src/puppet-web/ssl-pem.ts
+0
-4
src/puppet-web/watchdog.ts
src/puppet-web/watchdog.ts
+4
-5
src/puppet.spec.ts
src/puppet.spec.ts
+7
-0
src/puppet.ts
src/puppet.ts
+5
-8
src/room.ts
src/room.ts
+4
-7
src/state-monitor.spec.ts
src/state-monitor.spec.ts
+1
-1
src/state-monitor.ts
src/state-monitor.ts
+10
-12
src/util-lib.spec.ts
src/util-lib.spec.ts
+7
-0
src/util-lib.ts
src/util-lib.ts
+9
-4
src/wechaty.ts
src/wechaty.ts
+9
-12
test/contact.spec.ts
test/contact.spec.ts
+7
-0
test/docker.spec.ts
test/docker.spec.ts
+7
-0
test/electron.spec.ts
test/electron.spec.ts
+7
-0
test/node.spec.ts
test/node.spec.ts
+7
-0
test/puppet-web/bridge.spec.ts
test/puppet-web/bridge.spec.ts
+48
-54
test/puppet-web/browser.spec.ts
test/puppet-web/browser.spec.ts
+7
-0
test/puppet-web/event.spec.ts
test/puppet-web/event.spec.ts
+17
-5
test/puppet-web/puppet-web.spec.ts
test/puppet-web/puppet-web.spec.ts
+13
-4
test/puppet-web/server.spec.ts
test/puppet-web/server.spec.ts
+22
-12
test/puppet-web/watchdog.spec.ts
test/puppet-web/watchdog.spec.ts
+7
-0
test/room.spec.ts
test/room.spec.ts
+7
-0
test/webdriver-phantomjs.spec.ts
test/webdriver-phantomjs.spec.ts
+7
-0
test/webdriver.spec.ts
test/webdriver.spec.ts
+24
-17
test/wechaty.spec.ts
test/wechaty.spec.ts
+7
-0
未找到文件。
README.md
浏览文件 @
818c513a
...
...
@@ -30,7 +30,7 @@ Wechaty is a Bot Framework for Wechat **Personal** Account that helps you easy c
The shortest wechat bot code in the world: 6 lines JavaScript
```
javascript
const
Wechaty
=
require
(
'
wechaty
'
)
const
{
Wechaty
}
=
require
(
'
wechaty
'
)
Wechaty
.
instance
()
// Singleton
.
on
(
'
scan
'
,
(
url
,
code
)
=>
console
.
log
(
`Scan QrCode to login:
${
code
}
\n
${
url
}
`
))
...
...
bin/client.ts
浏览文件 @
818c513a
#!/usr/bin/env node
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
IoClient
...
...
bin/doctor.ts
浏览文件 @
818c513a
#!/usr/bin/env node
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
*
as
os
from
'
os
'
...
...
bin/version.ts
浏览文件 @
818c513a
#!/usr/bin/env node
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
Wechaty
}
from
'
../
'
...
...
example/gist-bot/index.ts
浏览文件 @
818c513a
...
...
@@ -13,9 +13,9 @@ import {
,
log
}
from
'
../../
'
import
onMessage
from
'
./on-message
'
import
onFriend
from
'
./on-friend
'
import
onRoomJoin
from
'
./on-room-join
'
import
{
onMessage
}
from
'
./on-message
'
import
{
onFriend
}
from
'
./on-friend
'
import
{
onRoomJoin
}
from
'
./on-room-join
'
const
welcome
=
`
=============== Powered by Wechaty ===============
...
...
example/gist-bot/on-friend.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
Contact
,
FriendRequest
,
Room
}
from
'
../../
'
export
default
async
function
onFriend
(
contact
:
Contact
,
request
?:
FriendRequest
):
Promise
<
void
>
{
export
async
function
onFriend
(
contact
:
Contact
,
request
?:
FriendRequest
):
Promise
<
void
>
{
try
{
if
(
!
request
)
{
console
.
log
(
'
New friend
'
+
contact
.
name
()
+
'
relationship confirmed!
'
)
...
...
example/gist-bot/on-message.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
Message
,
Room
}
from
'
../../
'
export
default
async
function
onMessage
(
message
:
Message
):
Promise
<
void
>
{
export
async
function
onMessage
(
message
:
Message
):
Promise
<
void
>
{
try
{
const
room
=
message
.
room
()
const
sender
=
message
.
from
()
...
...
example/gist-bot/on-room-join.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
Contact
,
Room
,
Sayable
}
from
'
../../
'
export
default
async
function
onRoomJoin
(
export
async
function
onRoomJoin
(
this
:
Sayable
,
room
:
Room
,
inviteeList
:
Contact
[]
...
...
index.ts
浏览文件 @
818c513a
import
{
Config
,
Sayable
}
from
'
./src/config
'
import
Contact
from
'
./src/contact
'
import
FriendRequest
from
'
./src/friend-request
'
import
IoClient
from
'
./src/io-client
'
import
Message
from
'
./src/message
'
import
Puppet
from
'
./src/puppet
'
import
PuppetWeb
from
'
./src/puppet-web/
'
import
Room
from
'
./src/room
'
import
UtilLib
from
'
./src/util-lib
'
import
Wechaty
from
'
./src/wechaty
'
import
log
from
'
./src/brolog-env
'
,
log
}
from
'
./src/config
'
import
{
Contact
}
from
'
./src/contact
'
import
{
FriendRequest
}
from
'
./src/friend-request
'
import
{
IoClient
}
from
'
./src/io-client
'
import
{
Message
}
from
'
./src/message
'
import
{
Puppet
}
from
'
./src/puppet
'
import
{
PuppetWeb
}
from
'
./src/puppet-web/
'
import
{
Room
}
from
'
./src/room
'
import
{
UtilLib
}
from
'
./src/util-lib
'
import
{
Wechaty
}
from
'
./src/wechaty
'
const
VERSION
=
require
(
'
./package.json
'
).
version
export
default
Wechaty
export
{
Config
,
Contact
...
...
@@ -28,24 +26,7 @@ export {
,
Room
,
Sayable
,
UtilLib
,
Wechaty
,
log
// for convenionce use npmlog with environment variable LEVEL
,
VERSION
}
Object
.
assign
(
Wechaty
,
{
Config
,
Contact
,
FriendRequest
,
IoClient
,
Message
,
Puppet
,
PuppetWeb
,
Room
,
UtilLib
,
Wechaty
,
default
:
Wechaty
,
log
// for convenionce use npmlog with environment variable LEVEL
,
VERSION
})
exports
=
Wechaty
}
src/brolog-env.ts
浏览文件 @
818c513a
...
...
@@ -28,5 +28,3 @@ if (levelRegex.test(level)) {
}
export
{
Brolog
}
export
default
log
src/config.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
Config
from
'
./config
'
import
Puppet
from
'
./puppet
'
test
(
'
Config list vars
'
,
t
=>
{
// t.truthy(Config.default , 'should export default')
// t.truthy(Config.Config , 'should export Config')
import
{
Config
}
from
'
./config
'
import
{
Puppet
}
from
'
./puppet
'
test
(
'
important variables
'
,
t
=>
{
t
.
true
(
'
head
'
in
Config
,
'
should exist `head` in Config
'
)
t
.
true
(
'
puppet
'
in
Config
,
'
should exist `puppet` in Config
'
)
t
.
true
(
'
apihost
'
in
Config
,
'
should exist `apihost` in Config
'
)
...
...
@@ -23,7 +27,7 @@ test('Config list vars', t => {
t
.
truthy
(
Config
.
CMD_CHROMIUM
,
'
should export CMD_CHROMIUM
'
)
})
test
(
'
Config methods
'
,
t
=>
{
test
(
'
validApiHost()
'
,
t
=>
{
const
OK_APIHOSTS
=
[
'
api.wechaty.io
'
,
'
wechaty.io:8080
'
...
...
@@ -45,19 +49,17 @@ test('Config methods', t => {
})
test
(
'
Config puppetInstance
'
,
t
=>
{
test
(
'
puppetInstance()
'
,
t
=>
{
t
.
throws
(()
=>
{
Config
.
puppetInstance
()
},
Error
,
'
should throw when not initialized
'
)
const
EXPECTED
=
{
userId
:
'
test
'
}
const
puppet
=
<
Puppet
>
EXPECTED
Config
.
puppetInstance
(
puppet
)
const
EXPECTED
=
<
Puppet
>
{
userId
:
'
test
'
}
const
mockPuppet
=
EXPECTED
Config
.
puppetInstance
(
p
uppet
)
Config
.
puppetInstance
(
mockP
uppet
)
let
instance
=
Config
.
puppetInstance
()
t
.
deepEqual
(
instance
,
<
Puppet
>
EXPECTED
,
'
should equal with initialized data
'
)
t
.
deepEqual
(
instance
,
EXPECTED
,
'
should equal with initialized data
'
)
Config
.
puppetInstance
(
null
)
t
.
throws
(()
=>
{
...
...
@@ -66,7 +68,7 @@ test('Config puppetInstance', t => {
})
test
(
'
Config docker mode
'
,
t
=>
{
test
(
'
isDocker
'
,
t
=>
{
t
.
true
(
'
isDocker
'
in
Config
,
'
should identify docker env by `isDocker`
'
)
if
(
'
C9_PORT
'
in
process
.
env
)
{
...
...
src/config.ts
浏览文件 @
818c513a
...
...
@@ -6,8 +6,8 @@
import
{
execSync
}
from
'
child_process
'
import
*
as
fs
from
'
fs
'
import
Puppet
from
'
./puppet
'
import
log
from
'
./brolog-env
'
import
{
Puppet
}
from
'
./puppet
'
import
{
log
}
from
'
./brolog-env
'
export
type
PuppetName
=
'
web
'
|
'
android
'
|
'
ios
'
export
type
HeadName
=
'
chrome
'
|
'
phantomjs
'
|
'
firefox
'
...
...
@@ -192,4 +192,3 @@ export interface Sleepable {
}
export
{
log
}
export
default
Config
src/contact.ts
浏览文件 @
818c513a
...
...
@@ -10,10 +10,10 @@ import {
Config
,
Sayable
}
from
'
./config
'
import
Message
from
'
./message
'
import
UtilLib
from
'
./util-lib
'
import
Wechaty
from
'
./wechaty
'
import
log
from
'
./brolog-env
'
import
{
Message
}
from
'
./message
'
import
{
UtilLib
}
from
'
./util-lib
'
import
{
Wechaty
}
from
'
./wechaty
'
import
{
log
}
from
'
./brolog-env
'
type
ContactObj
=
{
address
:
string
...
...
@@ -290,5 +290,3 @@ export class Contact implements Sayable {
// return []
// }
export
default
Contact
src/friend-request.ts
浏览文件 @
818c513a
/**
* Wechat for Bot. Connecting ChatBots
* Wechat
y - Wechat
for Bot. Connecting ChatBots
*
* Interface for puppet
*
...
...
@@ -10,8 +10,8 @@
*
*/
import
Config
from
'
./config
'
import
Contact
from
'
./contact
'
import
{
Config
}
from
'
./config
'
import
{
Contact
}
from
'
./contact
'
export
abstract
class
FriendRequest
{
...
...
@@ -29,5 +29,3 @@ export abstract class FriendRequest {
public
abstract
accept
():
Promise
<
void
>
}
export
default
FriendRequest
src/io-client.ts
浏览文件 @
818c513a
...
...
@@ -16,11 +16,11 @@
*/
// import Brolog from 'brolog'
import
Config
from
'
./config
'
import
Io
from
'
./io
'
import
StateMonitor
from
'
./state-monitor
'
import
Wechaty
from
'
./wechaty
'
import
brolog
from
'
./brolog-env
'
import
{
Config
}
from
'
./config
'
import
{
Io
}
from
'
./io
'
import
{
StateMonitor
}
from
'
./state-monitor
'
import
{
Wechaty
}
from
'
./wechaty
'
import
{
Brolog
}
from
'
./brolog-env
'
export
class
IoClient
{
...
...
@@ -31,7 +31,7 @@ export class IoClient {
constructor
(
private
token
:
string
=
Config
.
token
||
Config
.
DEFAULT_TOKEN
,
private
log
:
any
=
brolog
,
private
log
:
any
=
new
Brolog
()
)
{
if
(
!
log
)
{
const
e
=
new
Error
(
'
constructor() log(npmlog/brolog) must be set
'
)
...
...
@@ -299,5 +299,3 @@ export class IoClient {
}
}
}
export
default
IoClient
src/io.ts
浏览文件 @
818c513a
...
...
@@ -14,11 +14,11 @@ import * as WebSocket from 'ws'
import
{
Config
// WechatyEventName
,
log
}
from
'
./config
'
import
StateMonitor
from
'
./state-monitor
'
import
Wechaty
from
'
./wechaty
'
import
log
from
'
./brolog-env
'
import
{
StateMonitor
}
from
'
./state-monitor
'
import
{
Wechaty
}
from
'
./wechaty
'
export
type
IoSetting
=
{
wechaty
:
Wechaty
...
...
@@ -448,5 +448,3 @@ export class Io {
}
}
export
default
Io
src/message-media.ts
浏览文件 @
818c513a
...
...
@@ -6,14 +6,12 @@
* https://github.com/zixia/wechaty
*
*/
import
Config
from
'
./config
'
import
Message
from
'
./message
'
import
UtilLib
from
'
./util-lib
'
import
{
Config
,
log
}
from
'
./config
'
import
{
Message
}
from
'
./message
'
import
{
UtilLib
}
from
'
./util-lib
'
import
log
from
'
./brolog-env
'
import
PuppetWeb
from
'
./puppet-web/puppet-web
'
import
PuppetWebBridge
from
'
./puppet-web/bridge
'
import
{
PuppetWeb
}
from
'
./puppet-web/puppet-web
'
import
{
Bridge
as
PuppetWebBridge
}
from
'
./puppet-web/bridge
'
export
class
MediaMessage
extends
Message
{
private
bridge
:
PuppetWebBridge
...
...
@@ -76,5 +74,3 @@ export class MediaMessage extends Message {
})
}
}
export
default
MediaMessage
src/message.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
Config
,
log
}
from
'
./config
'
import
Message
from
'
./message
'
import
PuppetWeb
from
'
./puppet-web/
'
import
{
Message
}
from
'
./message
'
import
{
PuppetWeb
}
from
'
./puppet-web/
'
const
MOCK_USER_ID
=
'
TEST-USER-ID
'
...
...
src/message.ts
浏览文件 @
818c513a
/**
*
* Wechaty: Wechat for Bot. Connecting ChatBots
* Wechaty:
* * Wechaty -
Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
...
...
@@ -10,12 +10,12 @@ import {
Config
,
RecommendInfo
,
Sayable
,
log
}
from
'
./config
'
import
Contact
from
'
./contact
'
import
Room
from
'
./room
'
import
UtilLib
from
'
./util-lib
'
import
log
from
'
./brolog-env
'
import
{
Contact
}
from
'
./contact
'
import
{
Room
}
from
'
./room
'
import
{
UtilLib
}
from
'
./util-lib
'
export
type
MessageRawObj
=
{
MsgId
:
string
...
...
@@ -352,7 +352,6 @@ export class Message implements Sayable {
Message
.
initType
()
export
default
Message
export
*
from
'
./message-media
'
/*
...
...
src/puppet-web/bridge.ts
浏览文件 @
818c513a
...
...
@@ -12,9 +12,9 @@
/* tslint:disable:no-var-requires */
const
retryPromise
=
require
(
'
retry-promise
'
).
default
import
log
from
'
../brolog-env
'
import
{
log
}
from
'
../brolog-env
'
import
PuppetWeb
from
'
./puppet-web
'
import
{
PuppetWeb
}
from
'
./puppet-web
'
export
class
Bridge
{
...
...
@@ -382,8 +382,6 @@ export class Bridge {
}
}
export
default
Bridge
/* tslint:disable:jsdoc-format */
/* tslint:disable:max-line-length */
/**
...
...
src/puppet-web/browser-cookie.ts
浏览文件 @
818c513a
/**
* Wechat for Bot. Connecting ChatBots
* Wechat
y - Wechat
for Bot. Connecting ChatBots
*
* BrowserCookie
*
...
...
@@ -12,9 +12,9 @@
import
*
as
fs
from
'
fs
'
const
arrify
=
require
(
'
arrify
'
)
import
log
from
'
../brolog-env
'
import
{
log
}
from
'
../config
'
import
BrowserDriver
from
'
./browser-driver
'
import
{
BrowserDriver
}
from
'
./browser-driver
'
/**
* The reason that driverCookie type defined here
...
...
@@ -135,7 +135,7 @@ export class BrowserCookie {
public
async
load
():
Promise
<
void
>
{
if
(
!
this
.
storeFile
)
{
log
.
silly
(
'
PuppetWebBrowserCookie
'
,
'
load() skipped
because
no session store file
'
)
log
.
silly
(
'
PuppetWebBrowserCookie
'
,
'
load() skipped
:
no session store file
'
)
return
// } else if (this.browser.dead()) {
// throw new Error('loadSession() - browser dead')
...
...
@@ -146,14 +146,14 @@ export class BrowserCookie {
try
{
fs
.
statSync
(
storeFile
).
isFile
()
}
catch
(
e
)
{
log
.
silly
(
'
PuppetWebBrowserCookie
'
,
'
load() skipped
because
session store file not exist
'
)
log
.
silly
(
'
PuppetWebBrowserCookie
'
,
'
load() skipped
:
session store file not exist
'
)
return
}
await
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
readFile
(
storeFile
,
(
err
,
jsonStr
)
=>
{
if
(
err
)
{
log
.
verbose
(
'
PuppetWebBrowserCookie
'
,
'
load(%s) skipped
because
error code: %s
'
,
this
.
storeFile
,
err
.
code
)
log
.
verbose
(
'
PuppetWebBrowserCookie
'
,
'
load(%s) skipped
:
error code: %s
'
,
this
.
storeFile
,
err
.
code
)
reject
()
return
}
...
...
@@ -218,5 +218,3 @@ export class BrowserCookie {
}
}
export
default
BrowserCookie
src/puppet-web/browser-driver.ts
浏览文件 @
818c513a
/**
* Wechat for Bot. Connecting ChatBots
* Wechat
y - Wechat
for Bot. Connecting ChatBots
*
* BrowserDriver
*
...
...
@@ -16,8 +16,8 @@ import {
import
{
Config
,
HeadName
,
log
}
from
'
../config
'
import
log
from
'
../brolog-env
'
export
class
BrowserDriver
{
private
driver
:
WebDriver
...
...
@@ -294,5 +294,3 @@ export class BrowserDriver {
public
navigate
()
{
return
this
.
driver
.
navigate
()
}
public
quit
()
{
return
this
.
driver
.
quit
()
}
}
export
default
BrowserDriver
src/puppet-web/browser.ts
浏览文件 @
818c513a
/**
* Wechat for Bot. Connecting ChatBots
* Wechat
y - Wechat
for Bot. Connecting ChatBots
*
* Interface for puppet
*
...
...
@@ -15,15 +15,15 @@ const retryPromise = require('retry-promise').default // https://github.com/ola
import
{
Config
,
HeadName
}
from
'
../config
'
import
StateMonitor
from
'
../state-monitor
'
import
log
from
'
../brolog-env
'
}
from
'
../config
'
import
{
StateMonitor
}
from
'
../state-monitor
'
import
{
log
}
from
'
../brolog-env
'
import
{
CookieType
,
BrowserCookie
}
from
'
./browser-cookie
'
import
BrowserDriver
from
'
./browser-driver
'
}
from
'
./browser-cookie
'
import
{
BrowserDriver
}
from
'
./browser-driver
'
export
type
BrowserSetting
=
{
head
:
HeadName
...
...
@@ -371,5 +371,3 @@ export class Browser extends EventEmitter {
public
readCookie
()
{
return
this
.
cookie
.
read
()
}
public
cleanCookie
()
{
return
this
.
cookie
.
clean
()
}
}
export
default
Browser
src/puppet-web/event.ts
浏览文件 @
818c513a
...
...
@@ -18,19 +18,19 @@
import
{
WatchdogFood
,
ScanInfo
}
from
'
../config
'
import
Contact
from
'
../contact
'
,
log
}
from
'
../config
'
import
{
Contact
}
from
'
../contact
'
import
{
Message
,
MediaMessage
}
from
'
../message
'
import
log
from
'
../brolog-env
'
}
from
'
../message
'
import
Firer
from
'
./firer
'
import
PuppetWeb
from
'
./puppet-web
'
import
{
Firer
}
from
'
./firer
'
import
{
PuppetWeb
}
from
'
./puppet-web
'
/* tslint:disable:variable-name */
export
const
PuppetWeb
Event
=
{
export
const
Event
=
{
onBrowserDead
,
onServerLogin
...
...
@@ -398,5 +398,3 @@ async function onServerMessage(this: PuppetWeb, data): Promise<void> {
return
}
export
default
PuppetWebEvent
src/puppet-web/firer.spec.ts
浏览文件 @
818c513a
/**
*
* Wechaty: Wechat for Bot. Connecting ChatBots
* Wechaty:
* * Wechaty -
Wechat for Bot. Connecting ChatBots
*
* Class PuppetWeb Firer
*
...
...
@@ -12,14 +12,13 @@
*/
import
{
test
}
from
'
ava
'
import
Firer
from
'
./firer
'
import
{
Firer
as
Firer
}
from
'
./firer
'
test
(
'
Firer smoking test
'
,
t
=>
{
t
.
true
(
true
,
'
should be true
'
)
})
test
(
'
Firer.parseFriendConfirm
'
,
t
=>
{
test
(
'
parseFriendConfirm()
'
,
t
=>
{
const
contentList
=
[
[
'
You have added 李卓桓 as your WeChat contact. Start chatting!
'
...
...
@@ -41,7 +40,7 @@ test('Firer.parseFriendConfirm', t => {
t
.
false
(
result
,
'
should be falsy for other msg
'
)
})
test
(
'
Firer.parseRoomJoin
'
,
t
=>
{
test
(
'
parseRoomJoin()
'
,
t
=>
{
const
contentList
:
[
string
,
string
,
string
[]][]
=
[
[
`You've invited "李卓桓" to the group chat`
...
...
@@ -83,7 +82,7 @@ test('Firer.parseRoomJoin', t => {
},
Error
,
'
should throws if message is not expected
'
)
})
test
(
'
Firer.parseRoomLeave
'
,
t
=>
{
test
(
'
parseRoomLeave()
'
,
t
=>
{
const
contentList
=
[
[
`You removed "Bruce LEE" from the group chat`
...
...
@@ -107,7 +106,7 @@ test('Firer.parseRoomLeave', t => {
},
Error
,
'
should throw if message is not expected
'
)
})
test
(
'
Firer.parseRoomTopic
'
,
t
=>
{
test
(
'
parseRoomTopic()
'
,
t
=>
{
const
contentList
=
[
[
`"李卓桓.PreAngel" changed the group name to "ding"`
...
...
src/puppet-web/firer.ts
浏览文件 @
818c513a
/**
*
* Wechaty: Wechat for Bot. Connecting ChatBots
* Wechaty:
* * Wechaty -
Wechat for Bot. Connecting ChatBots
*
* Class PuppetWeb Firer
*
...
...
@@ -20,18 +20,17 @@ const retryPromise = require('retry-promise').default
import
{
// RecommendInfo
}
from
'
../config
'
import
Contact
from
'
../contact
'
log
}
from
'
../config
'
import
{
Contact
}
from
'
../contact
'
import
{
Message
}
from
'
../message
'
import
log
from
'
../brolog-env
'
}
from
'
../message
'
import
FriendRequest
from
'
./friend-request
'
import
{
FriendRequest
}
from
'
./friend-request
'
/* tslint:disable:variable-name */
export
const
PuppetWeb
Firer
=
{
export
const
Firer
=
{
checkFriendConfirm
,
checkFriendRequest
...
...
@@ -376,4 +375,3 @@ async function checkRoomTopic(m: Message): Promise<void> {
}
}
export
default
PuppetWebFirer
src/puppet-web/friend-request.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
Config
from
'
../config
'
import
Contact
from
'
../contact
'
import
Message
from
'
../message
'
import
Puppet
from
'
../puppet
'
import
PuppetWebFriendRequest
from
'
./friend-request
'
import
{
Config
}
from
'
../config
'
import
{
Contact
}
from
'
../contact
'
import
{
Message
}
from
'
../message
'
import
{
Puppet
}
from
'
../puppet
'
import
{
FriendRequest
as
PuppetWebFriendRequest
}
from
'
./friend-request
'
Config
.
puppetInstance
({
userId
:
'
xxx
'
...
...
src/puppet-web/friend-request.ts
浏览文件 @
818c513a
/**
* Wechat for Bot. Connecting ChatBots
* Wechat
y - Wechat
for Bot. Connecting ChatBots
*
* Interface for puppet
*
...
...
@@ -19,13 +19,13 @@
/* tslint:disable:no-var-requires */
const
retryPromise
=
require
(
'
retry-promise
'
).
default
import
Contact
from
'
../contact
'
import
{
Contact
}
from
'
../contact
'
import
{
Config
,
RecommendInfo
}
from
'
../config
'
import
FriendRequest
from
'
../friend-request
'
import
log
from
'
../brolog-env
'
,
log
}
from
'
../config
'
import
{
FriendRequest
}
from
'
../friend-request
'
class
PuppetWebFriendRequest
extends
FriendRequest
{
...
...
@@ -38,7 +38,7 @@ class PuppetWebFriendRequest extends FriendRequest {
super
()
}
public
receive
(
info
:
RecommendInfo
):
PuppetWebFriendRequest
{
public
receive
(
info
:
RecommendInfo
):
void
{
log
.
verbose
(
'
PuppetWebFriendRequest
'
,
'
receive(%s)
'
,
info
)
if
(
!
info
||
!
info
.
UserName
)
{
...
...
@@ -62,7 +62,7 @@ class PuppetWebFriendRequest extends FriendRequest {
this
.
type
=
'
receive
'
return
this
return
}
public
confirm
(
contact
:
Contact
):
void
{
...
...
@@ -132,4 +132,4 @@ class PuppetWebFriendRequest extends FriendRequest {
}
export
default
PuppetWebFriendRequest
export
{
PuppetWebFriendRequest
as
FriendRequest
}
src/puppet-web/index.ts
浏览文件 @
818c513a
...
...
@@ -8,13 +8,10 @@
* https://github.com/zixia/wechaty
*
*/
export
{
Bridge
}
from
'
./bridge
'
export
{
Browser
}
from
'
./browser
'
export
{
PuppetWebEvent
as
Event
}
from
'
./event
'
export
{
Server
}
from
'
./server
'
export
{
Watchdog
}
from
'
./watchdog
'
import
PuppetWeb
from
'
./puppet-web
'
export
{
PuppetWeb
}
export
default
PuppetWeb
export
{
Bridge
}
from
'
./bridge
'
export
{
Browser
}
from
'
./browser
'
export
{
Event
}
from
'
./event
'
export
{
FriendRequest
}
from
'
./friend-request
'
export
{
PuppetWeb
}
from
'
./puppet-web
'
export
{
Server
}
from
'
./server
'
export
{
Watchdog
}
from
'
./watchdog
'
src/puppet-web/puppet-web.ts
浏览文件 @
818c513a
...
...
@@ -18,27 +18,27 @@ import {
,
HeadName
,
ScanInfo
,
WatchdogFood
}
from
'
../config
'
,
log
}
from
'
../config
'
import
Contact
from
'
../contact
'
import
{
Contact
}
from
'
../contact
'
// import FriendRequest from '../friend-request'
import
Message
from
'
../message
'
import
Puppet
from
'
../puppet
'
import
Room
from
'
../room
'
import
UtilLib
from
'
../util-lib
'
import
log
from
'
../brolog-env
'
import
Bridge
from
'
./bridge
'
import
Browser
from
'
./browser
'
import
Event
from
'
./event
'
import
Server
from
'
./server
'
import
Watchdog
from
'
./watchdog
'
import
{
Message
}
from
'
../message
'
import
{
Puppet
}
from
'
../puppet
'
import
{
Room
}
from
'
../room
'
import
{
UtilLib
}
from
'
../util-lib
'
import
{
Bridge
}
from
'
./bridge
'
import
{
Browser
}
from
'
./browser
'
import
{
Event
}
from
'
./event
'
import
{
Server
}
from
'
./server
'
import
{
Watchdog
}
from
'
./watchdog
'
export
type
PuppetWebSetting
=
{
head
?:
HeadName
profile
?:
string
}
const
DEFAULT_PUPPET_PORT
=
18788
//
//
W(87) X(88), ascii char code ;-]
const
DEFAULT_PUPPET_PORT
=
18788
// W(87) X(88), ascii char code ;-]
export
class
PuppetWeb
extends
Puppet
{
...
...
@@ -87,6 +87,12 @@ export class PuppetWeb extends Puppet {
await
this
.
initBridge
()
log
.
verbose
(
'
PuppetWeb
'
,
'
initBridge() done
'
)
/**
* state must set to `live`
* before feed Watchdog
*/
this
.
state
.
current
(
'
live
'
)
const
food
:
WatchdogFood
=
{
data
:
'
inited
'
,
timeout
:
120000
// 2 mins for first login
...
...
@@ -94,7 +100,6 @@ export class PuppetWeb extends Puppet {
this
.
emit
(
'
watchdog
'
,
food
)
log
.
verbose
(
'
PuppetWeb
'
,
'
init() done
'
)
this
.
state
.
current
(
'
live
'
)
return
}
catch
(
e
)
{
...
...
@@ -112,16 +117,19 @@ export class PuppetWeb extends Puppet {
// this.state.target('dead')
if
(
this
.
state
.
current
()
===
'
dead
'
&&
this
.
state
.
inprocess
())
{
// log.warn('PuppetWeb', 'quit() is called but readyState is `disconnecting`?')
log
.
warn
(
'
PuppetWeb
'
,
'
quit() is called but state.current() is `dead` and inprocess() ?
'
)
throw
new
Error
(
'
do not call quit again when quiting
'
)
}
// POISON must feed before state set to `dead` & `inprocess`
this
.
emit
(
'
watchdog
'
,
{
data
:
'
PuppetWeb.quit()
'
,
type
:
'
POISON
'
})
/**
* must feed POISON to Watchdog
* before state set to `dead` & `inprocess`
*/
const
food
:
WatchdogFood
=
{
data
:
'
PuppetWeb.quit()
'
,
type
:
'
POISON
'
}
this
.
emit
(
'
watchdog
'
,
food
)
this
.
state
.
current
(
'
dead
'
,
false
)
...
...
@@ -158,7 +166,7 @@ export class PuppetWeb extends Puppet {
throw
e
}
log
.
verbose
(
'
PuppetWeb
'
,
'
quit() done
'
)
log
.
silly
(
'
PuppetWeb
'
,
'
quit() done
'
)
this
.
state
.
current
(
'
dead
'
)
}
...
...
@@ -508,5 +516,3 @@ export class PuppetWeb extends Puppet {
})
}
}
export
default
PuppetWeb
src/puppet-web/server.ts
浏览文件 @
818c513a
/**
* Wechat for Bot. Connecting ChatBots
* Wechat
y - Wechat
for Bot. Connecting ChatBots
*
* Web Server for puppet
*
...
...
@@ -16,7 +16,7 @@ import * as bodyParser from 'body-parser'
import
*
as
express
from
'
express
'
import
{
EventEmitter
}
from
'
events
'
import
log
from
'
../brolog-env
'
import
{
log
}
from
'
../config
'
export
class
Server
extends
EventEmitter
{
private
express
:
express
.
Application
...
...
@@ -171,5 +171,3 @@ export class Server extends EventEmitter {
return
}
}
export
default
Server
src/puppet-web/ssl-pem.ts
浏览文件 @
818c513a
...
...
@@ -69,9 +69,5 @@ g+Xdc4Ag/St5eqgrp95KOlVeepSlb35LAD1Cc91LddTXCYS7+dc4ndQYpgrLU0ru
Sw==
-----END CERTIFICATE-----
`
// module.exports = {
// cert: cert
// , key: key
// }
export
{
cert
,
key
}
src/puppet-web/watchdog.ts
浏览文件 @
818c513a
...
...
@@ -20,8 +20,9 @@ import {
,
WatchdogFoodName
,
log
}
from
'
../config
'
import
PuppetWeb
from
'
./puppet-web
'
import
Event
from
'
./event
'
import
{
PuppetWeb
}
from
'
./puppet-web
'
import
{
Event
}
from
'
./event
'
/* tslint:disable:variable-name */
export
const
Watchdog
=
{
...
...
@@ -62,7 +63,7 @@ function onFeed(this: PuppetWeb, food: WatchdogFood) {
// return
// }
if
(
this
.
state
.
target
()
===
'
dead
'
||
this
.
state
.
inprocess
())
{
log
.
info
(
'
PuppetWebWatchdog
'
,
'
onFeed() is disabled because target state is `dead` or state is inprocess
'
)
log
.
warn
(
'
PuppetWebWatchdog
'
,
'
onFeed() is disabled because target state is `dead` or state is inprocess
'
)
return
}
...
...
@@ -191,5 +192,3 @@ function monitorScan(this: PuppetWeb, type: WatchdogFoodName) {
this
.
lastScanEventTime
=
Date
.
now
()
}
}
export
default
Watchdog
src/puppet.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
PuppetWeb
}
from
'
../
'
...
...
src/puppet.ts
浏览文件 @
818c513a
/**
* Wechat for Bot. Connecting ChatBots
* Wechat
y - Wechat
for Bot. Connecting ChatBots
*
* Interface for Puppet
*
...
...
@@ -15,11 +15,10 @@ import { EventEmitter } from 'events'
import
{
Sayable
}
from
'
./config
'
import
Contact
from
'
./contact
'
import
Message
from
'
./message
'
import
StateMonitor
from
'
./state-monitor
'
import
Room
from
'
./room
'
// import log from './brolog-env'
import
{
Contact
}
from
'
./contact
'
import
{
Message
}
from
'
./message
'
import
{
StateMonitor
}
from
'
./state-monitor
'
import
{
Room
}
from
'
./room
'
// type ContactGetterFunc = {
// (id: string): Promise<any>
...
...
@@ -83,5 +82,3 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
abstract
contactFind
(
filterFunc
:
string
):
Promise
<
Contact
[]
>
public
abstract
contactRemark
(
contact
:
Contact
,
remark
:
string
):
Promise
<
boolean
>
}
export
default
Puppet
src/room.ts
浏览文件 @
818c513a
...
...
@@ -14,12 +14,11 @@ const arrify = require('arrify')
import
{
Config
,
Sayable
,
log
}
from
'
./config
'
import
Contact
from
'
./contact
'
import
Message
from
'
./message
'
import
UtilLib
from
'
./util-lib
'
import
log
from
'
./brolog-env
'
import
{
Contact
}
from
'
./contact
'
import
{
Message
}
from
'
./message
'
import
{
UtilLib
}
from
'
./util-lib
'
type
RoomObj
=
{
id
:
string
...
...
@@ -436,5 +435,3 @@ export class Room extends EventEmitter implements Sayable {
}
}
export
default
Room
src/state-monitor.spec.ts
浏览文件 @
818c513a
...
...
@@ -12,7 +12,7 @@
*/
import
test
from
'
ava
'
import
StateMonitor
from
'
./state-monitor
'
import
{
StateMonitor
}
from
'
./state-monitor
'
test
(
'
StateMonitor target/current & stable
'
,
t
=>
{
const
CLIENT_NAME
=
'
StateMonitorTest
'
...
...
src/state-monitor.ts
浏览文件 @
818c513a
...
...
@@ -34,14 +34,14 @@ export class StateMonitor <A, B>{
*/
public
target
(
newState
?:
A
|
B
):
A
|
B
{
if
(
newState
)
{
log
.
verbose
(
'
StateMonitor
'
,
'
state.target(%s) <- %s for %s
'
log
.
verbose
(
'
StateMonitor
'
,
'
%s:target(%s) <- %s
'
,
this
.
_client
,
newState
,
this
.
_target
,
this
.
_client
)
this
.
_target
=
newState
}
else
{
log
.
silly
(
'
StateMonitor
'
,
'
state.target() is %s of %s
'
,
this
.
_target
,
this
.
_clien
t
)
log
.
silly
(
'
StateMonitor
'
,
'
%s:target() %s
'
,
this
.
_client
,
this
.
_targe
t
)
}
return
this
.
_target
}
...
...
@@ -52,10 +52,10 @@ export class StateMonitor <A, B>{
*/
public
current
(
newState
?:
A
|
B
,
stable
=
true
):
A
|
B
{
if
(
newState
)
{
log
.
verbose
(
'
StateMonitor
'
,
'
state.current(%s,%s) <- (%s,%s) for %s
'
log
.
verbose
(
'
StateMonitor
'
,
'
%s:current(%s,%s) <- (%s,%s)
'
,
this
.
_client
,
newState
,
stable
,
this
.
_current
,
this
.
_stable
,
this
.
_client
)
/**
...
...
@@ -64,9 +64,9 @@ export class StateMonitor <A, B>{
if
(
this
.
_current
===
newState
&&
this
.
_stable
===
stable
&&
stable
===
false
)
{
log
.
warn
(
'
StateMonitor
'
,
'
state.current(%s,%s) called but there are already in the same state for %s
'
,
newState
,
stable
log
.
warn
(
'
StateMonitor
'
,
'
%s:current(%s,%s) called but there are already in the same state
'
,
this
.
_client
,
newState
,
stable
)
const
e
=
new
Error
(
'
current unchange
'
)
log
.
verbose
(
'
StateMonitor
'
,
e
.
stack
)
...
...
@@ -75,7 +75,7 @@ export class StateMonitor <A, B>{
this
.
_current
=
newState
this
.
_stable
=
stable
}
else
{
log
.
silly
(
'
StateMonitor
'
,
'
state.current() is %s of %s
'
,
this
.
_current
,
this
.
_cli
ent
)
log
.
silly
(
'
StateMonitor
'
,
'
%s:current() %s
'
,
this
.
_client
,
this
.
_curr
ent
)
}
return
this
.
_current
}
...
...
@@ -84,7 +84,7 @@ export class StateMonitor <A, B>{
* does the current state be stable(not inprocess)?
*/
public
stable
()
{
log
.
silly
(
'
StateMonitor
'
,
'
state.stable() is %s of %s
'
,
this
.
_stable
,
this
.
_client
)
log
.
silly
(
'
StateMonitor
'
,
'
%s:stable() is %s
'
,
this
.
_client
,
this
.
_stable
)
return
this
.
_stable
}
...
...
@@ -92,7 +92,7 @@ export class StateMonitor <A, B>{
* does the current state be inprocess(not stable)?
*/
public
inprocess
()
{
log
.
silly
(
'
StateMonitor
'
,
'
state.inprocess() is %s of %s
'
,
!
this
.
_stable
,
this
.
_client
)
log
.
silly
(
'
StateMonitor
'
,
'
%s:inprocess() %s
'
,
this
.
_client
,
!
this
.
_stable
)
return
!
this
.
_stable
}
...
...
@@ -103,5 +103,3 @@ export class StateMonitor <A, B>{
return
this
.
_client
}
}
export
default
StateMonitor
src/util-lib.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
UtilLib
...
...
src/util-lib.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
*
as
http
from
'
http
'
import
log
from
'
./brolog-env
'
import
{
log
}
from
'
./config
'
/**
* bug compatible with:
...
...
@@ -8,7 +15,7 @@ import log from './brolog-env'
*/
// import * as ws from 'ws'
class
UtilLib
{
export
class
UtilLib
{
public
static
stripHtml
(
html
?:
string
):
string
{
if
(
!
html
)
{
return
''
...
...
@@ -196,5 +203,3 @@ class UtilLib {
}
}
}
export
default
UtilLib
src/wechaty.ts
浏览文件 @
818c513a
...
...
@@ -18,18 +18,17 @@ import {
,
HeadName
,
PuppetName
,
Sayable
,
log
}
from
'
./config
'
import
Contact
from
'
./contact
'
import
FriendRequest
from
'
./friend-request
'
import
Message
from
'
./message
'
import
Puppet
from
'
./puppet
'
import
PuppetWeb
from
'
./puppet-web/
'
import
Room
from
'
./room
'
import
StateMonitor
from
'
./state-monitor
'
import
UtilLib
from
'
./util-lib
'
import
log
from
'
./brolog-env
'
import
{
Contact
}
from
'
./contact
'
import
{
FriendRequest
}
from
'
./friend-request
'
import
{
Message
}
from
'
./message
'
import
{
Puppet
}
from
'
./puppet
'
import
{
PuppetWeb
}
from
'
./puppet-web/
'
import
{
Room
}
from
'
./room
'
import
{
StateMonitor
}
from
'
./state-monitor
'
import
{
UtilLib
}
from
'
./util-lib
'
export
type
PuppetSetting
=
{
head
?:
HeadName
...
...
@@ -359,5 +358,3 @@ export class Wechaty extends EventEmitter implements Sayable {
})
}
}
export
default
Wechaty
test/contact.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
Contact
...
...
test/docker.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
*
as
fs
from
'
fs
'
...
...
test/electron.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
test
(
'
Electron smoke testing
'
,
async
t
=>
{
...
...
test/node.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
// import { log } from '../'
...
...
test/puppet-web/bridge.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
Bridge
,
Browser
,
PuppetWeb
// , log
}
from
'
../../src/puppet-web/
'
import
{
spy
}
from
'
sinon
'
test
(
'
Bridge retry-promise test
'
,
async
t
=>
{
// co(function* () {
const
EXPECTED_RESOLVE
=
'
Okey
'
const
EXPECTED_REJECT
=
'
NotTheTime
'
function
delayedFactory
(
timeout
)
{
const
startTime
=
Date
.
now
()
return
function
()
{
const
nowTime
=
Date
.
now
()
if
(
nowTime
-
startTime
>
timeout
)
{
return
Promise
.
resolve
(
EXPECTED_RESOLVE
)
}
return
Promise
.
reject
(
EXPECTED_REJECT
)
test
(
'
retryPromise()
'
,
async
t
=>
{
const
EXPECTED_RESOLVE
=
'
Okey
'
const
EXPECTED_REJECT
=
'
NotTheTime
'
function
delayedFactory
(
timeout
)
{
const
startTime
=
Date
.
now
()
return
function
()
{
const
nowTime
=
Date
.
now
()
if
(
nowTime
-
startTime
>
timeout
)
{
return
Promise
.
resolve
(
EXPECTED_RESOLVE
)
}
return
Promise
.
reject
(
EXPECTED_REJECT
)
}
const
thenSpy
=
spy
()
const
retryPromise
=
require
(
'
retry-promise
'
).
default
let
delay500
=
delayedFactory
(
500
)
await
retryPromise
({
max
:
1
,
backoff
:
1
},
function
()
{
return
delay500
()
})
// .then(r => {
// thenSpy(r)
// // t.fail('should not resolved retry-promise here')
// })
.
catch
(
e
=>
{
thenSpy
(
e
)
// t.is(e, EXPECTED_REJECT, `retry-promise got ${EXPECTED_REJECT} when wait not enough`)
})
t
.
true
(
thenSpy
.
withArgs
(
EXPECTED_REJECT
).
calledOnce
,
'
should got EXPECTED_REJECT when wait not enough
'
)
thenSpy
.
reset
()
let
anotherDelay50
=
delayedFactory
(
50
)
await
retryPromise
({
max
:
6
,
backoff
:
10
},
function
()
{
return
anotherDelay50
()
})
.
then
(
r
=>
{
thenSpy
(
r
)
// t.is(r, EXPECTED_RESOLVE, `retryPromise got "${EXPECTED_RESOLVE}" when wait enough`)
})
// .catch(e => {
// thenSpy(e)
// // t.fail(`should not be rejected(with ${e}) when there is enough wait`)
// })
t
.
true
(
thenSpy
.
withArgs
(
EXPECTED_RESOLVE
).
calledOnce
,
'
should got EXPECTED_RESOLVE when wait enough
'
)
}
const
thenSpy
=
spy
()
const
retryPromise
=
require
(
'
retry-promise
'
).
default
let
delay500
=
delayedFactory
(
500
)
await
retryPromise
({
max
:
1
,
backoff
:
1
},
function
()
{
return
delay500
()
}).
catch
(
e
=>
{
thenSpy
(
e
)
})
t
.
true
(
thenSpy
.
withArgs
(
EXPECTED_REJECT
).
calledOnce
,
'
should got EXPECTED_REJECT when wait not enough
'
)
thenSpy
.
reset
()
let
anotherDelay50
=
delayedFactory
(
50
)
await
retryPromise
({
max
:
6
,
backoff
:
10
},
function
()
{
return
anotherDelay50
()
})
.
then
(
r
=>
{
thenSpy
(
r
)
})
t
.
true
(
thenSpy
.
withArgs
(
EXPECTED_RESOLVE
).
calledOnce
,
'
should got EXPECTED_RESOLVE when wait enough
'
)
})
test
(
'
Bridge smoking test
'
,
async
t
=>
{
test
(
'
WechatyBro.ding()
'
,
async
t
=>
{
const
PORT
=
58788
const
browser
=
new
Browser
()
t
.
truthy
(
browser
,
'
should instanciated a browser
'
)
const
mockPuppet
=
{
browser
:
browser
}
const
b
=
new
Bridge
(
mockPuppet
as
PuppetWeb
,
PORT
)
t
.
truthy
(
b
,
'
should instanciated a bridge with mocked puppet
'
)
const
b
ridge
=
new
Bridge
(
mockPuppet
as
PuppetWeb
,
PORT
)
t
.
truthy
(
b
ridge
,
'
should instanciated a bridge with mocked puppet
'
)
await
browser
.
init
()
t
.
pass
(
'
should instanciated a browser
'
)
...
...
@@ -75,20 +69,20 @@ test('Bridge smoking test', async t => {
await
browser
.
open
()
t
.
pass
(
'
should open success
'
)
await
b
.
inject
()
await
b
ridge
.
inject
()
t
.
pass
(
'
should injected WechatyBro
'
)
const
retDing
=
await
b
.
execute
(
'
return WechatyBro.ding()
'
)
const
retDing
=
await
b
ridge
.
execute
(
'
return WechatyBro.ding()
'
)
t
.
is
(
retDing
,
'
dong
'
,
'
should got dong after execute WechatyBro.ding()
'
)
// @deprecated
// const retReady = await b.execute('return WechatyBro.isReady()')
// t.is(typeof retReady, 'boolean', 'should got a boolean return after execute WechatyBro.isReady()')
const
retCode
=
await
b
.
proxyWechaty
(
'
isLogin
'
)
const
retCode
=
await
b
ridge
.
proxyWechaty
(
'
isLogin
'
)
t
.
is
(
typeof
retCode
,
'
boolean
'
,
'
should got a boolean after call proxyWechaty(isLogin)
'
)
await
b
.
quit
()
await
b
ridge
.
quit
()
t
.
pass
(
'
b.quit()
'
)
await
browser
.
quit
()
t
.
pass
(
'
browser.quit()
'
)
...
...
test/puppet-web/browser.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
*
as
fs
from
'
fs
'
import
{
test
}
from
'
ava
'
...
...
test/puppet-web/event.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
...
...
@@ -19,11 +26,16 @@ test('Puppet Web Event smoking test', async t => {
let
pw
=
new
PuppetWeb
({
profile
:
PROFILE
})
t
.
truthy
(
pw
,
'
should instantiated a PuppetWeb
'
)
await
pw
.
init
()
t
.
pass
(
'
should be inited
'
)
try
{
await
pw
.
init
()
t
.
pass
(
'
should be inited
'
)
await
Event
.
onBrowserDead
.
call
(
pw
,
'
event unit test
'
)
t
.
pass
(
'
should finish onBrowserDead event process
'
)
await
Event
.
onBrowserDead
.
call
(
pw
,
'
event unit test
'
)
t
.
pass
(
'
should finish onBrowserDead event process
'
)
await
pw
.
quit
()
await
pw
.
quit
()
}
catch
(
e
)
{
t
.
fail
(
'
exception:
'
+
e
.
message
)
throw
e
}
})
test/puppet-web/puppet-web.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
...
...
@@ -13,7 +20,7 @@ import {
// import { spy } from 'sinon'
test
.
skip
(
'
@deprecated Puppet Web Self Message Identification
'
,
t
=>
{
test
(
'
@deprecated Puppet Web Self Message Identification
'
,
t
=>
{
const
p
=
new
PuppetWeb
()
t
.
truthy
(
p
,
'
should instantiated a PuppetWeb
'
)
...
...
@@ -29,7 +36,7 @@ test.skip('@deprecated Puppet Web Self Message Identification', t => {
* static variable `Contact.puppet` will be changed
* when `PuppteWeb.init()` and `PuppteWeb.quit()`
*/
test
.
serial
(
'
PuppetWeb
login/logout events
'
,
async
t
=>
{
test
.
serial
(
'
login/logout events
'
,
async
t
=>
{
let
pw
=
new
PuppetWeb
()
t
.
truthy
(
pw
,
'
should instantiated a PuppetWeb
'
)
...
...
@@ -56,7 +63,7 @@ test.serial('PuppetWeb login/logout events', async t => {
await
pw
.
quit
()
})
test
.
serial
(
'
PuppetWeb server/browser communication
'
,
async
t
=>
{
test
.
only
(
'
server/browser socketio ding
'
,
async
t
=>
{
let
pw
=
new
PuppetWeb
()
t
.
truthy
(
pw
,
'
should instantiated a PuppetWeb
'
)
...
...
@@ -71,13 +78,15 @@ test.serial('PuppetWeb server/browser communication', async t => {
const
ret
=
await
dingSocket
(
pw
.
server
)
t
.
is
(
ret
,
EXPECTED_DING_DATA
,
'
should got EXPECTED_DING_DATA after resolved dingSocket()
'
)
}
catch
(
e
)
{
t
.
fail
(
e
.
message
)
t
.
fail
(
e
&&
e
.
message
||
e
||
'
unknown exception???
'
)
}
await
pw
.
quit
()
return
/////////////////////////////////////////////////////////////////////////////
function
dingSocket
(
server
:
Server
)
{
const
maxTime
=
60000
// 60s
const
waitTime
=
3000
...
...
test/puppet-web/server.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
*
as
https
from
'
https
'
import
*
as
sinon
from
'
sinon
'
import
{
// PuppetWeb
// , Message
UtilLib
,
log
}
from
'
../../
'
}
from
'
../../
'
import
{
// PuppetWeb
Server
}
from
'
../../src/puppet-web/
'
}
from
'
../../src/puppet-web/
'
test
(
'
PuppetWebServer basic tests
'
,
async
t
=>
{
test
(
'
create & close
'
,
async
t
=>
{
const
port
=
await
UtilLib
.
getPort
(
18788
)
const
s
=
new
Server
(
port
)
t
.
is
(
typeof
s
,
'
object
'
,
'
PuppetWebServer instance created
'
)
...
...
@@ -49,19 +53,25 @@ test('PuppetWebServer basic tests', async t => {
await
s
.
quit
()
})
test
(
'
PuppetWebServer smoke test
ing
'
,
async
t
=>
{
test
(
'
http d
ing
'
,
async
t
=>
{
const
port
=
await
UtilLib
.
getPort
(
18788
)
const
server
=
new
Server
(
port
)
t
.
truthy
(
server
,
'
new server instance
'
)
await
server
.
init
()
t
.
pass
(
'
server:
'
+
port
+
'
inited
'
)
try
{
await
server
.
init
()
t
.
pass
(
'
server:
'
+
port
+
'
inited
'
)
const
retHttps
=
await
dingHttps
()
t
.
is
(
retHttps
,
'
dong
'
,
'
ding https
got dong
'
)
const
retHttps
=
await
dingHttps
()
t
.
is
(
retHttps
,
'
dong
'
,
'
ding https
got dong
'
)
await
server
.
quit
()
await
server
.
quit
()
}
catch
(
e
)
{
t
.
fail
(
'
smoke testing exception:
'
+
e
.
message
)
throw
e
}
return
// The following is help functions only
...
...
test/puppet-web/watchdog.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
/* tslint:disable:no-var-requires */
...
...
test/room.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
Room
...
...
test/webdriver-phantomjs.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
*
as
WebDriver
from
'
selenium-webdriver
'
import
*
as
express
from
'
express
'
import
*
as
http
from
'
http
'
...
...
test/webdriver.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
// import {
...
...
@@ -6,8 +13,8 @@ import { test } from 'ava'
// } from 'selenium-webdriver'
import
{
Bridge
as
PuppetWebBridge
,
Browser
as
PuppetWebBrowser
Bridge
,
Browser
,
PuppetWeb
}
from
'
../src/puppet-web/
'
...
...
@@ -19,38 +26,38 @@ import {
* there will have race conditions for the conflict of `getBrowserPids()`
*/
test
.
serial
(
'
WebDriver process create & quit test
'
,
async
t
=>
{
const
b
=
new
PuppetWeb
Browser
()
t
.
truthy
(
b
,
'
should instanciate a browser
'
)
const
b
rowser
=
new
Browser
()
t
.
truthy
(
b
rowser
,
'
should instanciate a browser
'
)
await
b
.
init
()
await
b
rowser
.
init
()
t
.
pass
(
'
should be inited successful
'
)
await
b
.
open
()
await
b
rowser
.
open
()
t
.
pass
(
'
should open successful
'
)
let
pids
=
await
b
.
getBrowserPids
()
let
pids
=
await
b
rowser
.
getBrowserPids
()
t
.
truthy
(
pids
.
length
>
0
,
'
should exist browser process after b.open()
'
)
await
b
.
quit
()
await
b
rowser
.
quit
()
t
.
pass
(
'
quited
'
)
pids
=
await
b
.
getBrowserPids
()
pids
=
await
b
rowser
.
getBrowserPids
()
t
.
is
(
pids
.
length
,
0
,
'
no driver process after quit
'
)
})
test
.
serial
(
'
WebDriver smoke testing
'
,
async
t
=>
{
const
wb
=
new
PuppetWeb
Browser
()
t
.
truthy
(
wb
,
'
Browser instnace
'
)
const
browser
=
new
Browser
()
t
.
truthy
(
browser
,
'
Browser instnace
'
)
const
mockPuppet
=
<
PuppetWeb
>
{
browser
:
wb
}
const
bridge
=
new
PuppetWeb
Bridge
(
mockPuppet
,
8788
)
const
mockPuppet
=
<
PuppetWeb
>
{
browser
:
browser
}
const
bridge
=
new
Bridge
(
mockPuppet
,
8788
)
t
.
truthy
(
bridge
,
'
Bridge instnace
'
)
let
driver
// for help function `execute`
const
m
=
(
await
wb
.
getBrowserPids
()).
length
const
m
=
(
await
browser
.
getBrowserPids
()).
length
t
.
is
(
m
,
0
,
'
should has no browser process before get()
'
)
driver
=
await
wb
.
driver
.
init
()
driver
=
await
browser
.
driver
.
init
()
t
.
truthy
(
driver
,
'
should init driver success
'
)
const
injectio
=
bridge
.
getInjectio
()
...
...
@@ -59,7 +66,7 @@ test.serial('WebDriver smoke testing', async t => {
await
driver
.
get
(
'
https://wx.qq.com/
'
)
t
.
pass
(
'
should open wx.qq.com
'
)
const
n
=
(
await
wb
.
getBrowserPids
()).
length
const
n
=
(
await
browser
.
getBrowserPids
()).
length
t
.
truthy
(
n
>
0
,
'
should exist browser process after get()
'
)
const
retAdd
=
await
driverExecute
(
'
return 1+1
'
)
...
...
@@ -69,7 +76,7 @@ test.serial('WebDriver smoke testing', async t => {
t
.
truthy
(
retInject
,
'
should return a object contains status of inject operation
'
)
t
.
is
(
retInject
.
code
,
200
,
'
should got code 200 for a success wechaty inject
'
)
await
wb
.
quit
()
await
browser
.
quit
()
return
...
...
test/wechaty.spec.ts
浏览文件 @
818c513a
/**
* Wechaty - Wechat for Bot. Connecting ChatBots
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
import
{
test
}
from
'
ava
'
import
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录