From d6b002d8f8ea254a36a5c5b2e528edadb77341a2 Mon Sep 17 00:00:00 2001 From: Zhuohuan LI Date: Sun, 7 Aug 2016 12:51:42 +0800 Subject: [PATCH] switch unit test tool from tap to tape, and modify usage of t.end to fix tape --- package.json | 5 ++--- src/puppet-web/browser.js | 4 ++-- src/puppet-web/watchdog.js | 5 +++-- test/README.md | 2 +- test/contact.spec.js | 4 ++-- test/message.spec.js | 4 ++-- test/puppet-web/bridge.spec.js | 2 +- test/puppet-web/browser.spec.js | 4 ++-- test/puppet-web/event.spec.js | 5 +++-- test/puppet-web/index.spec.js | 6 +++--- test/puppet-web/server.spec.js | 2 +- test/puppet-web/watchdog.spec.js | 4 ++-- test/room.spec.js | 4 ++-- test/web-util.spec.js | 2 +- test/webdriver.spec.js | 4 ++-- test/wechaty.spec.js | 2 +- 16 files changed, 30 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index f1900112..8348ba1c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "pretest": "npm run lint", "start": "node bin/io-bot", "demo": "node example/ding-dong-bot.js", - "test": "cross-env TAP_TIMEOUT=600 tap --reporter=tap test/{*,**}/*.spec.js" + "test": "cross-env LC_ALL=C TAP_TIMEOUT=600 tape test/**/*.spec.js" }, "repository": { "type": "git", @@ -65,8 +65,7 @@ "cross-env": "^2.0.0", "eslint": "^3.2.2", "qrcode-terminal": "^0.10.0", - "rimraf": "^2.5.4", - "tap": "^6.3.0", + "tape": "^4.6.0", "tuling123-client": "0.0.1" }, "files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955", diff --git a/src/puppet-web/browser.js b/src/puppet-web/browser.js index e14998cc..0c6a7e66 100644 --- a/src/puppet-web/browser.js +++ b/src/puppet-web/browser.js @@ -187,7 +187,7 @@ class Browser extends EventEmitter { const timeout = max * (backoff * max) / 2 return retryPromise({ max: max, backoff: backoff }, attempt => { - log.silly('PuppetWebBrowser', 'clean() retryPromise: attampt %s time for timeout %s' + log.silly('PuppetWebBrowser', 'clean() retryPromise: attempt %s time for timeout %s' , attempt, timeout) return new Promise((resolve, reject) => { @@ -195,7 +195,7 @@ class Browser extends EventEmitter { .then(pids => { if (pids.length === 0) { log.verbose('PuppetWebBrowser', 'clean() retryPromise() resolved') - resolve('clean() no browser process, confirm clean') + resolve('clean() browser process not found, at attemp#' + attempt) } else { reject(new Error('clean() found browser process, not clean, dirty')) } diff --git a/src/puppet-web/watchdog.js b/src/puppet-web/watchdog.js index 0014af4b..5db608b9 100644 --- a/src/puppet-web/watchdog.js +++ b/src/puppet-web/watchdog.js @@ -32,8 +32,9 @@ function onFeed({ , timeout = 60000 // 60s default. can be override in options but be careful about the number zero(0) } = {}) { - type = type || 'HEARTBEAT' // BUG compatible with issue: node-tap strange behaviour cause CircleCI & Travis-CI keep failing #11 - timeout = timeout || 60000 // BUG compatible with issue: node-tap strange behaviour cause CircleCI & Travis-CI keep failing #11 + // change to tape instead of tap + // type = type || 'HEARTBEAT' // BUG compatible with issue: node-tap strange behaviour cause CircleCI & Travis-CI keep failing #11 + // timeout = timeout || 60000 // BUG compatible with issue: node-tap strange behaviour cause CircleCI & Travis-CI keep failing #11 if (!this) { throw new Error('onFeed() must has `this` of instanceof PuppetWeb') diff --git a/test/README.md b/test/README.md index 34c8b112..83e78e9c 100644 --- a/test/README.md +++ b/test/README.md @@ -313,7 +313,7 @@ mkdir b cd b cat > bug.js <<__CODE__ -const test = require('tap').test +const test = require('tape') const func = require('../w.js') test('func param test', function(t) { diff --git a/test/contact.spec.js b/test/contact.spec.js index 74dde477..d7c600a0 100644 --- a/test/contact.spec.js +++ b/test/contact.spec.js @@ -1,4 +1,4 @@ -const test = require('tap').test +const test = require('tape') const Contact = require('../src/contact') const Puppet = require('../src/puppet') @@ -35,5 +35,5 @@ test('Contact smoke testing', t => { t.equal(typeof s, 'string', 'toString()') }) .catch(e => t.fail('ready() rejected: ' + e)) - .then(t.end) // test end + .then(_ => t.end()) // test end }) diff --git a/test/message.spec.js b/test/message.spec.js index 9b005fd2..0dd328b8 100644 --- a/test/message.spec.js +++ b/test/message.spec.js @@ -1,4 +1,4 @@ -const test = require('tap').test +const test = require('tape') const Message = require('../src/message') const Contact = require('../src/contact') const Puppet = require('../src/puppet') @@ -81,7 +81,7 @@ test('Message ready() promise testing', t => { t.equal(tc.get('name') , expectedToNickName , 'contact ready for ToNickName') }) .catch(e => t.fail('m.ready() rejected: ' + e)) - .then(t.end) // test end + .then(_ => t.end()) // test end }) test('TBW: Message static method', t => { diff --git a/test/puppet-web/bridge.spec.js b/test/puppet-web/bridge.spec.js index deae6049..e8cb82b4 100644 --- a/test/puppet-web/bridge.spec.js +++ b/test/puppet-web/bridge.spec.js @@ -1,5 +1,5 @@ const co = require('co') -const test = require('tap').test +const test = require('tape') const Browser = require('../../src/puppet-web/browser') const Bridge = require('../../src/puppet-web/bridge') diff --git a/test/puppet-web/browser.spec.js b/test/puppet-web/browser.spec.js index 0eae1a8c..880c1190 100644 --- a/test/puppet-web/browser.spec.js +++ b/test/puppet-web/browser.spec.js @@ -1,5 +1,5 @@ const co = require('co') -const test = require('tap').test +const test = require('tape') const log = require('../../src/npmlog-env') @@ -167,7 +167,7 @@ test('Browser session save & load', function(t) { }) .then(r => { // Finally b.quit() - .then(t.end) + .then(_ => t.end()) }) .catch(e => { t.fail(e) }) // Exception }) diff --git a/test/puppet-web/event.spec.js b/test/puppet-web/event.spec.js index 99b9a2a1..7c9953b0 100644 --- a/test/puppet-web/event.spec.js +++ b/test/puppet-web/event.spec.js @@ -1,6 +1,6 @@ const co = require('co') const util = require('util') -const test = require('tap').test +const test = require('tape') const retryPromise = require('retry-promise').default const log = require('../../src/npmlog-env') @@ -24,7 +24,8 @@ test('Puppet Web Event smoking test', function(t) { }) .catch(e => t.fail(e)) // Reject .then(r => { // Finally - pw.quit().then(t.end) + pw.quit() + .then(_ => t.end()) }) .catch(e => t.fail(e)) // Exception }) diff --git a/test/puppet-web/index.spec.js b/test/puppet-web/index.spec.js index e7a69c88..8dab876f 100644 --- a/test/puppet-web/index.spec.js +++ b/test/puppet-web/index.spec.js @@ -1,6 +1,6 @@ const co = require('co') const util = require('util') -const test = require('tap').test +const test = require('tape') const retryPromise = require('retry-promise').default const log = require('../../src/npmlog-env') @@ -61,7 +61,7 @@ false && test('PuppetWeb smoke testing', function(t) { .then(r => { // Finally 1 // log.warn('TestPuppetWeb', 'finally()') pw.quit() - .then(t.end) + .then(_ => t.end()) }) .catch(e => t.fail(e)) // Exception }) @@ -85,7 +85,7 @@ test('Puppet Web server/browser communication', function(t) { }) .then(r => { // Finally pw.quit() - .then(t.end) + .then(_ => t.end()) }) .catch(e => { t.fail(e) }) // Exception diff --git a/test/puppet-web/server.spec.js b/test/puppet-web/server.spec.js index d241998f..3604905d 100644 --- a/test/puppet-web/server.spec.js +++ b/test/puppet-web/server.spec.js @@ -1,5 +1,5 @@ const https = require('https') -const test = require('tap').test +const test = require('tape') const co = require('co') const log = require('../../src/npmlog-env') diff --git a/test/puppet-web/watchdog.spec.js b/test/puppet-web/watchdog.spec.js index d5f88a18..0eadb16d 100644 --- a/test/puppet-web/watchdog.spec.js +++ b/test/puppet-web/watchdog.spec.js @@ -1,6 +1,6 @@ const co = require('co') const util = require('util') -const test = require('tap').test +const test = require('tape') const retryPromise = require('retry-promise').default const log = require('../../src/npmlog-env') @@ -59,7 +59,7 @@ test('Puppet Web watchdog timer', function(t) { }) .then(() => { // Finally pw.quit() - .then(t.end) + .then(_ => t.end()) }) return diff --git a/test/room.spec.js b/test/room.spec.js index 43df321c..4fd66af2 100644 --- a/test/room.spec.js +++ b/test/room.spec.js @@ -1,4 +1,4 @@ -const test = require('tap').test +const test = require('tape') const Message = require('../src/message') const Room = require('../src/room') const Contact = require('../src/contact') @@ -39,7 +39,7 @@ test('Room smoke testing', t => { t.equal(typeof s, 'string', 'toString()') }) .catch(e => t.fail('ready() rejected: ' + e)) - .then(t.end) // test end + .then(_ => t.end()) // test end }) /* const rawData = JSON.parse('{"MsgId":"1120003476579027592","FromUserName":"@@4aa0ae1e1ebc568b613fa43ce93b478df0339f73340d87083822c2016d2e53d9","ToUserName":"@94e4b0db79ccc844d7bb4a2b1efac3ff","MsgType":1,"Content":"@9ad4ba13fac52c55d323521b67f7cc39:
[Strong]","Status":3,"ImgStatus":1,"CreateTime":1462889712,"VoiceLength":0,"PlayLength":0,"FileName":"","FileSize":"","MediaId":"","Url":"","AppMsgType":0,"StatusNotifyCode":0,"StatusNotifyUserName":"","RecommendInfo":{"UserName":"","NickName":"","QQNum":0,"Province":"","City":"","Content":"","Signature":"","Alias":"","Scene":0,"VerifyFlag":0,"AttrStatus":0,"Sex":0,"Ticket":"","OpCode":0},"ForwardFlag":0,"AppInfo":{"AppID":"","Type":0},"HasProductId":0,"Ticket":"","ImgHeight":0,"ImgWidth":0,"SubMsgType":0,"NewMsgId":1120003476579027600,"MMPeerUserName":"@@4aa0ae1e1ebc568b613fa43ce93b478df0339f73340d87083822c2016d2e53d9","MMDigest":"感恩的心 ","MMIsSend":false,"MMIsChatRoom":true,"MMUnread":false,"LocalID":"1120003476579027592","ClientMsgId":"1120003476579027592","MMActualContent":"HTML-CODE","MMActualSender":"@9ad4ba13fac52c55d323521b67f7cc39","MMDigestTime":"22:15","MMDisplayTime":1462889712,"MMTime":"22:15","_h":126,"_index":0,"_offsetTop":0,"$$hashKey":"0QK", "MemberList": [{"Uin":0,"UserName":"@94e4b0db79ccc844d7bb4a2b1efac3ff","NickName":"李卓桓","AttrStatus":37996631,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"北京阿布","KeyWord":"liz"},{"Uin":0,"UserName":"@34887973779b7dd827366a31772cd83df223e6f71d9a79e44fe619aafe2901a4","NickName":"Tiger","AttrStatus":4292711,"PYInitial":"","PYQuanPin":"","RemarkPYInitial":"","RemarkPYQuanPin":"","MemberStatus":0,"DisplayName":"DisplayNameTiger","KeyWord":"","HeadImgUrl":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=@34887973779b7dd827366a31772cd83df223e6f71d9a79e44fe619aafe2901a4&skey=@crypt_f9cec94b_8517b7f9fec85f5a78a804c4f45f5536&chatroomid=@7b3dcd218431d79045cda3493c3179ae"}]}') diff --git a/test/web-util.spec.js b/test/web-util.spec.js index 65737e86..4701cbff 100644 --- a/test/web-util.spec.js +++ b/test/web-util.spec.js @@ -1,6 +1,6 @@ 'use strict' -const test = require('tap').test +const test = require('tape') const log = require('../src/npmlog-env') const webUtil = require('../src/web-util') diff --git a/test/webdriver.spec.js b/test/webdriver.spec.js index 991ec8c8..fe81c25c 100644 --- a/test/webdriver.spec.js +++ b/test/webdriver.spec.js @@ -2,7 +2,7 @@ const path = require('path') const co = require('co') -const test = require('tap').test +const test = require('tape') const log = require('../src/npmlog-env') @@ -38,7 +38,7 @@ test('WebDriver process create & quit test', function(t) { t.equal(pids.length, 0, 'no driver process after quit') }) .catch(e => { t.fail(e) }) - .then(t.end.bind(t)) + .then(_ => t.end()) return }) diff --git a/test/wechaty.spec.js b/test/wechaty.spec.js index 2d6c2a1a..02d3f1d7 100644 --- a/test/wechaty.spec.js +++ b/test/wechaty.spec.js @@ -1,4 +1,4 @@ -const test = require('tap').test +const test = require('tape') const log = require('../src/npmlog-env') test('Wechaty Framework', function(t) { -- GitLab