Repository navigation
chore: migrate to Wechaty 2 EventTarget API and PuppetMock ding-dong test #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
huan
wants to merge
1
commit into
main
Choose a base branch
from
fix/wechaty-alpha21-mock-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,76 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Smoke test for Wechaty with `wechaty-puppet-mock`. | ||
| * Smoke tests for Wechaty with `wechaty-puppet-mock`. | ||
| * | ||
| * Verifies that `WechatyBuilder` starts a mocked bot, emits a `scan` event, | ||
| * and stops cleanly within the test timeout. | ||
| * Verifies that `Wechaty` starts a mocked bot, emits a `scan` event, | ||
| * handles a `ding` -> `dong` message roundtrip, and stops cleanly. | ||
| */ | ||
|
|
||
| import assert from 'node:assert/strict' | ||
| import { test } from 'node:test' | ||
|
|
||
| import { WechatyBuilder } from 'wechaty' | ||
| import { Wechaty } from 'wechaty' | ||
| import { | ||
| mock, | ||
| PuppetMock, | ||
| } from 'wechaty-puppet-mock' | ||
|
|
||
| test('wechaty-puppet-mock', { timeout: 120_000 }, async (t) => { | ||
| test('wechaty-puppet-mock scan', { timeout: 120_000 }, async (t) => { | ||
| const mocker = new mock.Mocker() | ||
| mocker.use(mock.SimpleEnvironment()) | ||
| const puppetMock = new PuppetMock({ mocker }) | ||
|
|
||
| const bot = WechatyBuilder.build({ | ||
| // wechaty-puppet-mock@1.x still bundles wechaty-puppet@1.x types | ||
| puppet: puppetMock as unknown as Exclude<NonNullable<Parameters<typeof WechatyBuilder.build>[0]>['puppet'], string | undefined>, | ||
| const bot = new Wechaty({ | ||
| puppet: puppetMock, | ||
| }) | ||
|
|
||
| t.after(async () => { | ||
| await bot.stop().catch(() => undefined) | ||
| }) | ||
|
|
||
| const future = new Promise((resolve) => bot.once('scan', resolve)) | ||
| const future = bot.next('scan') | ||
| await bot.start() | ||
| await future | ||
|
|
||
| assert.ok(bot.puppet, `Puppet ${bot.puppet} v${bot.puppet.version()} smoke testing passed.`) | ||
| }) | ||
|
|
||
| test('wechaty-puppet-mock ding-dong', { timeout: 120_000 }, async (t) => { | ||
| const mocker = new mock.Mocker() | ||
| const puppetMock = new PuppetMock({ mocker }) | ||
|
|
||
| const bot = new Wechaty({ | ||
| puppet: puppetMock, | ||
| }) | ||
|
|
||
| t.after(async () => { | ||
| await bot.stop().catch(() => undefined) | ||
| }) | ||
|
|
||
| const botContact = mocker.createContact({ name: 'Bot' }) | ||
| const userContact = mocker.createContact({ name: 'User' }) | ||
|
|
||
| const replyFuture = new Promise<string>((resolve) => { | ||
| userContact.on('message', (msg) => { | ||
| if (msg.text() === 'dong') { | ||
| resolve(msg.text() ?? '') | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| bot.addEventListener('message', async ({ detail: msg }) => { | ||
| if (msg.text() === 'ding') { | ||
| await msg.say('dong') | ||
| } | ||
| }) | ||
|
|
||
| const loginFuture = bot.next('login') | ||
| await bot.start() | ||
| mocker.login(botContact) | ||
| await loginFuture | ||
|
|
||
| userContact.say('ding').to(botContact) | ||
| const reply = await replyFuture | ||
|
|
||
| assert.equal(reply, 'dong') | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a fresh checkout following the documented
npm install/npm startflow withoutWECHATY_PUPPET, removing the explicit puppet does not select a compatible replacement for Neo. Wechaty resolves an omitted puppet through its system configuration, whose default iswechaty-puppet-wechat4u, not Neo. This silently changes the starter's backend while its header, README, and tutorial still promise Neo's QR-code login flow; the README's explicit Neo example also imports the dependency removed in this commit. Configure a supported Wechaty 2 puppet and update the installation and login instructions together, rather than leaving the main entry point dependent on an undocumented fallback. The same omission affectsexamples/basic/ding-dong-bot.ts.AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.