Skip to content

Commit

Permalink
fix: debug at 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and fengmk2 committed Sep 13, 2017
1 parent 678b83d commit 469739f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
5 changes: 3 additions & 2 deletions lib/cmd/debug.js
Expand Up @@ -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
Expand Down Expand Up @@ -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}`));
});
}
});
Expand Down
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -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"
},
Expand All @@ -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",
Expand Down
24 changes: 14 additions & 10 deletions test/lib/cmd/debug.test.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 469739f

Please sign in to comment.