summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShobhit Chittora <schittora@paypal.com>2019-09-14 05:39:46 +0530
committerRuben Bridgewater <ruben@bridgewater.de>2019-09-25 18:21:05 +0200
commit6b8951231c96bb61acf19a9ae29c07a0e82237a6 (patch)
treed4049dafd74522996beb05e2022edd8121d4ca71
parent3878e1ed314f5354e00379d6aaa8696b2a721dab (diff)
downloadnode-new-6b8951231c96bb61acf19a9ae29c07a0e82237a6.tar.gz
bootstrap: add exception handling for profiler bootstrap
Add exception handling for the case when profile is not bootstrapped when coverage is enabled. Fixes: https://github.com/nodejs/node/issues/29542 PR-URL: https://github.com/nodejs/node/pull/29552 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
-rw-r--r--lib/internal/bootstrap/pre_execution.js12
-rw-r--r--test/common/index.js7
-rw-r--r--test/parallel/test-coverage-with-inspector-disabled.js24
3 files changed, 41 insertions, 2 deletions
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index 6722e1c660..6dd69c0c9b 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -120,8 +120,16 @@ function setupCoverageHooks(dir) {
const { resolve } = require('path');
const coverageDirectory = resolve(cwd, dir);
const { sourceMapCacheToObject } = require('internal/source_map');
- internalBinding('profiler').setCoverageDirectory(coverageDirectory);
- internalBinding('profiler').setSourceMapCacheGetter(sourceMapCacheToObject);
+
+ if (process.features.inspector) {
+ internalBinding('profiler').setCoverageDirectory(coverageDirectory);
+ internalBinding('profiler').setSourceMapCacheGetter(sourceMapCacheToObject);
+ } else {
+ process.emitWarning('The inspector is disabled, ' +
+ 'coverage could not be collected',
+ 'Warning');
+ return '';
+ }
return coverageDirectory;
}
diff --git a/test/common/index.js b/test/common/index.js
index 98a2687222..00ebd283a0 100644
--- a/test/common/index.js
+++ b/test/common/index.js
@@ -651,6 +651,12 @@ function skipIfInspectorDisabled() {
}
}
+function skipIfInspectorEnabled() {
+ if (process.features.inspector) {
+ skip('V8 inspector is enabled');
+ }
+}
+
function skipIfReportDisabled() {
if (!process.config.variables.node_report) {
skip('Diagnostic reporting is disabled');
@@ -783,6 +789,7 @@ module.exports = {
skipIf32Bits,
skipIfEslintMissing,
skipIfInspectorDisabled,
+ skipIfInspectorEnabled,
skipIfReportDisabled,
skipIfWorker,
diff --git a/test/parallel/test-coverage-with-inspector-disabled.js b/test/parallel/test-coverage-with-inspector-disabled.js
new file mode 100644
index 0000000000..0b0c2aea43
--- /dev/null
+++ b/test/parallel/test-coverage-with-inspector-disabled.js
@@ -0,0 +1,24 @@
+'use strict';
+
+const common = require('../common');
+common.skipIfInspectorEnabled();
+
+const fixtures = require('../common/fixtures');
+const assert = require('assert');
+const { spawnSync } = require('child_process');
+const env = { ...process.env, NODE_V8_COVERAGE: '/foo/bar' };
+const childPath = fixtures.path('v8-coverage/subprocess');
+const { status, stderr } = spawnSync(
+ process.execPath,
+ [childPath],
+ { env }
+);
+
+const warningMessage = 'The inspector is disabled, ' +
+ 'coverage could not be collected';
+
+assert.strictEqual(status, 0);
+assert.strictEqual(
+ stderr.toString().includes(`Warning: ${warningMessage}`),
+ true
+);