Skip to content

Commit

Permalink
fix: debug mode detect (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 committed Apr 9, 2019
1 parent f85aafb commit 819d78f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ class TestCommand extends Command {
* @protected
*/
* formatTestArgs({ argv, debugOptions }) {
// whether is debug mode, if pass --inspect then `debugOptions` is valid
// others like WebStorm 2019 will pass NODE_OPTIONS, and egg-bin itself will be debug, so could detect `process.debugPort`.
const isDebugging = debugOptions || process.debugPort;
const testArgv = Object.assign({}, argv);

/* istanbul ignore next */
Expand All @@ -86,10 +83,12 @@ class TestCommand extends Command {
// force exit
testArgv.exit = true;

if (isDebugging) {
// --no-timeouts
testArgv.timeouts = false;
testArgv.timeout = undefined;
// whether is debug mode, if pass --inspect then `debugOptions` is valid
// others like WebStorm 2019 will pass NODE_OPTIONS, and egg-bin itself will be debug, so could detect `process.env.JB_DEBUG_FILE`.

if (debugOptions || process.env.JB_DEBUG_FILE) {
// --no-timeout
testArgv.timeout = false;
}

// collect require
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/test-files/test/no-timeouts.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

describe('no-timeouts.test.js', () => {
it('should success', function() {
console.log(`timeout: ${this.timeout()}`);
});
});
30 changes: 30 additions & 0 deletions test/lib/cmd/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,34 @@ describe('test/lib/cmd/test.test.js', () => {
assert(!args);
});
});

describe('no-timeouts', () => {
it('should timeout', done => {
mm(process.env, 'TEST_TIMEOUT', '5000');
mm(process.env, 'TESTS', 'test/**/no-timeouts.test.js');
coffee.fork(eggBin, [ 'test' ], { cwd })
.expect('stdout', /timeout: 5000/)
.expect('code', 0)
.end(done);
});

it('should no-timeout at debug mode', done => {
mm(process.env, 'TESTS', 'test/**/no-timeouts.test.js');
coffee.fork(eggBin, [ 'test', '--inspect' ], { cwd })
// .debug()
.expect('stdout', /timeout: 0/)
.expect('code', 0)
.end(done);
});

it('should no-timeout at WebStorm debug mode', done => {
mm(process.env, 'TESTS', 'test/**/no-timeouts.test.js');
mm(process.env, 'JB_DEBUG_FILE', __filename);
coffee.fork(eggBin, [ 'test' ], { cwd })
// .debug()
.expect('stdout', /timeout: 0/)
.expect('code', 0)
.end(done);
});
});
});
2 changes: 1 addition & 1 deletion test/my-egg-bin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('test/my-egg-bin.test.js', () => {
];
coffee.fork(eggBin, args, { cwd })
// .debug()
.expect('stdout', /"--no-timeouts",/)
.expect('stdout', /"--no-timeout",/)
.notExpect('stdout', /"--timeout=/)
.expect('code', 0)
.end(done);
Expand Down

0 comments on commit 819d78f

Please sign in to comment.