chore(testrunner): support first-class test debugging (#1606)

This patch teaches testrunner to override both timeout and
parallel execution option if there's attached inspector.
This commit is contained in:
Andrey Lushnikov 2017-12-15 14:25:06 -08:00 committed by GitHub
parent a3a3774926
commit be438c59c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -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",

View File

@ -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);

View File

@ -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;
@ -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);