Skip to content

Commit

Permalink
chore(testrunner): support first-class test debugging (#1606)
Browse files Browse the repository at this point in the history
This patch teaches testrunner to override both timeout and
parallel execution option if there's attached inspector.
  • Loading branch information
aslushnikov committed Dec 15, 2017
1 parent a3a3774 commit be438c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"unit": "node test/test.js",
"debug-unit": "cross-env DEBUG_TEST=true node --inspect-brk test/test.js",
"debug-unit": "node --inspect-brk test/test.js",
"test-doclint": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js",
"test": "npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-node6-transformer",
"install": "node install.js",
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Expand Up @@ -53,7 +53,7 @@ const defaultBrowserOptions = {
args: ['--no-sandbox']
};

const timeout = process.env.DEBUG_TEST || slowMo ? 0 : 10 * 1000;
const timeout = slowMo ? 0 : 10 * 1000;
let parallel = 1;
if (process.env.PPTR_PARALLEL_TESTS)
parallel = parseInt(process.env.PPTR_PARALLEL_TESTS.trim(), 10);
Expand Down
12 changes: 12 additions & 0 deletions utils/testrunner/TestRunner.js
Expand Up @@ -21,6 +21,8 @@ const Multimap = require('./Multimap');
const TimeoutError = new Error('Timeout');
const TerminatedError = new Error('Terminated');

const MAJOR_NODEJS_VERSION = parseInt(process.version.substring(1).split('.')[0], 10);

class UserCallback {
constructor(callback, timeout) {
this._callback = callback;
Expand Down Expand Up @@ -269,6 +271,16 @@ class TestRunner extends EventEmitter {

this._hasFocusedTestsOrSuites = false;

if (MAJOR_NODEJS_VERSION >= 8) {
const inspector = require('inspector');
if (inspector.url()) {
console.log('TestRunner detected inspector; overriding certain properties to be debugger-friendly');
console.log(' - timeout = 0 (Infinite)');
this._timeout = 2147483647;
this._parallel = 1;
}
}

// bind methods so that they can be used as a DSL.
this.describe = this._addSuite.bind(this, TestMode.Run);
this.fdescribe = this._addSuite.bind(this, TestMode.Focus);
Expand Down

0 comments on commit be438c5

Please sign in to comment.