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

merge

......@@ -19,6 +19,7 @@ install:
test_script:
- node --version
- npm --version
- npm run lint
- npm run dist
- npm run test:chrome:fast
......
......@@ -7,6 +7,8 @@ dependencies:
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats
override:
- echo 'Ignore CircleCI defaults'
test:
override:
......
......@@ -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) {
......
......@@ -15,12 +15,14 @@
"CMD_CHROMIUM": "/wechaty/bin/xvfb-chromium"
},
"scripts": {
"ava": "ava --verbose --extension ts",
"ts-node": "ts-node",
"dist": "npm run clean && tsc && shx cp package.json dist/ && shx cp src/puppet-web/*.js dist/src/puppet-web/",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"doctor": "check-node-version --node '>= 6.9' && ts-node bin/doctor",
"doctor": "npm run check-node-version && ts-node bin/doctor",
"clean": "shx rm -fr dist/*",
"lint": "check-node-version --node '>= 6.9' && npm run eslint && npm run tslint",
"check-node-version": "check-node-version --node \">= 6.9\"",
"lint": "npm run check-node-version && npm run eslint && npm run tslint",
"nycava": "WECHATY_HEAD=chrome nyc ava --serial --fail-fast --verbose --timeout=3m \"dist/{src,test}/**/*.spec.js\"",
"eslint": "eslint \"{bin,example,src,test}/**/*.js\" --ignore-pattern=\"test/fixture/**\"",
"tslint": "tslint \"{bin,example,src,test}/**/*.ts\" --exclude=\"test/fixture/**\" --exclude=\"dist/\" && tsc --noEmit",
......@@ -34,7 +36,6 @@
"test:chrome:fast": "cross-env LC_ALL=C WECHATY_HEAD=chrome ava --fail-fast --timeout=3m \"dist/{src,test}/**/*.spec.js\"",
"testdev": "cross-env LC_ALL=C WECHATY_LOG=silly ava --ext ts --serial --verbose --fail-fast --timeout=2m",
"testdist": "cross-env WECHATY_LOG=SILLY WECHATY_HEAD=chrome ava --ext ts --verbose --fail-fast --timeout=2m",
"ava": "ava --extension ts",
"io-client": "ts-node bin/io-client",
"dev": "ts-node dev.ts",
"demo": "ts-node example/ding-dong-bot.ts",
......@@ -107,7 +108,7 @@
"is-ci": "1.0.9",
"is-docker": "1.1.0",
"moment": "2.17.0",
"ps-tree": "1.0.1",
"ps-tree": "^1.1.0",
"retry-promise": "1.0.0",
"selenium-webdriver": "3.0.0",
"socket.io": "1.4.8",
......@@ -119,7 +120,7 @@
"@types/fluent-ffmpeg": "0.0.2",
"@types/mime": "0.0.29",
"@types/node": "6.0.54",
"@types/request": "0.0.36",
"@types/request": "0.0.37",
"@types/sinon": "1.16.33",
"@types/ws": "0.0.37",
"apiai": "3.0.3",
......@@ -139,7 +140,7 @@
"shx": "0.2.1",
"sinon": "1.17.5",
"sloc": "0.1.11",
"ts-node": "1.4.1",
"ts-node": "1.7.3",
"tslint": "4.1.1",
"tuling123-client": "0.0.1",
"typescript": "2.1.4",
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册