Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
0f02d2a6
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,发现更多精彩内容 >>
提交
0f02d2a6
编写于
7月 12, 2020
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add createFixture (#2022)
上级
86db819f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
163 addition
and
0 deletion
+163
-0
src/create-fixture.spec.ts
src/create-fixture.spec.ts
+81
-0
src/create-fixture.ts
src/create-fixture.ts
+82
-0
未找到文件。
src/create-fixture.spec.ts
0 → 100755
浏览文件 @
0f02d2a6
#!/usr/bin/env ts-node
import
{
test
,
sinon
,
}
from
'
tstest
'
import
{
MockContact
}
from
'
wechaty-puppet-mock/dist/src/mocker/user/mock-contact
'
import
{
Message
}
from
'
./user/message
'
import
{
createFixture
}
from
'
./create-fixture
'
test
(
'
createFixture() initial state
'
,
async
(
t
)
=>
{
for
await
(
const
fixture
of
createFixture
())
{
t
.
true
(
fixture
.
message
instanceof
Message
,
'
should have message instance
'
)
t
.
equal
(
fixture
.
message
.
type
(),
Message
.
Type
.
Text
,
'
should have message with text type
'
)
t
.
equal
(
typeof
fixture
.
message
.
text
(),
'
string
'
,
'
should have message with text content
'
)
t
.
equal
(
fixture
.
moList
.
length
,
0
,
'
should be empty mo list
'
)
t
.
equal
(
fixture
.
mtList
.
length
,
0
,
'
should be empty mt list
'
)
t
.
true
(
fixture
.
mary
instanceof
MockContact
,
'
should get mock contact mary
'
)
t
.
true
(
fixture
.
mike
instanceof
MockContact
,
'
should get mock contact mike
'
)
}
})
test
(
'
createFixture() Mobile Originated
'
,
async
(
t
)
=>
{
for
await
(
const
fixture
of
createFixture
())
{
const
spy
=
sinon
.
spy
()
fixture
.
wechaty
.
on
(
'
message
'
,
spy
)
fixture
.
user
.
say
().
to
(
fixture
.
mary
)
await
new
Promise
(
setImmediate
)
t
.
true
(
spy
.
called
,
'
should received message event
'
)
t
.
equal
(
spy
.
args
[
0
][
0
].
from
().
id
,
fixture
.
user
.
id
,
'
should get user as from
'
)
t
.
equal
(
spy
.
args
[
0
][
0
].
to
().
id
,
fixture
.
mary
.
id
,
'
should get mary as to
'
)
t
.
equal
(
fixture
.
moList
.
length
,
1
,
'
should be 1 mo
'
)
t
.
equal
(
fixture
.
mtList
.
length
,
0
,
'
should be empty mt list
'
)
t
.
equal
(
fixture
.
moList
[
0
].
id
,
spy
.
args
[
0
][
0
].
id
,
'
should get the same message instance
'
)
}
})
test
(
'
createFixture() Mobile Terminated
'
,
async
(
t
)
=>
{
for
await
(
const
fixture
of
createFixture
())
{
const
spy
=
sinon
.
spy
()
fixture
.
wechaty
.
on
(
'
message
'
,
spy
)
fixture
.
mary
.
say
().
to
(
fixture
.
user
)
await
new
Promise
(
setImmediate
)
t
.
true
(
spy
.
called
,
'
should received message event
'
)
t
.
equal
(
spy
.
args
[
0
][
0
].
to
().
id
,
fixture
.
user
.
id
,
'
should get user as to
'
)
t
.
equal
(
spy
.
args
[
0
][
0
].
from
().
id
,
fixture
.
mary
.
id
,
'
should get mary as from
'
)
t
.
equal
(
fixture
.
moList
.
length
,
0
,
'
should be 0 mo
'
)
t
.
equal
(
fixture
.
mtList
.
length
,
1
,
'
should be 1 mt
'
)
t
.
equal
(
fixture
.
mtList
[
0
].
id
,
spy
.
args
[
0
][
0
].
id
,
'
should get the same message instance
'
)
}
})
test
(
'
user.say() multiple times with moList
'
,
async
t
=>
{
for
await
(
const
fixture
of
createFixture
())
{
const
TEXT_LIST
=
[
'
one
'
,
'
two
'
,
'
three
'
,
]
for
(
const
text
of
TEXT_LIST
)
{
await
fixture
.
user
.
say
(
text
).
to
(
fixture
.
mary
)
}
await
new
Promise
(
setImmediate
)
t
.
equal
(
fixture
.
moList
.
length
,
TEXT_LIST
.
length
,
'
should receive all TEXT_LIST
'
)
for
(
let
i
=
0
;
i
<
TEXT_LIST
.
length
;
i
++
)
{
t
.
ok
(
fixture
.
moList
[
i
],
`should exist moList for
${
i
}
`
)
t
.
deepEqual
(
fixture
.
moList
[
i
].
text
(),
TEXT_LIST
[
i
],
`should get TEXT_LIST[
${
i
}
]:
${
TEXT_LIST
[
i
]}
`
)
}
}
})
src/create-fixture.ts
0 → 100644
浏览文件 @
0f02d2a6
/* eslint-disable sort-keys */
import
{
PuppetMock
,
Mocker
,
}
from
'
wechaty-puppet-mock
'
import
{
MockContact
}
from
'
wechaty-puppet-mock/dist/src/mocker/user/mock-contact
'
import
{
MockRoom
}
from
'
wechaty-puppet-mock/dist/src/mocker/user/mock-room
'
import
{
Wechaty
}
from
'
./wechaty
'
import
{
Message
}
from
'
./user/message
'
interface
Fixture
{
wechaty
:
Wechaty
,
mocker
:
Mocker
,
message
:
Message
,
moList
:
Message
[],
mtList
:
Message
[],
user
:
MockContact
,
mary
:
MockContact
,
mike
:
MockContact
,
room
:
MockRoom
,
}
async
function
*
createFixture
():
AsyncGenerator
<
Fixture
>
{
const
mocker
=
new
Mocker
()
const
puppet
=
new
PuppetMock
({
mocker
})
const
wechaty
=
new
Wechaty
({
puppet
})
await
wechaty
.
start
()
const
[
user
,
mike
,
mary
]
=
mocker
.
createContacts
(
3
)
mocker
.
login
(
user
)
const
room
=
mocker
.
createRoom
({
memberIdList
:
[
user
.
id
,
mike
.
id
,
mary
.
id
,
],
})
const
messageFuture
=
new
Promise
<
Message
>
(
resolve
=>
wechaty
.
once
(
'
message
'
,
resolve
))
mike
.
say
().
to
(
room
)
const
message
=
await
messageFuture
// Mobile Terminated
const
mtList
=
[]
as
Message
[]
const
recordMobileTerminatedMessage
=
(
message
:
Message
)
=>
{
if
(
!
message
.
self
())
{
mtList
.
push
(
message
)
}
}
wechaty
.
on
(
'
message
'
,
recordMobileTerminatedMessage
)
// Mobile Originated
const
moList
=
[]
as
Message
[]
const
recordMobileOriginatedMessage
=
(
message
:
Message
)
=>
{
if
(
message
.
self
())
{
moList
.
push
(
message
)
}
}
wechaty
.
on
(
'
message
'
,
recordMobileOriginatedMessage
)
yield
{
wechaty
,
mocker
,
message
,
moList
,
mtList
,
user
,
mary
,
mike
,
room
,
}
await
wechaty
.
stop
()
}
export
{
createFixture
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录