From 469739f1b494c647fcb06e0db432d435ed9e1805 Mon Sep 17 00:00:00 2001 From: TZ Date: Wed, 13 Sep 2017 16:18:16 +0800 Subject: [PATCH] fix: debug at 6.x --- lib/cmd/debug.js | 5 +++-- package.json | 9 ++++++--- test/lib/cmd/debug.test.js | 24 ++++++++++++++---------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/cmd/debug.js b/lib/cmd/debug.js index 5bd312eb..7a4adf00 100644 --- a/lib/cmd/debug.js +++ b/lib/cmd/debug.js @@ -6,11 +6,11 @@ const InspectorProxy = require('inspector-proxy'); const debug = require('debug')('egg-bin'); const semver = require('semver'); const Command = require('./dev'); +const newDebugger = semver.gte(process.version, '8.0.0'); class DebugCommand extends Command { constructor(rawArgv) { super(rawArgv); - const newDebugger = semver.gte(process.version, '8.0.0'); this.usage = 'Usage: egg-bin debug [dir] [options]'; this.options = { // set default to empty so `--inspect` will always pass to fork @@ -67,7 +67,8 @@ class DebugCommand extends Command { const { debugPort, pid } = msg.data; debug(`recieve new worker#${pid} debugPort: ${debugPort}`); proxy.start({ debugPort }).then(() => { - console.log(chalk.yellow(`DevTools → ${proxy.url}`)); + console.log(chalk.yellow(`Debug Proxy online, now you could attach to ${proxyPort} without worry about reload.`)); + if (newDebugger) console.log(chalk.yellow(`DevTools → ${proxy.url}`)); }); } }); diff --git a/package.json b/package.json index 1da8873c..0673a782 100644 --- a/package.json +++ b/package.json @@ -9,17 +9,20 @@ }, "dependencies": { "autod": "^2.9.0", + "chalk": "^2.1.0", "co-mocha": "^1.2.0", "common-bin": "^2.7.0", "debug": "^3.0.1", "detect-port": "^1.2.1", "egg-utils": "^2.2.0", "globby": "^6.1.0", + "inspector-proxy": "^1.0.0", "intelli-espower-loader": "^1.0.1", - "mocha": "^3.5.0", + "mocha": "^3.5.3", "mz-modules": "^2.0.0", - "nyc": "^11.2.0", + "nyc": "^11.2.1", "power-assert": "^1.4.4", + "semver": "^5.4.1", "test-exclude": "^4.1.1", "ypkgfiles": "^1.4.0" }, @@ -36,7 +39,7 @@ "eslint": "^4.6.1", "eslint-config-egg": "^5.1.1", "jsdom": "^8.0.1", - "mm": "^2.1.0", + "mm": "^2.2.0", "mz": "^2.6.0", "react": "^0.14.7", "react-addons-test-utils": "^0.14.7", diff --git a/test/lib/cmd/debug.test.js b/test/lib/cmd/debug.test.js index 09a184e8..59cb0992 100644 --- a/test/lib/cmd/debug.test.js +++ b/test/lib/cmd/debug.test.js @@ -4,6 +4,7 @@ const path = require('path'); const coffee = require('coffee'); const mm = require('egg-mock'); const net = require('net'); +const semver = require('semver'); describe('test/lib/cmd/debug.test.js', () => { const eggBin = require.resolve('../../../bin/egg-bin.js'); @@ -65,21 +66,24 @@ describe('test/lib/cmd/debug.test.js', () => { describe('real egg', () => { const cwd = path.join(__dirname, '../../fixtures/example'); + const newDebugger = semver.gte(process.version, '8.0.0'); - it('should proxy', () => { - return coffee.fork(eggBin, [ 'debug' ], { cwd }) - // .debug() - .expect('stderr', /Debugger listening/) - .expect('stdout', /DevTools → chrome-devtools:.*:9999/) + it('should proxy', function* () { + const app = coffee.fork(eggBin, [ 'debug' ], { cwd }); + // app.debug(); + if (newDebugger) app.expect('stdout', /DevTools → chrome-devtools:.*:9999/); + yield app.expect('stderr', /Debugger listening/) + .expect('stdout', /Debug Proxy online, now you could attach to 9999/) .expect('code', 0) .end(); }); - it('should proxy with port', () => { - return coffee.fork(eggBin, [ 'debug', '--proxy=6666' ], { cwd }) - // .debug() - .expect('stderr', /Debugger listening/) - .expect('stdout', /DevTools → chrome-devtools:.*:6666/) + it('should proxy with port', function* () { + const app = coffee.fork(eggBin, [ 'debug', '--proxy=6666' ], { cwd }); + // app.debug(); + if (newDebugger) app.expect('stdout', /DevTools → chrome-devtools:.*:6666/); + yield app.expect('stderr', /Debugger listening/) + .expect('stdout', /Debug Proxy online, now you could attach to 6666/) .expect('code', 0) .end(); });