提交 e86194d1 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

#40 try to fix unit test in CI!

上级 ce50196d
...@@ -14,7 +14,7 @@ import Wechaty from './src/wechaty' ...@@ -14,7 +14,7 @@ import Wechaty from './src/wechaty'
import log from './src/brolog-env' import log from './src/brolog-env'
const version = require('./package.json').version const VERSION = require('./package.json').version
export default Wechaty export default Wechaty
export { export {
...@@ -30,5 +30,5 @@ export { ...@@ -30,5 +30,5 @@ export {
, UtilLib , UtilLib
, Wechaty , Wechaty
, log // for convenionce use npmlog with environment variable LEVEL , log // for convenionce use npmlog with environment variable LEVEL
, version , VERSION
} }
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
"tslint": "tslint \"{bin,example,src,test}/**/*.ts\" && tsc --noEmit", "tslint": "tslint \"{bin,example,src,test}/**/*.ts\" && tsc --noEmit",
"sloc": "sloc . --details --format cli-table --keys total,source,comment --exclude \"node_modules|doc\" && sloc . --exclude \"node_modules|doc\"", "sloc": "sloc . --details --format cli-table --keys total,source,comment --exclude \"node_modules|doc\" && sloc . --exclude \"node_modules|doc\"",
"pretest": "npm run lint && npm run clean && npm run build", "pretest": "npm run lint && npm run clean && npm run build",
"test": "npm run test:phantomjs && npm run test:chrome", "test": "npm run test:chrome",
"posttest": "npm run clean && npm run sloc", "posttest": "npm run clean && npm run sloc",
"test:phantomjs": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=phantomjs ava --timeout=10m \"dist/test/*.spec.js\"", "test:phantomjs": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=phantomjs ava --timeout=10m \"dist/test/*.spec.js\"",
"test:phantomjs.bak": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=phantomjs ava --timeout=10m \"dist/{src,test}/**/*.spec.js\"", "test:phantomjs.bak": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=phantomjs ava --timeout=10m \"dist/{src,test}/**/*.spec.js\"",
"test:chrome": "cross-env LC_ALL=C WECHATY_LOG=silly WECHATY_HEAD=chrome ava --timeout=10m \"dist/{src,test}/**/*.spec.js\"", "test:chrome": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=chrome ava --ext js --timeout=10m \"dist/{src,test}/**/*.spec.js\"",
"testdev": "cross-env LC_ALL=C WECHATY_LOG=silly ava --ext ts --serial --verbose --fail-fast --timeout=3m", "testdev": "cross-env LC_ALL=C WECHATY_LOG=silly ava --ext ts --serial --verbose --fail-fast --timeout=3m",
"testdist": "ava --ext ts --verbose --fail-fast --timeout=3m", "testdist": "WECHATY_HEAD=phantomjs ava --ext ts --verbose --fail-fast --timeout=3m",
"ava": "cross-env LC_ALL=C WECHATY_LOG=verbose ts-node node_modules/.bin/ava \"{src,test}/**/*.spec.js\"", "ava": "cross-env LC_ALL=C WECHATY_LOG=verbose ts-node node_modules/.bin/ava \"{src,test}/**/*.spec.js\"",
"start": "ts-node bin/client", "start": "ts-node bin/client",
"dev": "ts-node dev.ts", "dev": "ts-node dev.ts",
......
...@@ -60,19 +60,21 @@ export class Browser extends EventEmitter { ...@@ -60,19 +60,21 @@ export class Browser extends EventEmitter {
this.state.target('open') this.state.target('open')
this.state.current('open', false) this.state.current('open', false)
// fastUrl is used to open in browser for we can set cookies. // jumpUrl is used to open in browser for we can set cookies.
// backup: 'https://res.wx.qq.com/zh_CN/htmledition/v2/images/icon/ico_loading28a2f7.gif' // backup: 'https://res.wx.qq.com/zh_CN/htmledition/v2/images/icon/ico_loading28a2f7.gif'
const fastUrl = 'https://wx.qq.com/zh_CN/htmledition/v2/images/webwxgeticon.jpg' const jumpUrl = 'https://wx.qq.com/zh_CN/htmledition/v2/images/webwxgeticon.jpg'
// return co.call(this, function* () {
try { try {
await this.initDriver() await this.initDriver()
// this.live = true // this.live = true
await this.open(fastUrl) await this.open(jumpUrl)
await this.loadCookie() await this.loadCookie()
.catch(e => { // fail safe .catch(e => { // fail safe
log.verbose('PuppetWeb', 'browser.loadSession(%s) exception: %s', this.setting.sessionFile, e && e.message || e) log.verbose('PuppetWeb', 'browser.loadSession(%s) exception: %s'
, this.setting.sessionFile
, e && e.message || e
)
}) })
await this.open() await this.open()
/** /**
...@@ -165,7 +167,7 @@ export class Browser extends EventEmitter { ...@@ -165,7 +167,7 @@ export class Browser extends EventEmitter {
) )
} }
if (typeof newDriver !== 'undefined') { if (newDriver !== undefined) {
if (newDriver) { if (newDriver) {
this._driver = newDriver this._driver = newDriver
return this._driver return this._driver
...@@ -343,7 +345,7 @@ export class Browser extends EventEmitter { ...@@ -343,7 +345,7 @@ export class Browser extends EventEmitter {
/** /**
* *
* if we use AVA to test, then this.clean will cause problems * if we use AVA test runner, then this.clean might cause problems
* because there will be more than one instance of browser with the same nodejs process id * because there will be more than one instance of browser with the same nodejs process id
* *
*/ */
...@@ -386,7 +388,8 @@ export class Browser extends EventEmitter { ...@@ -386,7 +388,8 @@ export class Browser extends EventEmitter {
return retryPromise({ max: max, backoff: backoff }, attempt => { return retryPromise({ max: max, backoff: backoff }, attempt => {
log.silly('PuppetWebBrowser', 'clean() retryPromise: attempt %s time for timeout %s' log.silly('PuppetWebBrowser', 'clean() retryPromise: attempt %s time for timeout %s'
, attempt, timeout) , attempt, timeout
)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.getBrowserPids() this.getBrowserPids()
...@@ -549,7 +552,10 @@ export class Browser extends EventEmitter { ...@@ -549,7 +552,10 @@ export class Browser extends EventEmitter {
// log.verbose('PuppetWebBrowser', 'dead() emit a `dead` event because %s', msg) // log.verbose('PuppetWebBrowser', 'dead() emit a `dead` event because %s', msg)
// this.emit('dead', msg) // this.emit('dead', msg)
// } // }
if (this.state.target() === 'open' && this.state.current() === 'open' && this.state.stable()) { if ( this.state.target() === 'open'
&& this.state.current() === 'open'
&& this.state.stable()
) {
log.verbose('PuppetWebBrowser', 'dead() emit a `dead` event because %s', msg) log.verbose('PuppetWebBrowser', 'dead() emit a `dead` event because %s', msg)
this.emit('dead', msg) this.emit('dead', msg)
} else { } else {
......
// import * as path from 'path'
import { test } from 'ava' import { test } from 'ava'
// import { // import {
......
...@@ -3,6 +3,7 @@ import { test } from 'ava' ...@@ -3,6 +3,7 @@ import { test } from 'ava'
import { import {
Config Config
, Contact , Contact
, FriendRequest
, IoClient , IoClient
, Message , Message
, Puppet , Puppet
...@@ -11,28 +12,30 @@ import { ...@@ -11,28 +12,30 @@ import {
, Wechaty , Wechaty
, log , log
, version , VERSION
} from '../' } from '../'
test('Wechaty Framework', t => { test('Wechaty Framework', t => {
t.truthy(Wechaty , 'should export Wechaty')
t.truthy(Message , 'should export Message')
t.truthy(Contact , 'should export Contact') t.truthy(Contact , 'should export Contact')
t.truthy(Room , 'should export Room') t.truthy(FriendRequest, 'should export FriendREquest')
t.truthy(IoClient , 'should export IoClient') t.truthy(IoClient , 'should export IoClient')
t.truthy(Message , 'should export Message')
t.truthy(log , 'should export log')
t.truthy(Puppet , 'should export Puppet') t.truthy(Puppet , 'should export Puppet')
t.truthy(PuppetWeb , 'should export PuppetWeb') t.truthy(PuppetWeb , 'should export PuppetWeb')
t.truthy(Room , 'should export Room')
t.truthy(Wechaty , 'should export Wechaty')
t.truthy(log , 'should export log')
const bot = Wechaty.instance() const bot = Wechaty.instance()
t.is(bot.version(true), version, 'should export version in package.json') t.is(bot.version(true), require('../package.json').version
, 'should return version as the same in package.json'
)
t.is(VERSION, require('../package.json').version
, 'should export version in package.json'
)
}) })
test('Wechaty Config setting', t => { test('Wechaty Config setting', t => {
t.truthy(Config , 'should export Config') t.truthy(Config , 'should export Config')
t.truthy(Config.DEFAULT_HEAD , 'should has DEFAULT_HEAD') t.truthy(Config.DEFAULT_HEAD , 'should has DEFAULT_HEAD')
t.truthy(Config.DEFAULT_PUPPET , 'should has DEFAULT_PUPPET') t.truthy(Config.DEFAULT_PUPPET , 'should has DEFAULT_PUPPET')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册