From be438c59c1c5b34c222bd3d7b4cecd94d3b923c0 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 15 Dec 2017 14:25:06 -0800 Subject: [PATCH] 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. --- package.json | 2 +- test/test.js | 2 +- utils/testrunner/TestRunner.js | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index afc00f57f3059..2298d1b1cb790 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/test.js b/test/test.js index 97e2d40bbc3e8..5f215de6a2595 100644 --- a/test/test.js +++ b/test/test.js @@ -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); diff --git a/utils/testrunner/TestRunner.js b/utils/testrunner/TestRunner.js index 3c081745bdd07..6f1308adbb9a6 100644 --- a/utils/testrunner/TestRunner.js +++ b/utils/testrunner/TestRunner.js @@ -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);