From 832c5979d07c6fa537046b5363a9be9f23614780 Mon Sep 17 00:00:00 2001 From: James Talmage Date: Sun, 22 Nov 2015 05:33:40 -0500 Subject: [PATCH] logger.js: fix beautifyStack on Windows. Fixes: #255 The RegExp did not take into account Windows Drive Letters. --- lib/logger.js | 4 +++- test/logger.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/logger.js diff --git a/lib/logger.js b/lib/logger.js index 7f2c11d92..32532dec8 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -8,7 +8,7 @@ var log = new Squeak({separator: ' '}); var x = module.exports; function beautifyStack(stack) { - var re = /(?:^(?! {4}at\b).{6})|(?:\((?:[\\\/](?:(?!node_modules[\\\/]ava[\\\/])[^:\\\/])+)+:\d+:\d+\))/; + var re = /(?:^(?! {4}at\b).{6})|(?:\((?:[A-Z]:)?(?:[\\\/](?:(?!node_modules[\\\/]ava[\\\/])[^:\\\/])+)+:\d+:\d+\))/; var found = false; return stack.split('\n').filter(function (line) { @@ -18,6 +18,8 @@ function beautifyStack(stack) { }).join('\n'); } +x._beautifyStack = beautifyStack; + log.type('success', { color: 'green', prefix: figures.tick diff --git a/test/logger.js b/test/logger.js new file mode 100644 index 000000000..3268d2d6c --- /dev/null +++ b/test/logger.js @@ -0,0 +1,25 @@ +'use strict'; +var test = require('tap').test; +var logger = require('../lib/logger'); + +test('beautify stack - removes uninteresting lines', function (t) { + try { + fooFunc(); + } catch (e) { + var stack = logger._beautifyStack(e.stack); + t.match(stack, /fooFunc/); + t.match(stack, /barFunc/); + t.match(e.stack, /Module._compile/); + t.notMatch(stack, /Module\._compile/); + t.end(); + } +}); + +function fooFunc() { + barFunc(); +} + +function barFunc() { + throw new Error(); +} +