From 959134f955f04175e50d2aaebd49794c6f406dbc Mon Sep 17 00:00:00 2001 From: "Zhuohuan LI (CARPE DIEM)" Date: Sat, 1 Oct 2016 14:17:31 +0800 Subject: [PATCH] get rid of global config DEFAULT_PUPPET_PORT --- package.json | 1 - src/config.spec.js | 1 - src/puppet-web/puppet-web.js | 4 +++- src/puppet-web/server.js | 9 +++++++-- test/wechaty.spec.js | 1 - 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 0d36ee93..22054268 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "DEFAULT_PUPPET": "web", "DEFAULT_PROFILE": "profile", "DEFAULT_PORT": 8788, - "DEFAULT_PUPPET_PORT": 18788, "DEFAULT_PROTOCOL": "io|0.0.1", "DEFAULT_TOKEN": "WECHATY_IO_TOKEN", "DEFAULT_APIHOST": "api.wechaty.io", diff --git a/src/config.spec.js b/src/config.spec.js index 5010a4b8..f5659486 100644 --- a/src/config.spec.js +++ b/src/config.spec.js @@ -16,7 +16,6 @@ test('Config list vars', t => { t.truthy(Config.DEFAULT_PORT , 'should export DEFAULT_PORT') t.truthy(Config.DEFAULT_PROFILE , 'should export DEFAULT_PROFILE') t.truthy(Config.DEFAULT_HEAD , 'should export DEFAULT_HEAD') - t.truthy(Config.DEFAULT_PUPPET_PORT , 'should export DEFAULT_PUPPET_PORT') t.truthy(Config.DEFAULT_PROTOCOL , 'should export DEFAULT_PROTOCOL') t.truthy(Config.DEFAULT_APIHOST , 'should export DEFAULT_APIHOST') t.truthy(Config.CMD_CHROMIUM , 'should export CMD_CHROMIUM') diff --git a/src/puppet-web/puppet-web.js b/src/puppet-web/puppet-web.js index fcd3d10a..e1b5697c 100644 --- a/src/puppet-web/puppet-web.js +++ b/src/puppet-web/puppet-web.js @@ -36,6 +36,8 @@ const Watchdog = require('./watchdog') const UtilLib = require('../util-lib') const Config = require('../config') +const DEFAULT_PUPPET_PORT = 18788 // // W(87) X(88), ascii char code ;-] + class PuppetWeb extends Puppet { constructor({ head = Config.head @@ -62,7 +64,7 @@ class PuppetWeb extends Puppet { return co.call(this, function* () { - this.port = yield UtilLib.getPort(Config.DEFAULT_PUPPET_PORT) + this.port = yield UtilLib.getPort(DEFAULT_PUPPET_PORT) log.verbose('PuppetWeb', 'init() getPort %d', this.port) yield this.initAttach(this) diff --git a/src/puppet-web/server.js b/src/puppet-web/server.js index a05c8ad7..9e5f4888 100644 --- a/src/puppet-web/server.js +++ b/src/puppet-web/server.js @@ -23,9 +23,14 @@ const EventEmitter = require('events') class Server extends EventEmitter { constructor({ - port = Config.DEFAULT_PUPPET_PORT // W(87) X(88), ascii char code ;-] - } = {}) { + port + }) { super() + + if (!port) { + throw new Error('port not found') + } + this.port = port } diff --git a/test/wechaty.spec.js b/test/wechaty.spec.js index 5e51cf0d..bda9d1f0 100644 --- a/test/wechaty.spec.js +++ b/test/wechaty.spec.js @@ -26,5 +26,4 @@ test('Wechaty Config setting', t => { t.truthy(Config.DEFAULT_HEAD , 'should has DEFAULT_HEAD') t.truthy(Config.DEFAULT_PUPPET , 'should has DEFAULT_PUPPET') t.truthy(Config.DEFAULT_PORT , 'should has DEFAULT_PORT') - t.truthy(Config.DEFAULT_PUPPET_PORT, 'should has DEFAULT_PUPPET_PORT') }) -- GitLab