README.md 10.3 KB
Newer Older
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
# Unit Test

Run unit tests

```shell
$ npm test
```

If you want to see full log messages

```shell
$ WECHATY_LOG=silly npm test
```


##

## Example Output

```bash
$ npm test

> wechaty@0.2.3 pretest /home/ubuntu/workspace
> npm run lint


> wechaty@0.2.3 lint /home/ubuntu/workspace
> eslint src test


> wechaty@0.2.3 test /home/ubuntu/workspace
> cross-env TAP_TIMEOUT=600 tap --reporter=tap test/*-spec.js

TAP version 13
    # Subtest: test/contact-spec.js
        # Subtest: Contact smoke testing
        ok 1 - id/UserName right
        ok 2 - UserName set
        ok 3 - NickName set
        ok 4 - toString()
        1..4
    ok 1 - Contact smoke testing # time=213.836ms

    1..1
    # time=326.734ms
ok 1 - test/contact-spec.js # time=631.879ms

    # Subtest: test/message-spec.js
        # Subtest: Message constructor parser test
        ok 1 - id right
        ok 2 - from right
        ok 3 - toString()
        1..3
    ok 1 - Message constructor parser test # time=27.72ms

        # Subtest: Message ready() promise testing
        ok 1 - id/MsgId right
        ok 2 - contact ready for FromUserName
        ok 3 - contact ready for FromNickName
        ok 4 - contact ready for ToUserName
        ok 5 - contact ready for ToNickName
        1..5
    ok 2 - Message ready() promise testing # time=413.647ms

        # Subtest: TBW: Message static method
        ok 1 - Message.find
        ok 2 - Message.findAll with limit 2
        1..2
    ok 3 - TBW: Message static method # time=7.324ms

    1..3
    # time=542.623ms
ok 2 - test/message-spec.js # time=846.417ms

    # Subtest: test/puppet-web-bridge-spec.js
        # Subtest: Bridge retry-promise testing
        ok 1 - retry-promise got NotTheTime when wait not enough
        ok 2 - retryPromise got "Okey" when wait enough
        1..2
    ok 1 - Bridge retry-promise testing # time=83.13ms

        # Subtest: Bridge smoking test
        ok 1 - should instanciated a browser
        ok 2 - should instanciated a bridge with mocked puppet
        ok 3 - should instanciated a browser
        ok 4 - should open success
        ok 5 - should injected wechaty
        ok 6 - should got dong after execute Wechaty.ding()
        ok 7 - should got a boolean after call proxyWechaty(isLogin)
        ok 8 - b.quit()
        ok 9 - browser.quit()
        1..9
    ok 2 - Bridge smoking test # time=1969.856ms

    1..2
    # time=2406.254ms
ok 3 - test/puppet-web-bridge-spec.js # time=2744.939ms

    # Subtest: test/puppet-web-browser-spec.js
        # Subtest: Browser class cookie smoking tests
        ok 1 - should instanciate a browser instance
        ok 2 - should inited
        ok 3 - should opened
        ok 4 - should got 2 after execute script 1+1
        ok 5 - should got plenty of cookies
        ok 6 - should no cookie anymore after deleteAllCookies()
        ok 7 - getCookies() should filter out the cookie named wechaty0
        ok 8 - getCookies() should filter out the cookie named wechaty1
        ok 9 - re-opened url
        ok 10 - getCookie() should get expected cookie named after re-open url
        ok 11 - should be a not dead browser
        ok 12 - should be a live browser
        1..12
    ok 1 - Browser class cookie smoking tests # time=2738.551ms

        # Subtest: Browser session save & load
        ok 1 - new Browser
        ok 2 - inited
        ok 3 - opened
        ok 4 - should no cookie after deleteAllCookies()
        ok 5 - cookie from getCookie() should be same as we just set
        ok 6 - should get cookies from checkSession() after addCookies()
        ok 7 - cookie from checkSession() return should be same as we just set by addCookies()
        ok 8 - should get cookies from saveSession()
        ok 9 - should has the cookie we just set
        ok 10 - cookie from saveSession() return should be same as we just set
        ok 11 - should no cookie from checkSession() after deleteAllCookies()
        ok 12 - should get cookies after loadSession()
        ok 13 - cookie from loadSession() should has expected cookie
        ok 14 - should get cookies from checkSession() after loadSession()
        ok 15 - should has cookie after filtered after loadSession()
        ok 16 - cookie from checkSession() return should has expected cookie after loadSession
        ok 17 - quited
        ok 18 - re-new/init/open Browser
        ok 19 - loadSession for new instance of Browser
        ok 20 - cookie from getCookie() after browser quit, should load the right cookie back
        1..20
    ok 2 - Browser session save & load # time=3703.605ms

    1..2
    # time=6768.282ms
ok 4 - test/puppet-web-browser-spec.js # time=7046.929ms

    # Subtest: test/puppet-web-event-spec.js
        # Subtest: Puppet Web Event smoking test
        ok 1 - should instantiated a PuppetWeb
        ok 2 - should be inited
10:04:25 WARN PuppetWebEvent onBrowserDead() co() set isBrowserBirthing true
        1..2
    ok 1 - Puppet Web Event smoking test # time=4429.701ms

    1..1
    # time=5307.687ms
ok 5 - test/puppet-web-event-spec.js # time=5601.53ms

    # Subtest: test/puppet-web-server-spec.js
        # Subtest: PuppetWebServer basic tests
        ok 1 - PuppetWebServer instance created
        ok 2 - create express
        ok 3 - create https server
        ok 4 - HttpsServer quited
        ok 5 - HttpsServer closed
        ok 6 - create socket io
        1..6
    ok 1 - PuppetWebServer basic tests # time=101.099ms

        # Subtest: PuppetWebServer smoke testing
        ok 1 - new server instance
        ok 2 - server:58788 inited
        ok 3 - ding https   got dong
        1..3
    ok 2 - PuppetWebServer smoke testing # time=75.06ms

    1..2
    # time=614.65ms
ok 6 - test/puppet-web-server-spec.js # time=1014.765ms

    # Subtest: test/puppet-web-spec.js
        # Subtest: PuppetWeb smoke testing
        ok 1 - should instantiated a PuppetWeb
        ok 2 - should be inited
        ok 3 - should be not logined
        ok 4 - should be logined after emit login event
        ok 5 - should be logouted after logout event
        1..5
    ok 1 - PuppetWeb smoke testing # time=2177.999ms

        # Subtest: Puppet Web server/browser communication
        ok 1 - should instantiated a PuppetWeb
        ok 2 - should be inited
        ok 3 - should got EXPECTED_DING_DATA after resolved dingSocket()
        1..3
    ok 2 - Puppet Web server/browser communication # time=4453.266ms

        # Subtest: Puppet Web Self Message Identification
        ok 1 - should instantiated a PuppetWeb
        ok 2 - should identified self for message which from is self
        1..2
    ok 3 - Puppet Web Self Message Identification # time=3.77ms

    1..3
    # time=7388.271ms
ok 7 - test/puppet-web-spec.js # time=7734.744ms

    # Subtest: test/puppet-web-watchdog-spec.js
        # Subtest: Puppet Web watchdog timer
        ok 1 - should instantiate a PuppetWeb
        ok 2 - should get event[error] after watchdog timeout
        ok 3 - set log.level = silent to mute log when watchDog reset wechaty temporary
        ok 4 - should get EXPECTED_DING_DATA from ding after watchdog reset, and restored log level
        1..4
    ok 1 - Puppet Web watchdog timer # time=3261.171ms

    1..1
    # time=3898.268ms
ok 8 - test/puppet-web-watchdog-spec.js # time=4203.963ms

    # Subtest: test/room-spec.js
        # Subtest: Room smoke testing
        ok 1 - id/UserName right
        ok 2 - UserName set
        ok 3 - NickName set
        ok 4 - EncryChatRoomId set
        ok 5 - toString()
        1..5
    ok 1 - Room smoke testing # time=217.241ms

    1..1
    # time=312.937ms
ok 9 - test/room-spec.js # time=589.173ms

    # Subtest: test/web-util-spec.js
        # Subtest: Html smoking test
        ok 1 - should strip html as expected
        ok 2 - should unescape html as expected
        ok 3 - should digest emoji string 0 as expected
        ok 4 - should digest emoji string 1 as expected
        ok 5 - should convert plain text as expected
        1..5
    ok 1 - Html smoking test # time=13.157ms

        # Subtest: Media download smoking test
        ok 1 - should has cookies in req
        ok 2 - should has a cookie named life value 42
        ok 3 - should success download dong from downloadStream()
        1..3
    ok 2 - Media download smoking test # time=207.54ms

    1..2
    # time=314.788ms
ok 10 - test/web-util-spec.js # time=613.88ms

    # Subtest: test/webdriver-spec.js
        # Subtest: WebDriver process create & quit test
        ok 1 - should instanciate a browser
        ok 2 - should be inited successful
        ok 3 - should open successful
        ok 4 - should exist browser process after b.open()
        ok 5 - quited
        ok 6 - no driver process after quit
        1..6
    ok 1 - WebDriver process create & quit test # time=1971.315ms

        # Subtest: WebDriver smoke testing
        ok 1 - Browser instnace
        ok 2 - Bridge instnace
        ok 3 - should has no browser process before get()
        ok 4 - should init driver success
        ok 5 - should got injectio script
        ok 6 - should open wx.qq.com
        ok 7 - should exist browser process after get()
        ok 8 - should return 2 for execute 1+1 in browser
        ok 9 - should return a object contains status of inject operation
        ok 10 - should got code 200 for a success wechaty inject
        1..10
    ok 2 - WebDriver smoke testing # time=1812.719ms

    1..2
    # time=4121.1ms
ok 11 - test/webdriver-spec.js # time=4412.773ms

    # Subtest: test/wechaty-spec.js
        # Subtest: Wechaty Framework
        ok 1 - should export Wechaty
        ok 2 - should export Wechaty.Message
        ok 3 - should export Wechaty.Contact
        ok 4 - should export Wechaty.Room
        ok 5 - should export version in package.json
        1..5
    ok 1 - Wechaty Framework # time=634.931ms

    1..1
    # time=709.635ms
ok 12 - test/wechaty-spec.js # time=967.99ms

1..12
# time=36443.146ms
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
```

# BUG


## TAP & CI

```

mkdir a
cd a

npm init --yes

mkdir b
cd b

cat > bug.js <<__CODE__
316
const test  = require('tape')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
const func = require('../w.js')

test('func param test', function(t) {
        const type = func({ data: 'direct call' })

        t.equal(type, 'default', 'should be default')
        t.end()
})
__CODE__

cat > ../w.js <<__CODE__
module.exports = function func(options) {
        const { type = 'default', data } = options || {}
        console.log('type=' + type + ', data=' + data)
        return type
}
__CODE__


npm install tap --save-dev

node bug.js
tap bug.js
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
340
```