Skip to content

Commit 445a89f

Browse files
addaleaxjasnell
authored andcommitted
lib: fix coverage reporting
Taking the source code of a function and running it in another context does not play well with coverage instrumentation. For now, do the simple thing and just write the source code as a string literal. Fixes: #19912 Refs: #19524 PR-URL: #20035 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 4b73383 commit 445a89f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/internal/util.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,16 @@ function isInsideNodeModules() {
390390
// Use `runInNewContext()` to get something tamper-proof and
391391
// side-effect-free. Since this is currently only used for a deprecated API,
392392
// the perf implications should be okay.
393-
getStructuredStack = runInNewContext('(' + function() {
393+
getStructuredStack = runInNewContext(`(function() {
394394
Error.prepareStackTrace = function(err, trace) {
395395
err.stack = trace;
396396
};
397397
Error.stackTraceLimit = Infinity;
398398
399399
return function structuredStack() {
400-
// eslint-disable-next-line no-restricted-syntax
401400
return new Error().stack;
402401
};
403-
} + ')()', {}, { filename: 'structured-stack' });
402+
})()`, {}, { filename: 'structured-stack' });
404403
}
405404

406405
const stack = getStructuredStack();

0 commit comments

Comments
 (0)