Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: debug mode detect #130

Merged
merged 4 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocha 最新版是 --no-timeout 没有 s

}

// 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