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

code clean

上级 856fd1fb
......@@ -24,7 +24,7 @@ import { EventEmitter } from 'events'
import {
Config
, Wechaty
} from '..'
} from '../'
// log.level = 'verbose'
// log.level = 'silly'
......
......@@ -87,7 +87,7 @@ class Talker extends EventEmitter {
text: any
time: any
}
private timer: number | null
private timer: NodeJS.Timer | null
constructor(private thinker) {
super()
......@@ -111,12 +111,12 @@ class Talker extends EventEmitter {
return text
}
public updateTimer(delayTime?) {
public updateTimer(delayTime?: number) {
delayTime = delayTime || this.delayTime()
log.verbose('Talker', 'updateTimer(%s)', delayTime)
if (this.timer) { clearTimeout(this.timer) }
this.timer = setTimeout(this.say.bind(this), delayTime)
this.timer = setTimeout(_ => this.say(), delayTime)
}
public hear(text) {
......
......@@ -137,7 +137,7 @@ export class BrowserCookie {
}
public async load(): Promise<void> {
log.verbose('PuppetWebBrowserCookie', 'load() from %s', this.storeFile)
log.verbose('PuppetWebBrowserCookie', 'load() from %s', this.storeFile || '"undefined"')
const cookies = this.getCookiesFromFile()
......@@ -166,7 +166,7 @@ export class BrowserCookie {
}
public getCookiesFromFile(): CookieType[] | null {
log.verbose('PuppetWebBrowserCookie', 'getCookiesFromFile() from %s', this.storeFile)
log.verbose('PuppetWebBrowserCookie', 'getCookiesFromFile() from %s', this.storeFile || '"undefined"')
try {
if (!this.storeFile) {
......
......@@ -268,6 +268,7 @@ export class Browser extends EventEmitter {
psTree(process.pid, (err, children) => {
if (err) {
log.error('PuppetWebBrowser', 'getBrowserPidList() %s', err.message || err)
reject(err)
return
}
......
......@@ -50,7 +50,7 @@ export class PuppetWeb extends Puppet {
public lastScanEventTime: number
public watchDogLastSaveSession: number
public watchDogTimer: number
public watchDogTimer: NodeJS.Timer | null
public watchDogTimerTime: number
constructor(public setting: PuppetWebSetting = {}) {
......
......@@ -81,7 +81,7 @@ function onFeed(this: PuppetWeb, food: WatchdogFood): void {
memoryCheck.call(this)
}
function clearWatchDogTimer() {
function clearWatchDogTimer(this: PuppetWeb) {
if (!this.watchDogTimer) {
log.verbose('PuppetWebWatchdog', 'clearWatchDogTimer() nothing to clear')
return
......@@ -95,19 +95,18 @@ function clearWatchDogTimer() {
}
}
function setWatchDogTimer(this: PuppetWeb, timeout, feed) {
function setWatchDogTimer(this: PuppetWeb, timeout: number, feed) {
clearWatchDogTimer.call(this)
log.silly('PuppetWebWatchdog', 'setWatchDogTimer(%d, %s)', timeout, feed)
this.watchDogTimer = setTimeout(watchDogReset.bind(this, timeout, feed), timeout)
this.watchDogTimer = setTimeout(_ => watchDogReset.call(this, timeout, feed), timeout)
this.watchDogTimerTime = Date.now() + timeout
// this.watchDogTimer.unref()
// block quit, force to use quit() // this.watchDogTimer.unref() // dont block quit
}
function watchDogReset(timeout, lastFeed) {
async function watchDogReset(timeout, lastFeed): Promise<void> {
log.verbose('PuppetWebWatchdog', 'watchDogReset(%d, %s)', timeout, lastFeed)
const e = new Error('watchDogReset() watchdog reset after '
......@@ -117,7 +116,8 @@ function watchDogReset(timeout, lastFeed) {
)
log.verbose('PuppetWebWatchdog', e.message)
this.emit('error', e)
return Event.onBrowserDead.call(this, e)
Event.onBrowserDead.call(this, e)
return
}
/**
......
......@@ -9,8 +9,8 @@ import * as fs from 'fs'
import { test } from 'ava'
import {
Config
, log
Config,
log,
} from '../../'
import {
......
......@@ -25,23 +25,27 @@ import {
* if 2 tests run parallel in the same process,
* there will have race conditions for the conflict of `getBrowserPids()`
*/
test.serial('WebDriver process create & quit test', async t => {
const browser = new Browser()
t.truthy(browser, 'should instanciate a browser')
await browser.init()
t.pass('should be inited successful')
await browser.open()
t.pass('should open successful')
let pids = await browser.getBrowserPidList()
t.truthy(pids.length > 0, 'should exist browser process after b.open()')
await browser.quit()
t.pass('quited')
pids = await browser.getBrowserPidList()
t.is(pids.length, 0, 'no driver process after quit')
test.only('WebDriver process create & quit test', async t => {
try {
const browser = new Browser()
t.truthy(browser, 'should instanciate a browser')
await browser.init()
t.pass('should be inited successful')
await browser.open()
t.pass('should open successful')
let pids = await browser.getBrowserPidList()
t.truthy(pids.length > 0, 'should exist browser process after b.open()')
await browser.quit()
t.pass('quited')
pids = await browser.getBrowserPidList()
t.is(pids.length, 0, 'no driver process after quit')
} catch (err) {
t.fail(err.message || err)
}
})
test.serial('WebDriver smoke testing', async t => {
......
{
"compilerOptions": {
"target": "es6"
"target": "es2015"
, "module": "commonjs"
, "outDir": "dist"
, "declaration": true
......@@ -15,13 +15,14 @@
, "noImplicitAny": false
, "noUnusedParameters": false
, "noImplicitThis": false
, "traceResolution": false
}
, "exclude": [
"node_modules"
, "dist"
]
, "include": [
"bin/*.ts"
"bin/*.ts"
, "example/**/*.ts"
, "src/**/*.ts"
, "test/**/*.spec.ts"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册