aboutsummaryrefslogtreecommitdiff
path: root/node_modules/ava/lib/beautify-stack.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/ava/lib/beautify-stack.js')
-rw-r--r--node_modules/ava/lib/beautify-stack.js51
1 files changed, 43 insertions, 8 deletions
diff --git a/node_modules/ava/lib/beautify-stack.js b/node_modules/ava/lib/beautify-stack.js
index 189ed0714..4ae8c04be 100644
--- a/node_modules/ava/lib/beautify-stack.js
+++ b/node_modules/ava/lib/beautify-stack.js
@@ -8,6 +8,7 @@ let ignoreStackLines = [];
const avaInternals = /\/ava\/(?:lib\/)?[\w-]+\.js:\d+:\d+\)?$/;
const avaDependencies = /\/node_modules\/(?:bluebird|empower-core|(?:ava\/node_modules\/)?(?:babel-runtime|core-js))\//;
+const stackFrameLine = /^.+( \(.+:\d+:\d+\)|:\d+:\d+)$/;
if (!debug.enabled) {
ignoreStackLines = StackUtils.nodeInternals();
@@ -17,21 +18,55 @@ if (!debug.enabled) {
const stackUtils = new StackUtils({internals: ignoreStackLines});
+function extractFrames(stack) {
+ return stack
+ .split('\n')
+ .map(line => line.trim())
+ .filter(line => stackFrameLine.test(line))
+ .join('\n');
+}
+
+/**
+ * Given a string value of the format generated for the `stack` property of a
+ * V8 error object, return a string that contains only stack frame information
+ * for frames that have relevance to the consumer.
+ *
+ * For example, given the following string value:
+ *
+ * ```
+ * Error
+ * at inner (/home/ava/ex.js:7:12)
+ * at /home/ava/ex.js:12:5
+ * at outer (/home/ava/ex.js:13:4)
+ * at Object.<anonymous> (/home/ava/ex.js:14:3)
+ * at Module._compile (module.js:570:32)
+ * at Object.Module._extensions..js (module.js:579:10)
+ * at Module.load (module.js:487:32)
+ * at tryModuleLoad (module.js:446:12)
+ * at Function.Module._load (module.js:438:3)
+ * at Module.runMain (module.js:604:10)
+ * ```
+ *
+ * ...this function returns the following string value:
+ *
+ * ```
+ * inner (/home/ava/ex.js:7:12)
+ * /home/ava/ex.js:12:5
+ * outer (/home/ava/ex.js:13:4)
+ * Object.<anonymous> (/home/ava/ex.js:14:3)
+ * ```
+ */
module.exports = stack => {
if (!stack) {
return '';
}
+ stack = extractFrames(stack);
// Workaround for https://github.com/tapjs/stack-utils/issues/14
// TODO: fix it in `stack-utils`
stack = cleanStack(stack);
- const title = stack.split('\n')[0];
- const lines = stackUtils
- .clean(stack)
- .split('\n')
- .map(x => ` ${x}`)
- .join('\n');
-
- return `${title}\n${lines}`;
+ return stackUtils.clean(stack)
+ // Remove the trailing newline inserted by the `stack-utils` module
+ .trim();
};