Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wechaty/puppet-mock
Puppet Mocker for Wechaty (& A Puppet Template Starter)
https://github.com/wechaty/puppet-mock
mock pupet testing wechaty
Last synced: 11 days ago
JSON representation
Puppet Mocker for Wechaty (& A Puppet Template Starter)
- Host: GitHub
- URL: https://github.com/wechaty/puppet-mock
- Owner: wechaty
- License: apache-2.0
- Created: 2018-06-27T14:56:58.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-10-03T07:43:42.000Z (over 2 years ago)
- Last Synced: 2024-10-02T22:01:23.573Z (5 months ago)
- Topics: mock, pupet, testing, wechaty
- Language: TypeScript
- Homepage: https://paka.dev/npm/wechaty-puppet-mock
- Size: 273 KB
- Stars: 46
- Watchers: 4
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PUPPET-MOCK
[](https://badge.fury.io/js/wechaty-puppet-mock)
[](https://www.npmjs.com/package/wechaty-puppet-mock?activeTab=versions)
[](https://github.com/wechaty/wechaty-puppet-mock/actions?query=workflow%3ANPM)
[](https://github.com/Chatie/tsconfig/issues/16)
> Picture Credit:
[](https://github.com/wechaty/wechaty)
[](https://www.typescriptlang.org/)Puppet Mocker & Starter Template for Wechaty, it is very useful when you:
1. Want to test the Wechaty framework with a mock puppet, or
1. You want to write your own Puppet implenmentation.Then `PuppetMock` will helps you a lot.
## USAGE
### Puppet Mock
```ts
import { Wechaty } from 'wechaty'
import { PuppetMock } from 'wechaty-puppet-mock'const puppet = new PuppetMock()
const wechaty = new Wechaty({ puppet })wechaty.start()
```### Mocker & Environment
```ts
import {
PuppetMock,
Mocker,
SimpleEnvironment,
} from 'wechaty-puppet-mock'const mocker = new Mocker()
mocker.use(SimpleEnvironment())const puppet = new PuppetMock({ mocker })
const wechaty = new Wechaty({ puppet })wechaty.start()
// The Mocker will start perform the SimpleEnvironment...
```See: [SimpleEnvironment](src/mocker/environment.ts)
## API Reference
### Mocker
```ts
import { Wechaty } from 'wechaty'
import { PuppetMock, mock } from 'wechaty-puppet-mock'const mocker = new mock.Mocker()
const puppet = new PuppetMock({ mocker })
const bot = new Wechaty({ puppet })await bot.start()
mocker.scan('https://github.com/wechaty', 1)
const user = mocker.createContact()
mocker.login(user)const contact = mocker.createContact()
const room = mocker.createRoom()user.say('Hello').to(contact)
contact.say('World').to(user)
```## HELPER UTILITIES
### StateSwitch
```ts
this.state.on('pending')
this.state.on(true)
this.state.off('pending')
this.state.off(true)await this.state.ready('on')
await this.state.ready('off')```
### Watchdog
```ts
```### MemoryCard
```ts
await memory.set('config', { id: 1, key: 'xxx' })
const config = await memory.get('config')
console.log(config)
// Output: { id: 1, key: 'xxx' }
```## HISTORY
### master v1.18 (Mar 14, 2022)
Upgrade to Wechaty Puppet v1.18
### v1.0 (Oct 29, 2021)
Release v1.0 of Puppet Mock
1. v0.31: Support ES Modules
### v0.25 (July 13, 2020)
1. Rename `MockXXX` to `XXXMock` for keep the consistent naming style with `PuppetMock`.
1. Export `mock` namespace and move all related modules under it.### v0.22 (June 4, 2020)
`Mocker` Released. `Mocker` is a manager for controlling the behavior of the Puppet activities.
1. Add `MockContact`, `MockRoom`, and `MockMessage` for `Mockers`
1. Add `MockEnvironment` for mocking the server behaviors.
1. Support `Wechaty#Contact.find()` from the `mocker.createContacts()`
1. Support `Wechaty#Room.find()` from the `mocker.createRooms()`
1. Support `message` event for `talker`, `listener`, and `room` of `MockMessage`### v0.0.1 (Jun 27, 2018)
Initial version.
`PuppetMock` is a skelton Puppet without do anything, it will make testing easy when developing Wechaty
## AUTHOR
[Huan LI](http://linkedin.com/in/zixia) \
## COPYRIGHT & LICENSE
* Code & Docs © 2018 Huan LI \
* Code released under the Apache-2.0 License
* Docs released under Creative Commons