Skip to content
Permalink
Browse files

fix: debug mode detect (#130)

  • Loading branch information
atian25 committed Apr 9, 2019
1 parent f85aafb commit 819d78fb4d8a1c13827f0e64c197e129777fe646
Showing with 44 additions and 8 deletions.
  1. +6 −7 lib/cmd/test.js
  2. +7 −0 test/fixtures/test-files/test/no-timeouts.test.js
  3. +30 −0 test/lib/cmd/test.test.js
  4. +1 −1 test/my-egg-bin.test.js
@@ -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 */
@@ -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
@@ -0,0 +1,7 @@
'use strict';

describe('no-timeouts.test.js', () => {
it('should success', function() {
console.log(`timeout: ${this.timeout()}`);
});
});
@@ -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);
});
});
});
@@ -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);

0 comments on commit 819d78f

Please sign in to comment.
You can’t perform that action at this time.