From 23947e6a566d1ba8021fc50fcae851a8befac985 Mon Sep 17 00:00:00 2001 From: "Zhuohuan LI (CARPE DIEM)" Date: Thu, 1 Sep 2016 05:17:44 +0000 Subject: [PATCH] issue #21 switch back to phantomjs, and headless & head will all be tested --- package.json | 12 +++++++----- src/config.js | 9 +++++---- src/puppet-web/puppet-web.js | 2 +- test/puppet-web/puppet-web.spec.js | 5 +++++ test/webdriver-phantomjs.spec.js | 29 +++++++++++++++-------------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index eb74e17c..1ee8aba8 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "wechaty", - "version": "0.3.15", + "version": "0.3.16", "description": "Wechat for Bot (Personal Account)", "main": "index.js", "wechaty": { - "DEFAULT_HEAD": "chrome", + "DEFAULT_HEAD": "phantomjs", "DEFAULT_PUPPET": "web", "DEFAULT_PROFILE": "default-profile-name", "DEFAULT_PORT": 18788, @@ -16,11 +16,13 @@ "eslint": "eslint \"{src,test}/**/*.js\"", "tslint": "tslint \"{src,test}/**/*.ts\"", "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", "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": { "type": "git", diff --git a/src/config.js b/src/config.js index f547e943..11444ac3 100644 --- a/src/config.js +++ b/src/config.js @@ -1,7 +1,8 @@ -const Config = { - isDocker: !!process.env.WECHATY_DOCKER -} +const Config = require('../package.json').wechaty -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 diff --git a/src/puppet-web/puppet-web.js b/src/puppet-web/puppet-web.js index 3280fd0e..5df452d4 100644 --- a/src/puppet-web/puppet-web.js +++ b/src/puppet-web/puppet-web.js @@ -38,7 +38,7 @@ const Config = require('../config') class PuppetWeb extends Puppet { constructor({ - head = Config.DEFAULT_HEAD + head = Config.head , profile = null // if not set profile, then do not store session. } = {}) { super() diff --git a/test/puppet-web/puppet-web.spec.js b/test/puppet-web/puppet-web.spec.js index a855a9c9..a8957856 100644 --- a/test/puppet-web/puppet-web.spec.js +++ b/test/puppet-web/puppet-web.spec.js @@ -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') }) +/** + * 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 => { let pw = new PuppetWeb() t.truthy(pw, 'should instantiated a PuppetWeb') diff --git a/test/webdriver-phantomjs.spec.js b/test/webdriver-phantomjs.spec.js index 83a7d783..560e4cfa 100644 --- a/test/webdriver-phantomjs.spec.js +++ b/test/webdriver-phantomjs.spec.js @@ -3,38 +3,38 @@ import express from 'express' import * as http from 'http' import * as url from 'url' +import Phantomjs from 'phantomjs-prebuilt' + import { test } from 'ava' import { UtilLib, log } from '../' -test('Phantomjs smoking test', t => { - const phantomjsExe = require('phantomjs-prebuilt').path - +test.todo('Phantomjs replace javascript source file content test', async t => { const phantomjsArgs = [ '--load-images=false' , '--ignore-ssl-errors=true' // this help socket.io connect with localhost , '--web-security=false' // https://github.com/ariya/phantomjs/issues/12440#issuecomment-52155299 , '--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() - .setAlertBehavior('ignore') - .set('phantomjs.binary.path', phantomjsExe) - .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') + // .setAlertBehavior('ignore') + .set('phantomjs.binary.path', Phantomjs.path) + .set('phantomjs.cli.args', phantomjsArgs) const driver = new WebDriver.Builder() - .withCapabilities(customPhantom) - .build() + .withCapabilities(customPhantom) + .build() // http://stackoverflow.com/questions/24834403/phantomjs-change-webpage-content-before-evaluating driver.executePhantomJS(` this.onResourceRequested = function(request, net) { console.log('REQUEST ' + request.url); + alert('REQUEST ' + request.url); // blockRe = /wx\.qq\.com\/\?t=v2\/fake/i // 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 @@ -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() }) -- GitLab