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

issue #21 switch back to phantomjs, and headless & head will all be tested

上级 e82be8c8
{ {
"name": "wechaty", "name": "wechaty",
"version": "0.3.15", "version": "0.3.16",
"description": "Wechat for Bot (Personal Account)", "description": "Wechat for Bot (Personal Account)",
"main": "index.js", "main": "index.js",
"wechaty": { "wechaty": {
"DEFAULT_HEAD": "chrome", "DEFAULT_HEAD": "phantomjs",
"DEFAULT_PUPPET": "web", "DEFAULT_PUPPET": "web",
"DEFAULT_PROFILE": "default-profile-name", "DEFAULT_PROFILE": "default-profile-name",
"DEFAULT_PORT": 18788, "DEFAULT_PORT": 18788,
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
"eslint": "eslint \"{src,test}/**/*.js\"", "eslint": "eslint \"{src,test}/**/*.js\"",
"tslint": "tslint \"{src,test}/**/*.ts\"", "tslint": "tslint \"{src,test}/**/*.ts\"",
"pretest": "npm run lint", "pretest": "npm run lint",
"test": "npm run test:phantomjs && npm run test:chrome",
"test:phantomjs": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=phantomjs ava --timeout=10m \"{src,test}/**/*.spec.js\"",
"test:chrome": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=chrome ava --timeout=10m \"{src,test}/**/*.spec.js\"",
"testdev": "cross-env LC_ALL=C WECHATY_LOG=silly ava --serial --verbose --fail-fast --timeout=3m"
"ava": "cross-env LC_ALL=C WECHATY_LOG=verbose ava \"{src,test}/**/*.spec.js\"",
"start": "node bin/io-bot", "start": "node bin/io-bot",
"demo": "node example/ding-dong-bot.js", "demo": "node example/ding-dong-bot.js",
"test": "cross-env LC_ALL=C WECHATY_LOG=info ava --timeout=10m \"{src,test}/**/*.spec.js\"",
"ava": "cross-env LC_ALL=C WECHATY_LOG=verbose ava \"{src,test}/**/*.spec.js\"",
"testdev": "cross-env LC_ALL=C WECHATY_LOG=silly ava --serial --verbose --fail-fast --timeout=3m"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
......
const Config = { const Config = require('../package.json').wechaty
isDocker: !!process.env.WECHATY_DOCKER
}
Object.assign(Config, require('../package.json').wechaty) Object.assign(Config, {
isDocker: !!process.env.WECHATY_DOCKER
, head: process.env.WECHATY_HEAD || Config.DEFAULT_HEAD
})
module.exports = Config.default = Config.Config = Config module.exports = Config.default = Config.Config = Config
...@@ -38,7 +38,7 @@ const Config = require('../config') ...@@ -38,7 +38,7 @@ const Config = require('../config')
class PuppetWeb extends Puppet { class PuppetWeb extends Puppet {
constructor({ constructor({
head = Config.DEFAULT_HEAD head = Config.head
, profile = null // if not set profile, then do not store session. , profile = null // if not set profile, then do not store session.
} = {}) { } = {}) {
super() super()
......
...@@ -23,6 +23,11 @@ test('Puppet Web Self Message Identification', t => { ...@@ -23,6 +23,11 @@ test('Puppet Web Self Message Identification', t => {
t.truthy(p.self(m), 'should identified self for message which from is self') t.truthy(p.self(m), 'should identified self for message which from is self')
}) })
/**
* the reason why use `test.serial` here is:
* static variable `Contact.puppet` will be changed
* when `PuppteWeb.init()` and `PuppteWeb.quit()`
*/
test.serial('PuppetWeb login/logout events', async t => { test.serial('PuppetWeb login/logout events', async t => {
let pw = new PuppetWeb() let pw = new PuppetWeb()
t.truthy(pw, 'should instantiated a PuppetWeb') t.truthy(pw, 'should instantiated a PuppetWeb')
......
...@@ -3,38 +3,38 @@ import express from 'express' ...@@ -3,38 +3,38 @@ import express from 'express'
import * as http from 'http' import * as http from 'http'
import * as url from 'url' import * as url from 'url'
import Phantomjs from 'phantomjs-prebuilt'
import { test } from 'ava' import { test } from 'ava'
import { UtilLib, log } from '../' import { UtilLib, log } from '../'
test('Phantomjs smoking test', t => { test.todo('Phantomjs replace javascript source file content test', async t => {
const phantomjsExe = require('phantomjs-prebuilt').path
const phantomjsArgs = [ const phantomjsArgs = [
'--load-images=false' '--load-images=false'
, '--ignore-ssl-errors=true' // this help socket.io connect with localhost , '--ignore-ssl-errors=true' // this help socket.io connect with localhost
, '--web-security=false' // https://github.com/ariya/phantomjs/issues/12440#issuecomment-52155299 , '--web-security=false' // https://github.com/ariya/phantomjs/issues/12440#issuecomment-52155299
, '--ssl-protocol=TLSv1' // https://github.com/ariya/phantomjs/issues/11239#issuecomment-42362211 , '--ssl-protocol=TLSv1' // https://github.com/ariya/phantomjs/issues/11239#issuecomment-42362211
, '--webdriver-loglevel=WARN'
// , '--webdriver-loglevel=DEBUG'
// , '--webdriver-logfile=webdriver.debug.log'
// , '--remote-debugger-port=8080'
] ]
phantomjsArgs.push('--remote-debugger-port=8080') // XXX: be careful when in production env.
phantomjsArgs.push('--webdriver-loglevel=DEBUG')
// phantomjsArgs.push('--webdriver-logfile=webdriver.debug.log')
const customPhantom = WebDriver.Capabilities.phantomjs() const customPhantom = WebDriver.Capabilities.phantomjs()
.setAlertBehavior('ignore') // .setAlertBehavior('ignore')
.set('phantomjs.binary.path', phantomjsExe) .set('phantomjs.binary.path', Phantomjs.path)
.set('phantomjs.cli.args', phantomjsArgs) .set('phantomjs.cli.args', phantomjsArgs)
.set('phantomjs.page.settings.userAgent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0')
const driver = new WebDriver.Builder() const driver = new WebDriver.Builder()
.withCapabilities(customPhantom) .withCapabilities(customPhantom)
.build() .build()
// http://stackoverflow.com/questions/24834403/phantomjs-change-webpage-content-before-evaluating // http://stackoverflow.com/questions/24834403/phantomjs-change-webpage-content-before-evaluating
driver.executePhantomJS(` driver.executePhantomJS(`
this.onResourceRequested = function(request, net) { this.onResourceRequested = function(request, net) {
console.log('REQUEST ' + request.url); console.log('REQUEST ' + request.url);
alert('REQUEST ' + request.url);
// blockRe = /wx\.qq\.com\/\?t=v2\/fake/i // blockRe = /wx\.qq\.com\/\?t=v2\/fake/i
// https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp2fd632.js // https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp2fd632.js
var webwxAppRe = /res\.wx\.qq\.com\/zh_CN\/htmledition\/v2\/js\/webwxApp.+\.js$/i var webwxAppRe = /res\.wx\.qq\.com\/zh_CN\/htmledition\/v2\/js\/webwxApp.+\.js$/i
...@@ -70,7 +70,8 @@ this.onResourceRequested = function(request, net) { ...@@ -70,7 +70,8 @@ this.onResourceRequested = function(request, net) {
} }
} }
`) `)
driver.get('https://wx.qq.com') await driver.get('https://wx.qq.com')
// console.log(await driver.getTitle())
// t.end() // t.end()
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册