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

code clean

上级 f9273738
......@@ -8,13 +8,13 @@ import * as fs from 'fs'
import Puppet from './puppet'
export type PuppetType = 'web' | 'android' | 'ios'
export type PuppetName = 'web' | 'android' | 'ios'
export type HeadName = 'chrome' | 'phantomjs' | 'firefox'
export interface ConfigSetting {
DEFAULT_HEAD: HeadName
DEFAULT_PUPPET: PuppetType
DEFAULT_PUPPET: PuppetName
DEFAULT_APIHOST: string
DEFAULT_PROFILE: string
DEFAULT_TOKEN: string
......@@ -27,7 +27,7 @@ export interface ConfigSetting {
token: string
debug: boolean
puppet: PuppetType
puppet: PuppetName
head: HeadName
apihost: string
......
......@@ -265,7 +265,7 @@ export class Browser extends EventEmitter {
return await this.driver.executeScript.apply(this.driver, arguments)
} catch (e) {
// this.dead(e)
log.warn('PuppetWebBrowser', 'execute() exception: %s', e.message.substr(0, 99))
log.warn('PuppetWebBrowser', 'execute() exception: %s, %s', e.message.substr(0, 99), e.stack)
throw e
}
}
......
......@@ -98,6 +98,7 @@ export class PuppetWeb extends Puppet {
} catch (e) {
log.error('PuppetWeb', 'init() exception: %s', e.stack)
this.emit('error', e)
await this.quit()
throw e
}
......
......@@ -28,13 +28,10 @@ export const Watchdog = {
onFeed
}
// feed me in time(after 1st feed), or I'll restart system
/**
* feed me in time(after 1st feed), or I'll restart system
*/
function onFeed(this: PuppetWeb, food: WatchdogFood) {
// 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 (!food.type) {
food.type = 'HEARTBEAT'
}
......@@ -49,17 +46,25 @@ function onFeed(this: PuppetWeb, food: WatchdogFood) {
const feed = `${food.type}:[${food.data}]`
log.silly('PuppetWebWatchdog', 'onFeed: %d, %s', food.timeout, feed)
// if (this.currentState() === 'killing') {
if (this.state.current() === 'dead' && this.state.inprocess()) {
log.warn('PuppetWebWatchdog', 'onFeed() is disabled because state.current() is `dead` and inprocess()')
return
}
// if (this.readyState() === 'disconnecting'
// // || this.readyState() === 'disconnected'
// ) {
// log.warn('PuppetWebWatchdog', 'onFeed() is disabled because readyState is `disconnecting`')
/**
* Disable Watchdog on the following conditions:
* 1. current state is dead and inprocess
* 1. target state is dead
*
* in other words, watchdog should only work in this condition:
* 1. target state is live
* 1. and stable is true
*
* this is because we will not want to active watchdog when we are closing a browser, or browser is closed.
*/
// if (this.state.current() === 'dead' && this.state.inprocess()) {
// log.warn('PuppetWebWatchdog', 'onFeed() is disabled because state.current() is `dead` and inprocess()')
// return
// }
if (this.state.target() === 'dead' || this.state.inprocess()) {
log.warn('PuppetWebWatchdog', 'onFeed() is disabled because target state is `dead` or state is inprocess')
return
}
setWatchDogTimer.call(this, food.timeout, feed)
......
......@@ -32,43 +32,10 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public state = new StateMonitor<'live', 'dead'>('Puppet', 'dead')
// private _targetState: string
// private _currentState: string
constructor() {
super()
/*
* @deprecated
* connected / disconnected
* connecting / disconnecting
*/
// this._readyState = 'disconnected'
// this.targetState('dead')
// this.currentState('dead')
// this.state.target('dead')
// this.state.current('dead')
}
// targetState : 'live' | 'dead'
// public targetState(newState?) {
// if (newState) {
// log.verbose('Puppet', 'targetState(%s)', newState)
// this._targetState = newState
// }
// return this._targetState
// }
// // currentState : 'birthing' | 'killing'
// public currentState(newState?) {
// if (newState) {
// log.verbose('Puppet', 'currentState(%s)', newState)
// this._currentState = newState
// }
// return this._currentState
// }
public abstract async init(): Promise<this>
/**
* @deprecated
......
......@@ -16,7 +16,7 @@ import * as path from 'path'
import {
Config
, HeadName
, PuppetType
, PuppetName
, Sayable
} from './config'
......@@ -31,9 +31,9 @@ import UtilLib from './util-lib'
import log from './brolog-env'
export type WechatySetting = {
export type PuppetSetting = {
head?: HeadName
type?: PuppetType
puppet?: PuppetName
profile?: string
}
......@@ -59,7 +59,7 @@ export class Wechaty extends EventEmitter implements Sayable {
public uuid: string
public static instance(setting?: WechatySetting) {
public static instance(setting?: PuppetSetting) {
if (setting && this._instance) {
throw new Error('there has already a instance. no params will be allowed any more')
}
......@@ -69,12 +69,12 @@ export class Wechaty extends EventEmitter implements Sayable {
return this._instance
}
private constructor(private setting: WechatySetting = {}) {
private constructor(private setting: PuppetSetting = {}) {
super()
log.verbose('Wechaty', 'contructor()')
setting.head = setting.head || Config.head
setting.type = setting.type || Config.puppet
setting.puppet = setting.puppet || Config.puppet
setting.profile = setting.profile || Config.profile
// setting.port = setting.port || Config.port
......@@ -90,7 +90,7 @@ export class Wechaty extends EventEmitter implements Sayable {
this.uuid = UtilLib.guid()
}
public toString() { return 'Class Wechaty(' + this.setting.type + ')'}
public toString() { return 'Class Wechaty(' + this.setting.puppet + ')'}
public version(forceNpm = false) {
const dotGitPath = path.join(__dirname, '..', '.git') // `/src/../.git`
......@@ -148,7 +148,7 @@ export class Wechaty extends EventEmitter implements Sayable {
public async init(): Promise<this> {
log.info('Wechaty', 'v%s initializing...' , this.version())
log.verbose('Wechaty', 'puppet: %s' , this.setting.type)
log.verbose('Wechaty', 'puppet: %s' , this.setting.puppet)
log.verbose('Wechaty', 'head: %s' , this.setting.head)
log.verbose('Wechaty', 'profile: %s' , this.setting.profile)
log.verbose('Wechaty', 'uuid: %s' , this.uuid)
......@@ -184,7 +184,7 @@ export class Wechaty extends EventEmitter implements Sayable {
public on(event: 'EVENT_PARAM_ERROR', listener: () => void): this
public on(event: WechatyEventName, listener: Function): this {
log.verbose('Wechaty', 'on(%s, %s)', event, typeof listener)
log.verbose('Wechaty', 'addListener(%s, %s)', event, typeof listener)
// const thisWithSay: Sayable = {
// say: (content: string) => {
......@@ -210,7 +210,7 @@ export class Wechaty extends EventEmitter implements Sayable {
throw new Error('no head')
}
switch (this.setting.type) {
switch (this.setting.puppet) {
case 'web':
puppet = new PuppetWeb({
head: this.setting.head
......@@ -219,7 +219,7 @@ export class Wechaty extends EventEmitter implements Sayable {
break
default:
throw new Error('Puppet unsupport(yet?): ' + this.setting.type)
throw new Error('Puppet unsupport(yet?): ' + this.setting.puppet)
}
const eventList: WechatyEventName[] = [
......
......@@ -12,7 +12,7 @@ import {
} from '../src/puppet-web/'
/**
* WHY USE test.serial
* WHY force to use SERIAL mode
*
* serial here is because we are checking browser pids inside test.
* if 2 tests run parallel in the same process,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册