-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always remove node internals from stacktraces #4695
Changes from 4 commits
81d3533
1596e89
4472f9b
f097ece
3c294ee
b4bfc53
c68e670
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,19 +158,12 @@ const extractSummary = (stdout: string) => { | |
// unifies their output to make it possible to snapshot them. | ||
const cleanupStackTrace = (output: string) => { | ||
return output | ||
.replace(/\n.*at.*timers\.js.*$/gm, '') | ||
.replace(/\n.*at.*assert\.js.*$/gm, '') | ||
.replace(/\n.*at.*node\.js.*$/gm, '') | ||
.replace(/\n.*at.*next_tick\.js.*$/gm, '') | ||
.replace(/\n.*at (new )?Promise \(<anonymous>\).*$/gm, '') | ||
.replace(/\n.*at <anonymous>.*$/gm, '') | ||
.replace(/\n.*at Generator.next \(<anonymous>\).*$/gm, '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
.replace(/^.*at.*[\s][\(]?(\S*\:\d*\:\d*).*$/gm, ' at $1'); | ||
}; | ||
|
||
module.exports = { | ||
cleanup, | ||
cleanupStackTrace, | ||
copyDir, | ||
createEmptyPackage, | ||
extractSummary, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,16 @@ import path from 'path'; | |
import chalk from 'chalk'; | ||
import micromatch from 'micromatch'; | ||
import slash from 'slash'; | ||
import StackUtils from 'stack-utils'; | ||
|
||
let nodeInternals = []; | ||
|
||
try { | ||
nodeInternals = StackUtils.nodeInternals(); | ||
} catch (e) { | ||
// `StackUtils.nodeInternals()` fails in browsers. We don't need to remove | ||
// node internals in the browser though, so no issue. | ||
} | ||
|
||
type StackTraceConfig = { | ||
rootDir: string, | ||
|
@@ -27,6 +37,9 @@ type StackTraceOptions = { | |
// filter for noisy stack trace lines | ||
const JASMINE_IGNORE = /^\s+at(?:(?:.*?vendor\/|jasmine\-)|\s+jasmine\.buildExpectationResult)/; | ||
const STACK_TRACE_IGNORE = /^\s+at.*?jest(-.*?)?(\/|\\)(build|node_modules|packages)(\/|\\)/; | ||
const ANONYMOUS_TRACE_IGNORE = /^\s+at <anonymous>.*$/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const ANONYMOUS_PROMISE_IGNORE = /^\s+at (new )?Promise \(<anonymous>\).*$/; | ||
const ANONYMOUS_GENERATOR_IGNORE = /^\s+at Generator.next \(<anonymous>\).*$/; | ||
const TITLE_INDENT = ' '; | ||
const MESSAGE_INDENT = ' '; | ||
const STACK_INDENT = ' '; | ||
|
@@ -106,10 +119,26 @@ const removeInternalStackEntries = (lines, options: StackTraceOptions) => { | |
let pathCounter = 0; | ||
|
||
return lines.filter(line => { | ||
const isPath = STACK_PATH_REGEXP.test(line); | ||
if (!isPath) { | ||
if (ANONYMOUS_TRACE_IGNORE.test(line)) { | ||
return false; | ||
} | ||
|
||
if (ANONYMOUS_PROMISE_IGNORE.test(line)) { | ||
return false; | ||
} | ||
|
||
if (ANONYMOUS_GENERATOR_IGNORE.test(line)) { | ||
return false; | ||
} | ||
|
||
if (nodeInternals.some(internal => internal.test(line))) { | ||
return false; | ||
} | ||
|
||
if (!STACK_PATH_REGEXP.test(line)) { | ||
return true; | ||
} | ||
|
||
if (JASMINE_IGNORE.test(line)) { | ||
return false; | ||
} | ||
|
@@ -118,7 +147,15 @@ const removeInternalStackEntries = (lines, options: StackTraceOptions) => { | |
return true; // always keep the first line even if it's from Jest | ||
} | ||
|
||
return !(STACK_TRACE_IGNORE.test(line) || options.noStackTrace); | ||
if (options.noStackTrace) { | ||
return false; | ||
} | ||
|
||
if (STACK_TRACE_IGNORE.test(line)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming this to |
||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this needs to be updated on Node 4? Not sure why it fails now though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next_tick
is not underinternal/
on node 4...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the integration test which fails, it's the new test I added in message-utils