Skip to content

Commit 33b7918

Browse files
jamestalmagesindresorhus
authored andcommitted
Close #257 PR: logger.js: fix beautifyStack on Windows. Fixes: #255.
1 parent 60b2337 commit 33b7918

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/logger.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var log = new Squeak({separator: ' '});
88
var x = module.exports;
99

1010
function beautifyStack(stack) {
11-
var re = /(?:^(?! {4}at\b).{6})|(?:\((?:[\\\/](?:(?!node_modules[\\\/]ava[\\\/])[^:\\\/])+)+:\d+:\d+\))/;
11+
var re = /(?:^(?! {4}at\b).{6})|(?:\((?:[A-Z]:)?(?:[\\\/](?:(?!node_modules[\\\/]ava[\\\/])[^:\\\/])+)+:\d+:\d+\))/;
1212
var found = false;
1313

1414
return stack.split('\n').filter(function (line) {
@@ -18,6 +18,8 @@ function beautifyStack(stack) {
1818
}).join('\n');
1919
}
2020

21+
x._beautifyStack = beautifyStack;
22+
2123
log.type('success', {
2224
color: 'green',
2325
prefix: figures.tick

test/logger.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
var test = require('tap').test;
3+
var logger = require('../lib/logger');
4+
5+
test('beautify stack - removes uninteresting lines', function (t) {
6+
try {
7+
fooFunc();
8+
} catch (err) {
9+
var stack = logger._beautifyStack(err.stack);
10+
t.match(stack, /fooFunc/);
11+
t.match(stack, /barFunc/);
12+
t.match(err.stack, /Module._compile/);
13+
t.notMatch(stack, /Module\._compile/);
14+
t.end();
15+
}
16+
});
17+
18+
function fooFunc() {
19+
barFunc();
20+
}
21+
22+
function barFunc() {
23+
throw new Error();
24+
}

0 commit comments

Comments
 (0)