Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
de173cf4
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,发现更多精彩内容 >>
提交
de173cf4
编写于
6月 15, 2017
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean(code): rename `Config` to `config`, change `wechaty.version()` to static compitibal
上级
fb00a88d
变更
33
隐藏空白更改
内联
并排
Showing
33 changed file
with
237 addition
and
210 deletion
+237
-210
bin/doctor.ts
bin/doctor.ts
+4
-4
bin/io-client.ts
bin/io-client.ts
+3
-3
example/api-ai-bot.ts
example/api-ai-bot.ts
+2
-2
example/contact-bot.ts
example/contact-bot.ts
+2
-2
example/ding-dong-bot.ts
example/ding-dong-bot.ts
+2
-2
example/friend-bot.ts
example/friend-bot.ts
+3
-3
example/gist-bot/index.ts
example/gist-bot/index.ts
+2
-2
example/media-file-bot.ts
example/media-file-bot.ts
+2
-2
example/room-bot.ts
example/room-bot.ts
+2
-2
example/speech-to-text-bot.ts
example/speech-to-text-bot.ts
+2
-2
example/tuling123-bot.ts
example/tuling123-bot.ts
+2
-2
index.ts
index.ts
+3
-3
src/config.spec.ts
src/config.spec.ts
+24
-24
src/config.ts
src/config.ts
+98
-44
src/contact.ts
src/contact.ts
+9
-9
src/friend-request.ts
src/friend-request.ts
+2
-2
src/io-client.ts
src/io-client.ts
+3
-3
src/io.ts
src/io.ts
+3
-3
src/message.spec.ts
src/message.spec.ts
+6
-6
src/message.ts
src/message.ts
+5
-5
src/puppet-web/browser-driver.ts
src/puppet-web/browser-driver.ts
+4
-4
src/puppet-web/browser.ts
src/puppet-web/browser.ts
+2
-2
src/puppet-web/friend-request.spec.ts
src/puppet-web/friend-request.spec.ts
+2
-2
src/puppet-web/friend-request.ts
src/puppet-web/friend-request.ts
+3
-3
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+2
-2
src/room.ts
src/room.ts
+10
-10
src/wechaty.ts
src/wechaty.ts
+14
-41
test/contact.spec.ts
test/contact.spec.ts
+2
-2
test/docker.spec.ts
test/docker.spec.ts
+3
-3
test/puppet-web/browser.spec.ts
test/puppet-web/browser.spec.ts
+4
-4
test/puppet-web/puppet-web.spec.ts
test/puppet-web/puppet-web.spec.ts
+3
-3
test/room.spec.ts
test/room.spec.ts
+4
-4
test/wechaty.spec.ts
test/wechaty.spec.ts
+5
-5
未找到文件。
bin/doctor.ts
浏览文件 @
de173cf4
...
...
@@ -20,9 +20,9 @@
import
*
as
os
from
'
os
'
import
Config
from
'
../src/config
'
import
Doctor
from
'
../src/doctor
'
import
Wechaty
from
'
../src/wechaty
'
import
{
config
}
from
'
../src/config
'
import
{
Doctor
}
from
'
../src/doctor
'
import
{
Wechaty
}
from
'
../src/wechaty
'
const
wechaty
=
Wechaty
.
instance
()
const
doctor
=
new
Doctor
()
...
...
@@ -43,7 +43,7 @@ async function main() {
1. Wechaty version:
${
wechaty
.
version
()}
2.
${
os
.
type
()}
${
os
.
arch
()}
version
${
os
.
release
()}
memory
${
Math
.
floor
(
os
.
freemem
()
/
1024
/
1024
)}
/
${
Math
.
floor
(
os
.
totalmem
()
/
1024
/
1024
)}
MB
3. Docker:
${
C
onfig
.
dockerMode
}
3. Docker:
${
c
onfig
.
dockerMode
}
4. Node version:
${
process
.
version
}
5. Tcp IPC TEST:
${
ipcTestResult
}
6. Chromedriver:
${
chromedriverVersion
}
...
...
bin/io-client.ts
浏览文件 @
de173cf4
...
...
@@ -19,7 +19,7 @@
*/
import
{
C
onfig
,
c
onfig
,
log
,
}
from
'
../src/config
'
...
...
@@ -42,12 +42,12 @@ __________________________________________________
`
let
token
=
C
onfig
.
token
let
token
=
c
onfig
.
token
if
(
!
token
)
{
log
.
error
(
'
Client
'
,
'
token not found: please set WECHATY_TOKEN in environment before run io-client
'
)
// process.exit(-1)
token
=
C
onfig
.
DEFAULT_TOKEN
token
=
c
onfig
.
DEFAULT_TOKEN
log
.
warn
(
'
Client
'
,
`set token to "
${
token
}
" for demo purpose`
)
}
...
...
example/api-ai-bot.ts
浏览文件 @
de173cf4
...
...
@@ -41,7 +41,7 @@ import { EventEmitter } from 'events'
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
C
onfig
,
c
onfig
,
Wechaty
,
}
from
'
../
'
...
...
@@ -56,7 +56,7 @@ import {
const
APIAI_API_KEY
=
'
7217d7bce18c4bcfbe04ba7bdfaf9c08
'
const
brainApiAi
=
ApiAi
(
APIAI_API_KEY
)
const
bot
=
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
const
bot
=
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
console
.
log
(
`
Welcome to api.AI Wechaty Bot.
...
...
example/contact-bot.ts
浏览文件 @
de173cf4
...
...
@@ -28,7 +28,7 @@ const QrcodeTerminal = require('qrcode-terminal')
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
C
onfig
,
c
onfig
,
Contact
,
Wechaty
,
log
,
...
...
@@ -54,7 +54,7 @@ Please wait... I'm trying to login in...
`
console
.
log
(
welcome
)
const
bot
=
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
const
bot
=
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
bot
.
on
(
'
login
'
,
function
(
this
,
user
)
{
...
...
example/ding-dong-bot.ts
浏览文件 @
de173cf4
...
...
@@ -27,7 +27,7 @@ const finis = require('finis')
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
C
onfig
,
c
onfig
,
Wechaty
,
log
,
MediaMessage
,
...
...
@@ -57,7 +57,7 @@ Please wait... I'm trying to login in...
`
console
.
log
(
welcome
)
const
bot
=
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
const
bot
=
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
bot
.
on
(
'
logout
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logouted`
))
...
...
example/friend-bot.ts
浏览文件 @
de173cf4
...
...
@@ -26,10 +26,10 @@ const QrcodeTerminal = require('qrcode-terminal')
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
Wechaty
,
config
,
Contact
,
Config
,
log
,
Wechaty
,
}
from
'
../
'
const
welcome
=
`
...
...
@@ -57,7 +57,7 @@ Please wait... I'm trying to login in...
`
console
.
log
(
welcome
)
const
bot
=
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
const
bot
=
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
bot
.
on
(
'
login
'
,
user
=>
log
.
info
(
'
Bot
'
,
`
${
user
.
name
()}
logined`
))
...
...
example/gist-bot/index.ts
浏览文件 @
de173cf4
...
...
@@ -23,7 +23,7 @@
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
C
onfig
,
c
onfig
,
Wechaty
,
log
,
}
from
'
../../
'
...
...
@@ -41,7 +41,7 @@ Please wait... I'm trying to login in...
`
console
.
log
(
welcome
)
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
.
on
(
'
scan
'
,
(
url
,
code
)
=>
{
if
(
!
/201|200/
.
test
(
String
(
code
)))
{
...
...
example/media-file-bot.ts
浏览文件 @
de173cf4
...
...
@@ -32,12 +32,12 @@ import * as qrcodeTerminal from 'qrcode-terminal'
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
C
onfig
,
c
onfig
,
Message
,
MsgType
,
Wechaty
,
}
from
'
../
'
const
bot
=
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
const
bot
=
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
bot
.
on
(
'
scan
'
,
(
url
,
code
)
=>
{
...
...
example/room-bot.ts
浏览文件 @
de173cf4
...
...
@@ -53,7 +53,7 @@ const qrcodeTerminal = require('qrcode-terminal')
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
C
onfig
,
c
onfig
,
Contact
,
Room
,
Wechaty
,
...
...
@@ -86,7 +86,7 @@ Please wait... I'm trying to login in...
`
console
.
log
(
welcome
)
const
bot
=
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
const
bot
=
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
bot
.
on
(
'
scan
'
,
(
url
,
code
)
=>
{
...
...
example/speech-to-text-bot.ts
浏览文件 @
de173cf4
...
...
@@ -33,13 +33,13 @@ const qrcodeTerminal = require('qrcode-terminal')
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
C
onfig
,
c
onfig
,
MediaMessage
,
MsgType
,
Wechaty
,
}
from
'
../
'
const
bot
=
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
const
bot
=
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
bot
.
on
(
'
scan
'
,
(
url
,
code
)
=>
{
...
...
example/tuling123-bot.ts
浏览文件 @
de173cf4
...
...
@@ -36,7 +36,7 @@ const Tuling123 = require('tuling123-client')
* when you are runing with Docker or NPM instead of Git Source.
*/
import
{
C
onfig
,
c
onfig
,
Wechaty
,
log
,
}
from
'
../
'
...
...
@@ -53,7 +53,7 @@ import {
const
TULING123_API_KEY
=
'
18f25157e0446df58ade098479f74b21
'
const
tuling
=
new
Tuling123
(
TULING123_API_KEY
)
const
bot
=
Wechaty
.
instance
({
profile
:
C
onfig
.
DEFAULT_PROFILE
})
const
bot
=
Wechaty
.
instance
({
profile
:
c
onfig
.
DEFAULT_PROFILE
})
console
.
log
(
`
Welcome to Tuling Wechaty Bot.
...
...
index.ts
浏览文件 @
de173cf4
import
{
Config
,
Sayable
,
config
,
log
,
Sayable
,
}
from
'
./src/config
'
import
Contact
from
'
./src/contact
'
...
...
@@ -23,7 +23,7 @@ import Wechaty from './src/wechaty'
const
VERSION
=
require
(
'
./package.json
'
).
version
export
{
C
onfig
,
c
onfig
,
Contact
,
FriendRequest
,
IoClient
,
...
...
src/config.spec.ts
浏览文件 @
de173cf4
...
...
@@ -18,24 +18,24 @@
*/
import
{
test
}
from
'
ava
'
import
{
C
onfig
}
from
'
./config
'
import
{
c
onfig
}
from
'
./config
'
import
{
Puppet
}
from
'
./puppet
'
test
(
'
important variables
'
,
t
=>
{
t
.
true
(
'
head
'
in
C
onfig
,
'
should exist `head` in Config
'
)
t
.
true
(
'
puppet
'
in
C
onfig
,
'
should exist `puppet` in Config
'
)
t
.
true
(
'
apihost
'
in
C
onfig
,
'
should exist `apihost` in Config
'
)
t
.
true
(
'
port
'
in
C
onfig
,
'
should exist `port` in Config
'
)
t
.
true
(
'
profile
'
in
C
onfig
,
'
should exist `profile` in Config
'
)
t
.
true
(
'
token
'
in
C
onfig
,
'
should exist `token` in Config
'
)
t
.
true
(
'
head
'
in
c
onfig
,
'
should exist `head` in Config
'
)
t
.
true
(
'
puppet
'
in
c
onfig
,
'
should exist `puppet` in Config
'
)
t
.
true
(
'
apihost
'
in
c
onfig
,
'
should exist `apihost` in Config
'
)
t
.
true
(
'
port
'
in
c
onfig
,
'
should exist `port` in Config
'
)
t
.
true
(
'
profile
'
in
c
onfig
,
'
should exist `profile` in Config
'
)
t
.
true
(
'
token
'
in
c
onfig
,
'
should exist `token` in Config
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_PUPPET
,
'
should export DEFAULT_PUPPET
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_PORT
,
'
should export DEFAULT_PORT
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_PROFILE
,
'
should export DEFAULT_PROFILE
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_HEAD
,
'
should export DEFAULT_HEAD
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_PROTOCOL
,
'
should export DEFAULT_PROTOCOL
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_APIHOST
,
'
should export DEFAULT_APIHOST
'
)
t
.
truthy
(
C
onfig
.
CMD_CHROMIUM
,
'
should export CMD_CHROMIUM
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_PUPPET
,
'
should export DEFAULT_PUPPET
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_PORT
,
'
should export DEFAULT_PORT
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_PROFILE
,
'
should export DEFAULT_PROFILE
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_HEAD
,
'
should export DEFAULT_HEAD
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_PROTOCOL
,
'
should export DEFAULT_PROTOCOL
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_APIHOST
,
'
should export DEFAULT_APIHOST
'
)
t
.
truthy
(
c
onfig
.
CMD_CHROMIUM
,
'
should export CMD_CHROMIUM
'
)
})
test
(
'
validApiHost()
'
,
t
=>
{
...
...
@@ -49,12 +49,12 @@ test('validApiHost()', t => {
]
OK_APIHOSTS
.
forEach
(
apihost
=>
{
t
.
notThrows
(()
=>
{
C
onfig
.
validApiHost
(
apihost
)
c
onfig
.
validApiHost
(
apihost
)
})
},
'
should not row for right apihost
'
)
ERR_APIHOSTS
.
forEach
(
apihost
=>
{
t
.
throws
(()
=>
{
C
onfig
.
validApiHost
(
apihost
)
c
onfig
.
validApiHost
(
apihost
)
})
},
'
should throw for error apihost
'
)
...
...
@@ -62,30 +62,30 @@ test('validApiHost()', t => {
test
(
'
puppetInstance()
'
,
t
=>
{
t
.
throws
(()
=>
{
C
onfig
.
puppetInstance
()
c
onfig
.
puppetInstance
()
},
Error
,
'
should throw when not initialized
'
)
const
EXPECTED
=
<
Puppet
>
{
userId
:
'
test
'
}
const
mockPuppet
=
EXPECTED
C
onfig
.
puppetInstance
(
mockPuppet
)
const
instance
=
C
onfig
.
puppetInstance
()
c
onfig
.
puppetInstance
(
mockPuppet
)
const
instance
=
c
onfig
.
puppetInstance
()
t
.
deepEqual
(
instance
,
EXPECTED
,
'
should equal with initialized data
'
)
C
onfig
.
puppetInstance
(
null
)
c
onfig
.
puppetInstance
(
null
)
t
.
throws
(()
=>
{
C
onfig
.
puppetInstance
()
c
onfig
.
puppetInstance
()
},
Error
,
'
should throw after set to null
'
)
})
test
(
'
dockerMode
'
,
t
=>
{
t
.
true
(
'
dockerMode
'
in
C
onfig
,
'
should identify docker env by `dockerMode`
'
)
t
.
true
(
'
dockerMode
'
in
c
onfig
,
'
should identify docker env by `dockerMode`
'
)
if
(
'
C9_PORT
'
in
process
.
env
)
{
t
.
is
(
C
onfig
.
dockerMode
,
false
,
'
should not in docker mode in Cloud9 IDE
'
)
t
.
is
(
c
onfig
.
dockerMode
,
false
,
'
should not in docker mode in Cloud9 IDE
'
)
}
else
if
(
require
(
'
is-ci
'
))
{
t
.
is
(
C
onfig
.
dockerMode
,
false
,
'
should not in docker mode in Continuous Integeration System
'
)
t
.
is
(
c
onfig
.
dockerMode
,
false
,
'
should not in docker mode in Continuous Integeration System
'
)
}
else
{
// a custom running envioronment, maybe docker, maybe not
}
...
...
src/config.ts
浏览文件 @
de173cf4
...
...
@@ -16,7 +16,43 @@
* limitations under the License.
*
*/
import
*
as
os
from
'
os
'
import
*
as
fs
from
'
fs
'
import
*
as
os
from
'
os
'
import
*
as
path
from
'
path
'
/**
* Raven.io
*/
import
*
as
Raven
from
'
raven
'
Raven
.
disableConsoleAlerts
()
Raven
.
config
(
process
.
env
.
NODE_ENV
===
'
production
'
&&
'
https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672
'
,
{
release
:
require
(
'
../package.json
'
).
version
,
tags
:
{
git_commit
:
'
c0deb10c4
'
,
platform
:
!!
process
.
env
(
'
WECHATY_DOCKER
'
)
?
'
docker
'
:
os
.
platform
(),
},
},
)
.
install
()
/*
try {
doSomething(a[0])
} catch (e) {
Raven.captureException(e)
}
Raven.context(function () {
doSomething(a[0])
})
*/
// const isCi = require('is-ci')
// const isDocker = require('is-docker')
...
...
@@ -78,22 +114,24 @@ export interface ConfigSetting {
puppetInstance
():
Puppet
puppetInstance
(
empty
:
null
):
void
puppetInstance
(
instance
:
Puppet
):
void
puppetInstance
(
instance
?:
Puppet
|
null
):
Puppet
|
void
puppetInstance
(
instance
?:
Puppet
|
null
):
Puppet
|
void
,
dockerMode
:
boolean
gitVersion
():
string
|
null
,
npmVersion
():
string
,
dockerMode
:
boolean
,
}
/* tslint:disable:variable-name */
/* tslint:disable:no-var-requires */
export
const
C
onfig
:
ConfigSetting
=
require
(
'
../package.json
'
).
wechaty
export
const
c
onfig
:
ConfigSetting
=
require
(
'
../package.json
'
).
wechaty
/**
* 1. ENVIRONMENT VARIABLES + PACKAGES.JSON (default)
*/
Object
.
assign
(
C
onfig
,
{
apihost
:
process
.
env
[
'
WECHATY_APIHOST
'
]
||
C
onfig
.
DEFAULT_APIHOST
,
head
:
process
.
env
[
'
WECHATY_HEAD
'
]
||
C
onfig
.
DEFAULT_HEAD
,
puppet
:
process
.
env
[
'
WECHATY_PUPPET
'
]
||
C
onfig
.
DEFAULT_PUPPET
,
Object
.
assign
(
c
onfig
,
{
apihost
:
process
.
env
[
'
WECHATY_APIHOST
'
]
||
c
onfig
.
DEFAULT_APIHOST
,
head
:
process
.
env
[
'
WECHATY_HEAD
'
]
||
c
onfig
.
DEFAULT_HEAD
,
puppet
:
process
.
env
[
'
WECHATY_PUPPET
'
]
||
c
onfig
.
DEFAULT_PUPPET
,
validApiHost
,
})
...
...
@@ -103,12 +141,12 @@ function validApiHost(apihost: string): boolean {
}
throw
new
Error
(
'
validApiHost() fail for
'
+
apihost
)
}
validApiHost
(
C
onfig
.
apihost
)
validApiHost
(
c
onfig
.
apihost
)
/**
* 2. ENVIRONMENT VARIABLES (only)
*/
Object
.
assign
(
C
onfig
,
{
Object
.
assign
(
c
onfig
,
{
port
:
process
.
env
[
'
WECHATY_PORT
'
]
||
null
,
// 0 for disable port
profile
:
process
.
env
[
'
WECHATY_PROFILE
'
]
||
null
,
// DO NOT set DEFAULT_PROFILE, because sometimes user do not want to save session
token
:
process
.
env
[
'
WECHATY_TOKEN
'
]
||
null
,
// DO NOT set DEFAULT, because sometimes user do not want to connect to io cloud service
...
...
@@ -118,15 +156,15 @@ Object.assign(Config, {
/**
* 3. Service Settings
*/
Object
.
assign
(
C
onfig
,
{
Object
.
assign
(
c
onfig
,
{
// get PORT form cloud service env, ie: heroku
httpPort
:
process
.
env
[
'
PORT
'
]
||
process
.
env
[
'
WECHATY_PORT
'
]
||
C
onfig
.
DEFAULT_PORT
,
httpPort
:
process
.
env
[
'
PORT
'
]
||
process
.
env
[
'
WECHATY_PORT
'
]
||
c
onfig
.
DEFAULT_PORT
,
})
/**
* 4. Envioronment Identify
*/
Object
.
assign
(
C
onfig
,
{
Object
.
assign
(
c
onfig
,
{
dockerMode
:
!!
process
.
env
(
'
WECHATY_DOCKER
'
),
isGlobal
:
isWechatyInstalledGlobal
(),
})
...
...
@@ -195,7 +233,52 @@ function puppetInstance(instance?: Puppet | null): Puppet | void {
}
Object
.
assign
(
Config
,
{
function
gitVersion
():
string
|
null
{
const
dotGitPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
.git
'
)
// only for ts-node, not for dist
// const gitLogArgs = ['log', '--oneline', '-1']
// TODO: use git rev-parse HEAD ?
const
gitArgs
=
[
'
rev-parse
'
,
'
HEAD
'
]
try
{
// Make sure this is a Wechaty repository
fs
.
statSync
(
dotGitPath
).
isDirectory
()
const
ss
=
require
(
'
child_process
'
)
.
spawnSync
(
'
git
'
,
gitArgs
,
{
cwd
:
__dirname
})
if
(
ss
.
status
!==
0
)
{
throw
new
Error
(
ss
.
error
)
}
const
revision
=
ss
.
stdout
.
toString
()
.
trim
()
.
slice
(
0
,
7
)
return
revision
}
catch
(
e
)
{
/* fall safe */
/**
* 1. .git not exist
* 2. git log fail
*/
log
.
silly
(
'
Wechaty
'
,
'
version() form development environment is not availble: %s
'
,
e
.
message
)
return
null
}
}
function
npmVersion
():
string
{
try
{
return
require
(
'
../package.json
'
).
version
}
catch
(
e
)
{
log
.
error
(
'
Wechaty
'
,
'
npmVersion() exception %s
'
,
e
.
message
)
Raven
.
captureException
(
e
)
return
'
0.0.0
'
}
}
Object
.
assign
(
config
,
{
gitVersion
,
npmVersion
,
puppetInstance
,
})
...
...
@@ -236,38 +319,9 @@ export interface Sleepable {
sleep
(
millisecond
:
number
):
Promise
<
void
>
}
import
*
as
Raven
from
'
raven
'
Raven
.
disableConsoleAlerts
()
Raven
.
config
(
process
.
env
.
NODE_ENV
===
'
production
'
&&
'
https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672
'
,
{
release
:
require
(
'
../package.json
'
).
version
,
tags
:
{
git_commit
:
'
c0deb10c4
'
,
platform
:
os
.
platform
(),
},
},
)
.
install
()
/*
try {
doSomething(a[0])
} catch (e) {
Raven.captureException(e)
}
Raven.context(function () {
doSomething(a[0])
})
*/
export
{
log
,
Raven
,
}
export
default
C
onfig
export
default
c
onfig
src/contact.ts
浏览文件 @
de173cf4
...
...
@@ -17,7 +17,7 @@
*
*/
import
{
C
onfig
,
c
onfig
,
Raven
,
Sayable
,
log
,
...
...
@@ -329,9 +329,9 @@ export class Contact implements Sayable {
}
try
{
const
hostname
=
await
(
C
onfig
.
puppetInstance
()
as
PuppetWeb
).
browser
.
hostname
()
const
hostname
=
await
(
c
onfig
.
puppetInstance
()
as
PuppetWeb
).
browser
.
hostname
()
const
avatarUrl
=
`http://
${
hostname
}${
this
.
obj
.
avatar
}
`
const
cookies
=
await
(
C
onfig
.
puppetInstance
()
as
PuppetWeb
).
browser
.
readCookie
()
const
cookies
=
await
(
c
onfig
.
puppetInstance
()
as
PuppetWeb
).
browser
.
readCookie
()
log
.
silly
(
'
Contact
'
,
'
avatar() url: %s
'
,
avatarUrl
)
return
UtilLib
.
urlStream
(
avatarUrl
,
cookies
)
...
...
@@ -388,9 +388,9 @@ export class Contact implements Sayable {
}
if
(
!
contactGetter
)
{
log
.
silly
(
'
Contact
'
,
'
get contact via
'
+
C
onfig
.
puppetInstance
().
constructor
.
name
)
contactGetter
=
C
onfig
.
puppetInstance
()
.
getContact
.
bind
(
C
onfig
.
puppetInstance
())
log
.
silly
(
'
Contact
'
,
'
get contact via
'
+
c
onfig
.
puppetInstance
().
constructor
.
name
)
contactGetter
=
c
onfig
.
puppetInstance
()
.
getContact
.
bind
(
c
onfig
.
puppetInstance
())
}
if
(
!
contactGetter
)
{
throw
new
Error
(
'
no contatGetter
'
)
...
...
@@ -431,7 +431,7 @@ export class Contact implements Sayable {
* ```
*/
public
self
():
boolean
{
const
userId
=
C
onfig
.
puppetInstance
()
const
userId
=
c
onfig
.
puppetInstance
()
.
userId
const
selfId
=
this
.
id
...
...
@@ -522,7 +522,7 @@ export class Contact implements Sayable {
throw
new
Error
(
'
unsupport name type
'
)
}
const
contactList
=
await
C
onfig
.
puppetInstance
()
const
contactList
=
await
c
onfig
.
puppetInstance
()
.
contactFind
(
filterFunction
)
.
catch
(
e
=>
{
log
.
error
(
'
Contact
'
,
'
findAll() rejected: %s
'
,
e
.
message
)
...
...
@@ -627,7 +627,7 @@ export class Contact implements Sayable {
return
this
.
obj
&&
this
.
obj
.
alias
||
null
}
return
C
onfig
.
puppetInstance
()
return
c
onfig
.
puppetInstance
()
.
contactAlias
(
this
,
newAlias
)
.
then
(
ret
=>
{
if
(
ret
)
{
...
...
src/friend-request.ts
浏览文件 @
de173cf4
...
...
@@ -18,7 +18,7 @@
*/
import
{
C
onfig
,
c
onfig
,
log
,
}
from
'
./config
'
import
Contact
from
'
./contact
'
...
...
@@ -32,7 +32,7 @@ export abstract class FriendRequest {
constructor
()
{
log
.
verbose
(
'
FriendRequest
'
,
'
constructor()
'
)
if
(
!
C
onfig
.
puppetInstance
())
{
if
(
!
c
onfig
.
puppetInstance
())
{
throw
new
Error
(
'
no Config.puppetInstance() instanciated
'
)
}
}
...
...
src/io-client.ts
浏览文件 @
de173cf4
...
...
@@ -25,7 +25,7 @@
import
{
StateSwitch
}
from
'
state-switch
'
import
{
C
onfig
,
c
onfig
,
log
as
globalLog
,
}
from
'
./config
'
import
{
Io
}
from
'
./io
'
...
...
@@ -39,7 +39,7 @@ export class IoClient {
private
state
=
new
StateSwitch
<
'
online
'
,
'
offline
'
>
(
'
IoClient
'
,
'
offline
'
,
globalLog
)
constructor
(
private
token
:
string
=
Config
.
token
||
C
onfig
.
DEFAULT_TOKEN
,
private
token
:
string
=
config
.
token
||
c
onfig
.
DEFAULT_TOKEN
,
private
log
:
any
=
globalLog
,
)
{
if
(
!
log
)
{
...
...
@@ -141,7 +141,7 @@ export class IoClient {
return
}
public
initWeb
(
port
=
C
onfig
.
httpPort
)
{
public
initWeb
(
port
=
c
onfig
.
httpPort
)
{
// if (process.env.DYNO) {
// }
const
app
=
require
(
'
express
'
)()
...
...
src/io.ts
浏览文件 @
de173cf4
...
...
@@ -21,7 +21,7 @@ import * as WebSocket from 'ws'
import
{
StateSwitch
}
from
'
state-switch
'
import
{
C
onfig
,
c
onfig
,
// WechatyEventName
log
,
}
from
'
./config
'
...
...
@@ -71,8 +71,8 @@ export class Io {
throw
new
Error
(
'
Io must has wechaty & token set
'
)
}
setting
.
apihost
=
setting
.
apihost
||
C
onfig
.
apihost
setting
.
protocol
=
setting
.
protocol
||
C
onfig
.
DEFAULT_PROTOCOL
setting
.
apihost
=
setting
.
apihost
||
c
onfig
.
apihost
setting
.
protocol
=
setting
.
protocol
||
c
onfig
.
DEFAULT_PROTOCOL
this
.
uuid
=
setting
.
wechaty
.
uuid
...
...
src/message.spec.ts
浏览文件 @
de173cf4
...
...
@@ -19,7 +19,7 @@
import
{
test
}
from
'
ava
'
import
{
C
onfig
,
c
onfig
,
log
,
}
from
'
./config
'
import
Message
from
'
./message
'
...
...
@@ -29,7 +29,7 @@ const MOCK_USER_ID = 'TEST-USER-ID'
const
puppet
=
new
PuppetWeb
()
puppet
.
userId
=
MOCK_USER_ID
C
onfig
.
puppetInstance
(
puppet
)
c
onfig
.
puppetInstance
(
puppet
)
test
(
'
constructor()
'
,
t
=>
{
/* tslint:disable:max-line-length */
...
...
@@ -93,7 +93,7 @@ test.serial('ready()', async t => {
})
}
C
onfig
.
puppetInstance
()
c
onfig
.
puppetInstance
()
.
getContact
=
mockGetContact
const
m
=
new
Message
(
rawData
)
...
...
@@ -131,7 +131,7 @@ test('findAll()', async t => {
})
test
(
'
self()
'
,
t
=>
{
C
onfig
.
puppetInstance
()
c
onfig
.
puppetInstance
()
const
m
=
new
Message
()
m
.
from
(
MOCK_USER_ID
)
...
...
@@ -183,11 +183,11 @@ test.serial('mentioned()', async t => {
let
puppet1
try
{
puppet1
=
C
onfig
.
puppetInstance
()
puppet1
=
c
onfig
.
puppetInstance
()
puppet1
.
getContact
=
mockContactGetter
}
catch
(
err
)
{
puppet1
=
{
getContact
:
mockContactGetter
}
C
onfig
.
puppetInstance
(
puppet1
)
c
onfig
.
puppetInstance
(
puppet1
)
}
const
msg11
=
new
Message
(
rawObj11
)
const
room11
=
msg11
.
room
()
...
...
src/message.ts
浏览文件 @
de173cf4
...
...
@@ -20,7 +20,7 @@ import * as fs from 'fs'
import
*
as
path
from
'
path
'
import
{
C
onfig
,
c
onfig
,
Raven
,
RecommendInfo
,
Sayable
,
...
...
@@ -414,7 +414,7 @@ export class Message implements Sayable {
public
count
()
{
return
this
.
_counter
}
public
self
():
boolean
{
const
userId
=
C
onfig
.
puppetInstance
()
const
userId
=
c
onfig
.
puppetInstance
()
.
userId
const
fromId
=
this
.
obj
.
from
...
...
@@ -619,7 +619,7 @@ export class Message implements Sayable {
}
}
return
C
onfig
.
puppetInstance
()
return
c
onfig
.
puppetInstance
()
.
send
(
m
)
}
...
...
@@ -651,7 +651,7 @@ export class MediaMessage extends Message {
}
// FIXME: decoupling needed
this
.
bridge
=
(
C
onfig
.
puppetInstance
()
as
PuppetWeb
)
this
.
bridge
=
(
c
onfig
.
puppetInstance
()
as
PuppetWeb
)
.
bridge
}
...
...
@@ -801,7 +801,7 @@ export class MediaMessage extends Message {
try
{
await
this
.
ready
()
// FIXME: decoupling needed
const
cookies
=
await
(
C
onfig
.
puppetInstance
()
as
PuppetWeb
).
browser
.
readCookie
()
const
cookies
=
await
(
c
onfig
.
puppetInstance
()
as
PuppetWeb
).
browser
.
readCookie
()
if
(
!
this
.
obj
.
url
)
{
throw
new
Error
(
'
no url
'
)
}
...
...
src/puppet-web/browser-driver.ts
浏览文件 @
de173cf4
...
...
@@ -27,7 +27,7 @@ import {
}
from
'
selenium-webdriver
'
import
{
C
onfig
,
c
onfig
,
HeadName
,
log
,
}
from
'
../config
'
...
...
@@ -113,9 +113,9 @@ export class BrowserDriver {
'
--no-sandbox
'
,
],
// issue #26 for run inside docker
}
if
(
C
onfig
.
dockerMode
)
{
if
(
c
onfig
.
dockerMode
)
{
log
.
verbose
(
'
PuppetWebBrowserDriver
'
,
'
getChromeDriver() wechaty in docker confirmed(should not show this in CI)
'
)
options
[
'
binary
'
]
=
C
onfig
.
CMD_CHROMIUM
options
[
'
binary
'
]
=
c
onfig
.
CMD_CHROMIUM
}
else
{
/**
* https://github.com/Chatie/wechaty/pull/416
...
...
@@ -224,7 +224,7 @@ export class BrowserDriver {
// , '--ssl-client-certificate-file=cert.pem' //
]
if
(
C
onfig
.
debug
)
{
if
(
c
onfig
.
debug
)
{
phantomjsArgs
.
push
(
'
--remote-debugger-port=8080
'
)
// XXX: be careful when in production env.
phantomjsArgs
.
push
(
'
--webdriver-loglevel=DEBUG
'
)
// phantomjsArgs.push('--webdriver-logfile=webdriver.debug.log')
...
...
src/puppet-web/browser.ts
浏览文件 @
de173cf4
...
...
@@ -26,7 +26,7 @@ import { StateSwitch } from 'state-switch'
const
retryPromise
=
require
(
'
retry-promise
'
).
default
// https://github.com/olalonde/retry-promise
import
{
C
onfig
,
c
onfig
,
HeadName
,
log
,
}
from
'
../config
'
...
...
@@ -53,7 +53,7 @@ export class Browser extends EventEmitter {
constructor
(
private
setting
:
BrowserSetting
=
{
head
:
C
onfig
.
head
,
head
:
c
onfig
.
head
,
sessionFile
:
''
,
},
)
{
...
...
src/puppet-web/friend-request.spec.ts
浏览文件 @
de173cf4
...
...
@@ -18,13 +18,13 @@
*/
import
{
test
}
from
'
ava
'
import
C
onfig
from
'
../config
'
import
c
onfig
from
'
../config
'
import
Contact
from
'
../contact
'
import
Message
from
'
../message
'
import
Puppet
from
'
../puppet
'
import
PuppetWebFriendRequest
from
'
./friend-request
'
C
onfig
.
puppetInstance
({
c
onfig
.
puppetInstance
({
userId
:
'
xxx
'
,
}
as
Puppet
)
...
...
src/puppet-web/friend-request.ts
浏览文件 @
de173cf4
...
...
@@ -30,7 +30,7 @@ const retryPromise = require('retry-promise').default
import
{
Contact
}
from
'
../contact
'
import
{
C
onfig
,
c
onfig
,
RecommendInfo
,
log
,
}
from
'
../config
'
...
...
@@ -97,7 +97,7 @@ export class PuppetWebFriendRequest extends FriendRequest {
this
.
hello
=
hello
}
return
C
onfig
.
puppetInstance
()
return
c
onfig
.
puppetInstance
()
.
friendRequestSend
(
contact
,
hello
)
}
...
...
@@ -108,7 +108,7 @@ export class PuppetWebFriendRequest extends FriendRequest {
throw
new
Error
(
'
request is not a `receive` type. it is a
'
+
this
.
type
+
'
type
'
)
}
const
ret
=
await
C
onfig
.
puppetInstance
()
const
ret
=
await
c
onfig
.
puppetInstance
()
.
friendRequestAccept
(
this
.
contact
,
this
.
ticket
)
const
max
=
20
...
...
src/puppet-web/puppet-web.ts
浏览文件 @
de173cf4
...
...
@@ -17,7 +17,7 @@
*
*/
import
{
C
onfig
,
c
onfig
,
HeadName
,
log
,
Raven
,
...
...
@@ -75,7 +75,7 @@ export class PuppetWeb extends Puppet {
super
()
if
(
!
setting
.
head
)
{
setting
.
head
=
C
onfig
.
head
setting
.
head
=
c
onfig
.
head
}
this
.
on
(
'
watchdog
'
,
Watchdog
.
onFeed
.
bind
(
this
))
}
...
...
src/room.ts
浏览文件 @
de173cf4
...
...
@@ -19,7 +19,7 @@
import
{
EventEmitter
}
from
'
events
'
import
{
C
onfig
,
c
onfig
,
Raven
,
Sayable
,
log
,
...
...
@@ -134,8 +134,8 @@ export class Room extends EventEmitter implements Sayable {
}
if
(
!
contactGetter
)
{
contactGetter
=
C
onfig
.
puppetInstance
()
.
getContact
.
bind
(
C
onfig
.
puppetInstance
())
contactGetter
=
c
onfig
.
puppetInstance
()
.
getContact
.
bind
(
c
onfig
.
puppetInstance
())
}
if
(
!
contactGetter
)
{
throw
new
Error
(
'
no contactGetter
'
)
...
...
@@ -216,7 +216,7 @@ export class Room extends EventEmitter implements Sayable {
m
.
room
(
this
)
return
C
onfig
.
puppetInstance
()
return
c
onfig
.
puppetInstance
()
.
send
(
m
)
}
...
...
@@ -295,7 +295,7 @@ export class Room extends EventEmitter implements Sayable {
throw
new
Error
(
'
contact not found
'
)
}
const
n
=
C
onfig
.
puppetInstance
()
const
n
=
c
onfig
.
puppetInstance
()
.
roomAdd
(
this
,
contact
)
return
n
}
...
...
@@ -306,7 +306,7 @@ export class Room extends EventEmitter implements Sayable {
if
(
!
contact
)
{
throw
new
Error
(
'
contact not found
'
)
}
const
n
=
await
C
onfig
.
puppetInstance
()
const
n
=
await
c
onfig
.
puppetInstance
()
.
roomDel
(
this
,
contact
)
.
then
(
_
=>
this
.
delLocal
(
contact
))
return
n
...
...
@@ -354,7 +354,7 @@ export class Room extends EventEmitter implements Sayable {
if
(
newTopic
)
{
log
.
verbose
(
'
Room
'
,
'
topic(%s)
'
,
newTopic
)
C
onfig
.
puppetInstance
()
c
onfig
.
puppetInstance
()
.
roomTopic
(
this
,
newTopic
)
.
catch
(
e
=>
{
log
.
warn
(
'
Room
'
,
'
topic(newTopic=%s) exception: %s
'
,
...
...
@@ -408,7 +408,7 @@ export class Room extends EventEmitter implements Sayable {
public
owner
():
Contact
|
null
{
const
ownerUin
=
this
.
obj
&&
this
.
obj
.
ownerUin
const
user
=
C
onfig
.
puppetInstance
()
const
user
=
c
onfig
.
puppetInstance
()
.
user
if
(
user
&&
user
.
get
(
'
uin
'
)
===
ownerUin
)
{
...
...
@@ -547,7 +547,7 @@ export class Room extends EventEmitter implements Sayable {
throw
new
Error
(
'
contactList not found
'
)
}
return
C
onfig
.
puppetInstance
()
return
c
onfig
.
puppetInstance
()
.
roomCreate
(
contactList
,
topic
)
.
catch
(
e
=>
{
log
.
error
(
'
Room
'
,
'
create() exception: %s
'
,
e
&&
e
.
stack
||
e
.
message
||
e
)
...
...
@@ -579,7 +579,7 @@ export class Room extends EventEmitter implements Sayable {
throw
new
Error
(
'
unsupport topic type
'
)
}
const
roomList
=
await
C
onfig
.
puppetInstance
()
const
roomList
=
await
c
onfig
.
puppetInstance
()
.
roomFind
(
filterFunction
)
.
catch
(
e
=>
{
log
.
verbose
(
'
Room
'
,
'
findAll() rejected: %s
'
,
e
.
message
)
...
...
src/wechaty.ts
浏览文件 @
de173cf4
...
...
@@ -17,13 +17,11 @@
*
*/
import
{
EventEmitter
}
from
'
events
'
import
*
as
fs
from
'
fs
'
import
*
as
path
from
'
path
'
import
{
StateSwitch
}
from
'
state-switch
'
import
{
C
onfig
,
c
onfig
,
HeadName
,
PuppetName
,
Raven
,
...
...
@@ -103,11 +101,7 @@ export class Wechaty extends EventEmitter implements Sayable {
* @private
*/
private
state
=
new
StateSwitch
<
'
standby
'
,
'
ready
'
>
(
'
Wechaty
'
,
'
standby
'
,
log
)
/**
* the npmVersion
* @private
*/
private
npmVersion
:
string
=
require
(
'
../package.json
'
).
version
/**
* the uuid
* @private
...
...
@@ -134,9 +128,9 @@ export class Wechaty extends EventEmitter implements Sayable {
super
()
log
.
verbose
(
'
Wechaty
'
,
'
contructor()
'
)
setting
.
head
=
setting
.
head
||
C
onfig
.
head
setting
.
puppet
=
setting
.
puppet
||
C
onfig
.
puppet
setting
.
profile
=
setting
.
profile
||
C
onfig
.
profile
setting
.
head
=
setting
.
head
||
c
onfig
.
head
setting
.
puppet
=
setting
.
puppet
||
c
onfig
.
puppet
setting
.
profile
=
setting
.
profile
||
c
onfig
.
profile
// setting.port = setting.port || Config.port
...
...
@@ -166,39 +160,18 @@ export class Wechaty extends EventEmitter implements Sayable {
* console.log(Wechaty.instance().version(true))
* // '0.7.9'
*/
public
version
(
forceNpm
=
false
):
string
{
// TODO: use git rev-parse HEAD ?
const
dotGitPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
.git
'
)
// only for ts-node, not for dist
// TODO: use git rev-parse HEAD ?
const
gitLogCmd
=
'
git
'
const
gitLogArgs
=
[
'
log
'
,
'
--oneline
'
,
'
-1
'
]
public
static
version
(
forceNpm
=
false
):
string
{
if
(
!
forceNpm
)
{
try
{
fs
.
statSync
(
dotGitPath
).
isDirectory
()
const
ss
=
require
(
'
child_process
'
)
.
spawnSync
(
gitLogCmd
,
gitLogArgs
,
{
cwd
:
__dirname
})
if
(
ss
.
status
!==
0
)
{
throw
new
Error
(
ss
.
error
)
}
const
revision
=
ss
.
stdout
.
toString
()
.
trim
()
const
revision
=
config
.
gitVersion
()
if
(
revision
)
{
return
`#git[
${
revision
}
]`
}
catch
(
e
)
{
/* fall safe */
/**
* 1. .git not exist
* 2. git log fail
*/
log
.
silly
(
'
Wechaty
'
,
'
version() form development environment is not availble: %s
'
,
e
.
message
)
}
}
return
config
.
npmVersion
()
}
return
this
.
npmVersion
public
version
(
forceNpm
?)
{
return
Wechaty
.
version
(
forceNpm
)
}
/**
...
...
@@ -378,7 +351,7 @@ export class Wechaty extends EventEmitter implements Sayable {
this
.
puppet
=
<
Puppet
>
puppet
// force to use base class Puppet interface for better encapsolation
// set puppet instance to Wechaty Static variable, for using by Contact/Room/Message/FriendRequest etc.
C
onfig
.
puppetInstance
(
puppet
)
c
onfig
.
puppetInstance
(
puppet
)
await
puppet
.
init
()
return
puppet
...
...
@@ -405,7 +378,7 @@ export class Wechaty extends EventEmitter implements Sayable {
const
puppetBeforeDie
=
this
.
puppet
this
.
puppet
=
null
C
onfig
.
puppetInstance
(
null
)
c
onfig
.
puppetInstance
(
null
)
await
puppetBeforeDie
.
quit
()
.
catch
(
e
=>
{
...
...
test/contact.spec.ts
浏览文件 @
de173cf4
...
...
@@ -17,11 +17,11 @@
*
*/
import
{
test
}
from
'
ava
'
import
C
onfig
from
'
../src/config
'
import
c
onfig
from
'
../src/config
'
import
Contact
from
'
../src/contact
'
import
PuppetWeb
from
'
../src/puppet-web
'
C
onfig
.
puppetInstance
(
new
PuppetWeb
())
c
onfig
.
puppetInstance
(
new
PuppetWeb
())
test
(
'
Contact smoke testing
'
,
async
t
=>
{
/* tslint:disable:variable-name */
...
...
test/docker.spec.ts
浏览文件 @
de173cf4
...
...
@@ -22,20 +22,20 @@ import * as fs from 'fs'
// import { execSync } from 'child_process'
// import * as sinon from 'sinon'
import
C
onfig
from
'
../src/config
'
import
c
onfig
from
'
../src/config
'
/**
* need keep this !Config.dockerMode because ava need at least one test() inside.
* × No tests found in test\docker.spec.js
*/
if
(
C
onfig
.
dockerMode
)
{
if
(
c
onfig
.
dockerMode
)
{
test
(
'
Docker smoke testing
'
,
function
(
t
)
{
// const n = execSync('ps a | grep Xvfb | grep -v grep | wc -l').toString().replace(/\n/, '', 'g')
// t.is(parseInt(n), 1, 'should has Xvfb started')
t
.
notThrows
(()
=>
{
// fs.accessSync(Config.CMD_CHROMIUM, fs['X_OK'])
fs
.
statSync
(
C
onfig
.
CMD_CHROMIUM
).
isFile
()
fs
.
statSync
(
c
onfig
.
CMD_CHROMIUM
).
isFile
()
},
'
should exist xvfb-chrome exectable
'
)
})
...
...
test/puppet-web/browser.spec.ts
浏览文件 @
de173cf4
...
...
@@ -20,7 +20,7 @@ import * as fs from 'fs'
import
{
test
}
from
'
ava
'
import
{
C
onfig
,
c
onfig
,
log
,
}
from
'
../../
'
...
...
@@ -31,7 +31,7 @@ import {
const
TEST_DOMAIN
=
'
www.chatie.io
'
const
TEST_URL
=
'
https://
'
+
TEST_DOMAIN
const
PROFILE
=
C
onfig
.
DEFAULT_PROFILE
+
'
-
'
+
process
.
pid
+
'
-
'
const
PROFILE
=
c
onfig
.
DEFAULT_PROFILE
+
'
-
'
+
process
.
pid
+
'
-
'
let
profileCounter
=
1
test
(
'
Cookie smoke testing
'
,
async
t
=>
{
...
...
@@ -105,7 +105,7 @@ test('Cookie save/load', async t => {
const
profileName
=
PROFILE
+
(
profileCounter
++
)
let
browser
=
new
Browser
({
head
:
C
onfig
.
head
,
head
:
c
onfig
.
head
,
sessionFile
:
profileName
,
})
...
...
@@ -179,7 +179,7 @@ test('Cookie save/load', async t => {
*/
browser
=
new
Browser
({
head
:
C
onfig
.
head
,
head
:
c
onfig
.
head
,
sessionFile
:
profileName
,
})
...
...
test/puppet-web/puppet-web.spec.ts
浏览文件 @
de173cf4
...
...
@@ -19,7 +19,7 @@
import
{
test
}
from
'
ava
'
import
{
C
onfig
,
c
onfig
,
log
,
}
from
'
../../src/config
'
import
PuppetWeb
from
'
../../src/puppet-web
'
...
...
@@ -34,7 +34,7 @@ test.serial('login/logout events', async t => {
const
pw
=
new
PuppetWeb
()
t
.
truthy
(
pw
,
'
should instantiated a PuppetWeb
'
)
C
onfig
.
puppetInstance
(
pw
)
c
onfig
.
puppetInstance
(
pw
)
await
pw
.
init
()
t
.
pass
(
'
should be inited
'
)
...
...
@@ -61,7 +61,7 @@ test.serial('server/browser socketio ding', async t => {
const
puppet
=
new
PuppetWeb
()
t
.
truthy
(
puppet
,
'
should instantiated a PuppetWeb
'
)
C
onfig
.
puppetInstance
(
puppet
)
c
onfig
.
puppetInstance
(
puppet
)
const
EXPECTED_DING_DATA
=
'
dingdong
'
...
...
test/room.spec.ts
浏览文件 @
de173cf4
...
...
@@ -18,12 +18,12 @@
*/
import
{
test
}
from
'
ava
'
import
C
onfig
from
'
../src/config
'
import
c
onfig
from
'
../src/config
'
import
Contact
from
'
../src/contact
'
import
PuppetWeb
from
'
../src/puppet-web
'
import
Room
from
'
../src/room
'
C
onfig
.
puppetInstance
(
new
PuppetWeb
())
c
onfig
.
puppetInstance
(
new
PuppetWeb
())
// Room.attach(new PuppetWeb())
// test('Room smoke testing', async t => {
...
...
@@ -105,11 +105,11 @@ test('Room smoking test', async t => {
let
puppet
try
{
puppet
=
C
onfig
.
puppetInstance
()
puppet
=
c
onfig
.
puppetInstance
()
puppet
.
getContact
=
mockContactGetter
}
catch
(
err
)
{
puppet
=
{
getContact
:
mockContactGetter
}
C
onfig
.
puppetInstance
(
puppet
)
c
onfig
.
puppetInstance
(
puppet
)
}
await
r
.
ready
()
...
...
test/wechaty.spec.ts
浏览文件 @
de173cf4
...
...
@@ -19,7 +19,7 @@
import
{
test
}
from
'
ava
'
import
{
C
onfig
,
c
onfig
,
Contact
,
FriendRequest
,
IoClient
,
...
...
@@ -54,8 +54,8 @@ test('Wechaty Framework', t => {
})
test
(
'
Wechaty Config setting
'
,
t
=>
{
t
.
truthy
(
C
onfig
,
'
should export Config
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_HEAD
,
'
should has DEFAULT_HEAD
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_PUPPET
,
'
should has DEFAULT_PUPPET
'
)
t
.
truthy
(
C
onfig
.
DEFAULT_PORT
,
'
should has DEFAULT_PORT
'
)
t
.
truthy
(
c
onfig
,
'
should export Config
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_HEAD
,
'
should has DEFAULT_HEAD
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_PUPPET
,
'
should has DEFAULT_PUPPET
'
)
t
.
truthy
(
c
onfig
.
DEFAULT_PORT
,
'
should has DEFAULT_PORT
'
)
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录