Skip to content

Commit

Permalink
logger.js: fix beautifyStack on Windows. Fixes: #255
Browse files Browse the repository at this point in the history
The RegExp did not take into account Windows Drive Letters.
  • Loading branch information
jamestalmage committed Nov 22, 2015
1 parent 60b2337 commit 832c597
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -18,6 +18,8 @@ function beautifyStack(stack) {
}).join('\n');
}

x._beautifyStack = beautifyStack;

log.type('success', {
color: 'green',
prefix: figures.tick
Expand Down
25 changes: 25 additions & 0 deletions test/logger.js
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 832c597

Please sign in to comment.