diff --git a/lib/cmd/test.js b/lib/cmd/test.js index c00489dc..c66a7be0 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/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 diff --git a/test/fixtures/test-files/test/no-timeouts.test.js b/test/fixtures/test-files/test/no-timeouts.test.js new file mode 100644 index 00000000..1b485902 --- /dev/null +++ b/test/fixtures/test-files/test/no-timeouts.test.js @@ -0,0 +1,7 @@ +'use strict'; + +describe('no-timeouts.test.js', () => { + it('should success', function() { + console.log(`timeout: ${this.timeout()}`); + }); +}); diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index 319346e1..68a9d0d3 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -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); + }); + }); }); diff --git a/test/my-egg-bin.test.js b/test/my-egg-bin.test.js index 6ad1d3cc..e45fdedc 100644 --- a/test/my-egg-bin.test.js +++ b/test/my-egg-bin.test.js @@ -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);