@pacoyang/wechaty-puppet-wechat 0.28.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +14 -0
- package/.eslintrc.js +7 -0
- package/.github/workflows/npm.yml +91 -0
- package/.markdownlintrc +13 -0
- package/.travis.yml +62 -0
- package/.vscode/settings.json +73 -0
- package/CODEOWNERS +9 -0
- package/LICENSE +201 -0
- package/NOTICE +8 -0
- package/README.md +145 -0
- package/dist/examples/demo.d.ts +20 -0
- package/dist/examples/demo.d.ts.map +1 -0
- package/dist/examples/demo.js +113 -0
- package/dist/examples/demo.js.map +1 -0
- package/dist/scripts/retry-unit-tests.d.ts +10 -0
- package/dist/scripts/retry-unit-tests.d.ts.map +1 -0
- package/dist/scripts/retry-unit-tests.js +47 -0
- package/dist/scripts/retry-unit-tests.js.map +1 -0
- package/dist/src/bridge.d.ts +100 -0
- package/dist/src/bridge.d.ts.map +1 -0
- package/dist/src/bridge.js +927 -0
- package/dist/src/bridge.js.map +1 -0
- package/dist/src/bridge.spec.d.ts +21 -0
- package/dist/src/bridge.spec.d.ts.map +1 -0
- package/dist/src/bridge.spec.js +191 -0
- package/dist/src/bridge.spec.js.map +1 -0
- package/dist/src/config.d.ts +10 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +57 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/event.d.ts +23 -0
- package/dist/src/event.d.ts.map +1 -0
- package/dist/src/event.js +166 -0
- package/dist/src/event.js.map +1 -0
- package/dist/src/event.spec.d.ts +3 -0
- package/dist/src/event.spec.d.ts.map +1 -0
- package/dist/src/event.spec.js +41 -0
- package/dist/src/event.spec.js.map +1 -0
- package/dist/src/firer.d.ts +50 -0
- package/dist/src/firer.d.ts.map +1 -0
- package/dist/src/firer.js +409 -0
- package/dist/src/firer.js.map +1 -0
- package/dist/src/firer.spec.d.ts +21 -0
- package/dist/src/firer.spec.d.ts.map +1 -0
- package/dist/src/firer.spec.js +190 -0
- package/dist/src/firer.spec.js.map +1 -0
- package/dist/src/mod.d.ts +23 -0
- package/dist/src/mod.d.ts.map +1 -0
- package/dist/src/mod.js +28 -0
- package/dist/src/mod.js.map +1 -0
- package/dist/src/puppet-wechat.d.ts +164 -0
- package/dist/src/puppet-wechat.d.ts.map +1 -0
- package/dist/src/puppet-wechat.js +1287 -0
- package/dist/src/puppet-wechat.js.map +1 -0
- package/dist/src/puppet-wechat.spec.d.ts +21 -0
- package/dist/src/puppet-wechat.spec.d.ts.map +1 -0
- package/dist/src/puppet-wechat.spec.js +123 -0
- package/dist/src/puppet-wechat.spec.js.map +1 -0
- package/dist/src/pure-function-helpers/is-type.d.ts +3 -0
- package/dist/src/pure-function-helpers/is-type.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/is-type.js +12 -0
- package/dist/src/pure-function-helpers/is-type.js.map +1 -0
- package/dist/src/pure-function-helpers/message-extname.d.ts +3 -0
- package/dist/src/pure-function-helpers/message-extname.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-extname.js +44 -0
- package/dist/src/pure-function-helpers/message-extname.js.map +1 -0
- package/dist/src/pure-function-helpers/message-filename.d.ts +3 -0
- package/dist/src/pure-function-helpers/message-filename.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-filename.js +19 -0
- package/dist/src/pure-function-helpers/message-filename.js.map +1 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.d.ts +4 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.js +67 -0
- package/dist/src/pure-function-helpers/message-raw-payload-parser.js.map +1 -0
- package/dist/src/pure-function-helpers/mod.d.ts +7 -0
- package/dist/src/pure-function-helpers/mod.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/mod.js +23 -0
- package/dist/src/pure-function-helpers/mod.js.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.d.ts +3 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.js +21 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.js.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.d.ts +21 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.js +37 -0
- package/dist/src/pure-function-helpers/normalize-scan-status.spec.js.map +1 -0
- package/dist/src/pure-function-helpers/web-message-type.d.ts +4 -0
- package/dist/src/pure-function-helpers/web-message-type.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/web-message-type.js +58 -0
- package/dist/src/pure-function-helpers/web-message-type.js.map +1 -0
- package/dist/src/pure-function-helpers/xml.d.ts +14 -0
- package/dist/src/pure-function-helpers/xml.d.ts.map +1 -0
- package/dist/src/pure-function-helpers/xml.js +64 -0
- package/dist/src/pure-function-helpers/xml.js.map +1 -0
- package/dist/src/version.d.ts +6 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +9 -0
- package/dist/src/version.js.map +1 -0
- package/dist/src/version.spec.d.ts +3 -0
- package/dist/src/version.spec.d.ts.map +1 -0
- package/dist/src/version.spec.js +13 -0
- package/dist/src/version.spec.js.map +1 -0
- package/dist/src/web-schemas.d.ts +249 -0
- package/dist/src/web-schemas.d.ts.map +1 -0
- package/dist/src/web-schemas.js +118 -0
- package/dist/src/web-schemas.js.map +1 -0
- package/dist/src/wechaty-bro.js +868 -0
- package/dist/tests/puppeteer-contact.spec.d.ts +21 -0
- package/dist/tests/puppeteer-contact.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-contact.spec.js +67 -0
- package/dist/tests/puppeteer-contact.spec.js.map +1 -0
- package/dist/tests/puppeteer-friendship.spec.d.ts +21 -0
- package/dist/tests/puppeteer-friendship.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-friendship.spec.js +115 -0
- package/dist/tests/puppeteer-friendship.spec.js.map +1 -0
- package/dist/tests/puppeteer-message.spec.d.ts +21 -0
- package/dist/tests/puppeteer-message.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-message.spec.js +184 -0
- package/dist/tests/puppeteer-message.spec.js.map +1 -0
- package/dist/tests/puppeteer-room.spec.d.ts +21 -0
- package/dist/tests/puppeteer-room.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer-room.spec.js +129 -0
- package/dist/tests/puppeteer-room.spec.js.map +1 -0
- package/dist/tests/puppeteer.spec.d.ts +21 -0
- package/dist/tests/puppeteer.spec.d.ts.map +1 -0
- package/dist/tests/puppeteer.spec.js +213 -0
- package/dist/tests/puppeteer.spec.js.map +1 -0
- package/docs/images/puppeteer-logo.png +0 -0
- package/docs/images/wechaty-puppet-wechat.png +0 -0
- package/examples/demo.ts +130 -0
- package/package.json +94 -0
- package/scripts/generate-version.sh +18 -0
- package/scripts/npm-pack-testing.sh +49 -0
- package/scripts/package-publish-config-tag.sh +13 -0
- package/scripts/retry-unit-tests.ts +57 -0
- package/src/bridge.spec.ts +224 -0
- package/src/bridge.ts +1122 -0
- package/src/config.ts +71 -0
- package/src/event.spec.ts +41 -0
- package/src/event.ts +247 -0
- package/src/firer.spec.ts +208 -0
- package/src/firer.ts +530 -0
- package/src/mod.ts +29 -0
- package/src/puppet-wechat.spec.ts +149 -0
- package/src/puppet-wechat.ts +1659 -0
- package/src/pure-function-helpers/is-type.ts +7 -0
- package/src/pure-function-helpers/message-extname.ts +57 -0
- package/src/pure-function-helpers/message-filename.ts +25 -0
- package/src/pure-function-helpers/message-raw-payload-parser.ts +85 -0
- package/src/pure-function-helpers/mod.ts +6 -0
- package/src/pure-function-helpers/normalize-scan-status.spec.ts +44 -0
- package/src/pure-function-helpers/normalize-scan-status.ts +23 -0
- package/src/pure-function-helpers/web-message-type.ts +71 -0
- package/src/pure-function-helpers/xml.ts +79 -0
- package/src/typings.d.ts +19 -0
- package/src/version.spec.ts +10 -0
- package/src/version.ts +6 -0
- package/src/web-schemas.ts +298 -0
- package/src/wechaty-bro.js +868 -0
- package/tests/fixtures/inject-file.js +7 -0
- package/tests/fixtures/smoke-testing.ts +42 -0
- package/tests/puppeteer-contact.spec.ts +78 -0
- package/tests/puppeteer-friendship.spec.ts +157 -0
- package/tests/puppeteer-message.spec.ts +249 -0
- package/tests/puppeteer-room.spec.ts +166 -0
- package/tests/puppeteer.spec.ts +262 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
VERSION=$(npx pkg-jq -r .version)
|
|
5
|
+
|
|
6
|
+
if npx --package @chatie/semver semver-is-prod $VERSION; then
|
|
7
|
+
NPM_TAG=latest
|
|
8
|
+
else
|
|
9
|
+
NPM_TAG=next
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
npm run dist
|
|
13
|
+
npm run pack
|
|
14
|
+
|
|
15
|
+
TMPDIR="/tmp/npm-pack-testing.$$"
|
|
16
|
+
mkdir "$TMPDIR"
|
|
17
|
+
mv *-*.*.*.tgz "$TMPDIR"
|
|
18
|
+
cp tests/fixtures/smoke-testing.ts "$TMPDIR"
|
|
19
|
+
|
|
20
|
+
cd $TMPDIR
|
|
21
|
+
npm init -y
|
|
22
|
+
npm install *-*.*.*.tgz \
|
|
23
|
+
@chatie/tsconfig \
|
|
24
|
+
@types/normalize-package-data \
|
|
25
|
+
@types/promise-retry \
|
|
26
|
+
@types/puppeteer \
|
|
27
|
+
brolog \
|
|
28
|
+
file-box \
|
|
29
|
+
memory-card \
|
|
30
|
+
normalize-package-data \
|
|
31
|
+
rxjs \
|
|
32
|
+
rx-queue \
|
|
33
|
+
state-switch \
|
|
34
|
+
"wechaty-puppet@$NPM_TAG" \
|
|
35
|
+
qr-image \
|
|
36
|
+
promise-retry \
|
|
37
|
+
watchdog \
|
|
38
|
+
|
|
39
|
+
./node_modules/.bin/tsc \
|
|
40
|
+
--esModuleInterop \
|
|
41
|
+
--lib dom,esnext \
|
|
42
|
+
--skipLibCheck \
|
|
43
|
+
--noEmitOnError \
|
|
44
|
+
--noImplicitAny \
|
|
45
|
+
--target es6 \
|
|
46
|
+
--module commonjs \
|
|
47
|
+
smoke-testing.ts
|
|
48
|
+
|
|
49
|
+
node smoke-testing.js
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
VERSION=$(npx pkg-jq -r .version)
|
|
5
|
+
|
|
6
|
+
if npx --package @chatie/semver semver-is-prod $VERSION; then
|
|
7
|
+
npx pkg-jq -i '.publishConfig.tag="latest"'
|
|
8
|
+
echo "production release: publicConfig.tag set to latest."
|
|
9
|
+
else
|
|
10
|
+
npx pkg-jq -i '.publishConfig.tag="next"'
|
|
11
|
+
echo 'development release: publicConfig.tag set to next.'
|
|
12
|
+
fi
|
|
13
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/Chatie/wechaty/issues/1084
|
|
4
|
+
* WebDriver / Puppeteer sometimes will fail(i.e. timeout) with no reason.
|
|
5
|
+
* That will cause the unit tests fail randomly.
|
|
6
|
+
* So we need to retry again when unit tests fail,
|
|
7
|
+
* and treat it's really fail after MAX_RETRY_NUM times.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// tslint:disable:no-console
|
|
11
|
+
|
|
12
|
+
import { spawn } from 'child_process'
|
|
13
|
+
|
|
14
|
+
const MAX_RETRY_NUM = 3
|
|
15
|
+
|
|
16
|
+
async function main (): Promise<number> {
|
|
17
|
+
console.info('Safe Test: starting...')
|
|
18
|
+
|
|
19
|
+
let round = 0
|
|
20
|
+
let succ = false
|
|
21
|
+
do {
|
|
22
|
+
console.info(`Safe Test: running for round #${round}`)
|
|
23
|
+
succ = await unitTest()
|
|
24
|
+
if (succ) { // success!
|
|
25
|
+
console.info(`Safe Test: successed at round #${round}!`)
|
|
26
|
+
return 0
|
|
27
|
+
}
|
|
28
|
+
} while (round++ < MAX_RETRY_NUM)
|
|
29
|
+
return 1 // fail finally :(
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function unitTest () {
|
|
33
|
+
const child = spawn(
|
|
34
|
+
'npm',
|
|
35
|
+
[
|
|
36
|
+
'run',
|
|
37
|
+
'test:unit',
|
|
38
|
+
],
|
|
39
|
+
{
|
|
40
|
+
shell: true, // https://stackoverflow.com/a/39682805/1123955
|
|
41
|
+
stdio: 'inherit',
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
45
|
+
child.once('exit', (code) =>
|
|
46
|
+
code === 0 ? resolve(true) : resolve(false),
|
|
47
|
+
)
|
|
48
|
+
child.once('error', reject)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
main()
|
|
53
|
+
.then(process.exit)
|
|
54
|
+
.catch((e) => {
|
|
55
|
+
console.error(e)
|
|
56
|
+
process.exit(1)
|
|
57
|
+
})
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
/**
|
|
3
|
+
* Wechaty - https://github.com/chatie/wechaty
|
|
4
|
+
*
|
|
5
|
+
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
// tslint:disable:arrow-parens
|
|
21
|
+
// tslint:disable:no-shadowed-variable
|
|
22
|
+
|
|
23
|
+
import test from 'blue-tape'
|
|
24
|
+
|
|
25
|
+
// import sinon from 'sinon'
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
launch,
|
|
29
|
+
} from 'puppeteer'
|
|
30
|
+
// import { spy } from 'sinon'
|
|
31
|
+
|
|
32
|
+
import {
|
|
33
|
+
MemoryCard,
|
|
34
|
+
} from 'memory-card'
|
|
35
|
+
|
|
36
|
+
// import {
|
|
37
|
+
// log,
|
|
38
|
+
// } from './config'
|
|
39
|
+
// log.silly('BridgeTesting', 'import typings for Brolog')
|
|
40
|
+
|
|
41
|
+
import Bridge from './bridge'
|
|
42
|
+
|
|
43
|
+
const PUPPETEER_LAUNCH_OPTIONS = {
|
|
44
|
+
args: [
|
|
45
|
+
'--disable-gpu',
|
|
46
|
+
'--disable-setuid-sandbox',
|
|
47
|
+
'--no-sandbox',
|
|
48
|
+
],
|
|
49
|
+
headless: true,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
test('PuppetWeChatBridge', async (t) => {
|
|
53
|
+
const memory = new MemoryCard()
|
|
54
|
+
await memory.load()
|
|
55
|
+
|
|
56
|
+
const bridge = new Bridge({ memory })
|
|
57
|
+
try {
|
|
58
|
+
await bridge.start()
|
|
59
|
+
await bridge.stop()
|
|
60
|
+
t.pass('Bridge instnace')
|
|
61
|
+
} catch (e) {
|
|
62
|
+
t.fail('Bridge instance: ' + e)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
/* eslint indent: off */
|
|
67
|
+
test('preHtmlToXml()', async (t) => {
|
|
68
|
+
const BLOCKED_HTML_ZH = [
|
|
69
|
+
'<pre style="word-wrap: break-word; white-space: pre-wrap;">',
|
|
70
|
+
'<error>',
|
|
71
|
+
'<ret>1203</ret>',
|
|
72
|
+
'<message>当前登录环境异常。为了你的帐号安全,暂时不能登录web微信。你可以通过Windows微信、Mac微信或者手机客户端微信登录。</message>',
|
|
73
|
+
'</error>',
|
|
74
|
+
'</pre>',
|
|
75
|
+
].join('')
|
|
76
|
+
|
|
77
|
+
const BLOCKED_XML_ZH = [
|
|
78
|
+
'<error>',
|
|
79
|
+
'<ret>1203</ret>',
|
|
80
|
+
'<message>当前登录环境异常。为了你的帐号安全,暂时不能登录web微信。你可以通过Windows微信、Mac微信或者手机客户端微信登录。</message>',
|
|
81
|
+
'</error>',
|
|
82
|
+
].join('')
|
|
83
|
+
|
|
84
|
+
const memory = new MemoryCard()
|
|
85
|
+
const bridge = new Bridge({ memory })
|
|
86
|
+
|
|
87
|
+
const xml = bridge.preHtmlToXml(BLOCKED_HTML_ZH)
|
|
88
|
+
t.equal(xml, BLOCKED_XML_ZH, 'should parse html to xml')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('testBlockedMessage()', async t => {
|
|
92
|
+
const BLOCKED_HTML_ZH = [
|
|
93
|
+
'<pre style="word-wrap: break-word; white-space: pre-wrap;">',
|
|
94
|
+
'<error>',
|
|
95
|
+
'<ret>1203</ret>',
|
|
96
|
+
'<message>当前登录环境异常。为了你的帐号安全,暂时不能登录web微信。你可以通过手机客户端或者windows微信登录。</message>',
|
|
97
|
+
'</error>',
|
|
98
|
+
'</pre>',
|
|
99
|
+
].join('')
|
|
100
|
+
|
|
101
|
+
const BLOCKED_XML_ZH = `
|
|
102
|
+
<error>
|
|
103
|
+
<ret>1203</ret>
|
|
104
|
+
<message>当前登录环境异常。为了你的帐号安全,暂时不能登录web微信。你可以通过手机客户端或者windows微信登录。</message>
|
|
105
|
+
</error>
|
|
106
|
+
`
|
|
107
|
+
const BLOCKED_TEXT_ZH = [
|
|
108
|
+
'当前登录环境异常。为了你的帐号安全,暂时不能登录web微信。',
|
|
109
|
+
'你可以通过手机客户端或者windows微信登录。',
|
|
110
|
+
].join('')
|
|
111
|
+
// tslint:disable:max-line-length
|
|
112
|
+
const BLOCKED_XML_EN = `
|
|
113
|
+
<error>
|
|
114
|
+
<ret>1203</ret>
|
|
115
|
+
<message>For account security, newly registered WeChat accounts are unable to log in to Web WeChat. To use WeChat on a computer, use Windows WeChat or Mac WeChat at http://wechat.com</message>
|
|
116
|
+
</error>
|
|
117
|
+
`
|
|
118
|
+
const BLOCKED_TEXT_EN = [
|
|
119
|
+
'For account security, newly registered WeChat accounts are unable to log in to Web WeChat.',
|
|
120
|
+
' To use WeChat on a computer, use Windows WeChat or Mac WeChat at http://wechat.com',
|
|
121
|
+
].join('')
|
|
122
|
+
|
|
123
|
+
t.test('not blocked', async t => {
|
|
124
|
+
const memory = new MemoryCard()
|
|
125
|
+
const bridge = new Bridge({ memory })
|
|
126
|
+
|
|
127
|
+
const msg = await bridge.testBlockedMessage('this is not xml')
|
|
128
|
+
t.equal(msg, false, 'should return false when no block message')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
t.test('html', async t => {
|
|
132
|
+
const memory = new MemoryCard()
|
|
133
|
+
const bridge = new Bridge({ memory })
|
|
134
|
+
|
|
135
|
+
const msg = await bridge.testBlockedMessage(BLOCKED_HTML_ZH)
|
|
136
|
+
t.equal(msg, BLOCKED_TEXT_ZH, 'should get zh blocked message')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
t.test('zh', async t => {
|
|
140
|
+
const memory = new MemoryCard()
|
|
141
|
+
const bridge = new Bridge({ memory })
|
|
142
|
+
|
|
143
|
+
const msg = await bridge.testBlockedMessage(BLOCKED_XML_ZH)
|
|
144
|
+
t.equal(msg, BLOCKED_TEXT_ZH, 'should get zh blocked message')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('en', async t => {
|
|
148
|
+
const memory = new MemoryCard()
|
|
149
|
+
const bridge = new Bridge({ memory })
|
|
150
|
+
|
|
151
|
+
const msg = await bridge.testBlockedMessage(BLOCKED_XML_EN)
|
|
152
|
+
t.equal(msg, BLOCKED_TEXT_EN, 'should get en blocked message')
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
test('clickSwitchAccount()', async t => {
|
|
157
|
+
const SWITCH_ACCOUNT_HTML = `
|
|
158
|
+
<div class="association show" ng-class="{show: isAssociationLogin && !isBrokenNetwork}">
|
|
159
|
+
<img class="img" mm-src="" alt="" src="//res.wx.qq.com/a/wx_fed/webwx/res/static/img/2KriyDK.png">
|
|
160
|
+
<p ng-show="isWaitingAsConfirm" class="waiting_confirm ng-hide">Confirm login on mobile WeChat</p>
|
|
161
|
+
<a href="javascript:;" ng-show="!isWaitingAsConfirm" ng-click="associationLogin()" class="button button_primary">Log in</a>
|
|
162
|
+
<a href="javascript:;" ng-click="qrcodeLogin()" class="button button_default">Switch Account</a>
|
|
163
|
+
</div>
|
|
164
|
+
`
|
|
165
|
+
const memory = new MemoryCard()
|
|
166
|
+
const bridge = new Bridge({ memory })
|
|
167
|
+
|
|
168
|
+
t.test('switch account needed', async t => {
|
|
169
|
+
const browser = await launch(PUPPETEER_LAUNCH_OPTIONS)
|
|
170
|
+
const page = await browser.newPage()
|
|
171
|
+
|
|
172
|
+
await page.setContent(SWITCH_ACCOUNT_HTML)
|
|
173
|
+
const clicked = await bridge.clickSwitchAccount(page)
|
|
174
|
+
|
|
175
|
+
await page.close()
|
|
176
|
+
await browser.close()
|
|
177
|
+
|
|
178
|
+
t.equal(clicked, true, 'should click the switch account button')
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
t.test('switch account not needed', async t => {
|
|
182
|
+
const browser = await launch(PUPPETEER_LAUNCH_OPTIONS)
|
|
183
|
+
const page = await browser.newPage()
|
|
184
|
+
|
|
185
|
+
await page.setContent('<h1>ok</h1>')
|
|
186
|
+
const clicked = await bridge.clickSwitchAccount(page)
|
|
187
|
+
|
|
188
|
+
await page.close()
|
|
189
|
+
await browser.close()
|
|
190
|
+
|
|
191
|
+
t.equal(clicked, false, 'should no button found')
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('WechatyBro.ding()', async t => {
|
|
196
|
+
const memory = new MemoryCard(Math.random().toString(36).substr(2, 5))
|
|
197
|
+
await memory.load()
|
|
198
|
+
const bridge = new Bridge({
|
|
199
|
+
memory,
|
|
200
|
+
})
|
|
201
|
+
t.ok(bridge, 'should instanciated a bridge')
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
await bridge.start()
|
|
205
|
+
t.pass('should init Bridge')
|
|
206
|
+
|
|
207
|
+
const retDing = await bridge.evaluate(() => {
|
|
208
|
+
// eslint-disable-next-line
|
|
209
|
+
return WechatyBro.ding()
|
|
210
|
+
}) as string
|
|
211
|
+
|
|
212
|
+
t.is(retDing, 'dong', 'should got dong after execute WechatyBro.ding()')
|
|
213
|
+
|
|
214
|
+
const retCode = await bridge.proxyWechaty('loginState')
|
|
215
|
+
t.is(typeof retCode, 'boolean', 'should got a boolean after call proxyWechaty(loginState)')
|
|
216
|
+
|
|
217
|
+
await bridge.stop()
|
|
218
|
+
t.pass('b.quit()')
|
|
219
|
+
} catch (err) {
|
|
220
|
+
t.fail('exception: ' + err.message)
|
|
221
|
+
} finally {
|
|
222
|
+
await memory.destroy()
|
|
223
|
+
}
|
|
224
|
+
})
|