diff --git a/index.js b/index.js index f567133..b67507d 100644 --- a/index.js +++ b/index.js @@ -53,8 +53,9 @@ class StackUtils { stack = stack.split('\n'); } - if (!(/^\s*at /.test(stack[0])) && (/^\s*at /.test(stack[1]))) { - stack = stack.slice(1); + const firstAt = stack.findIndex(line => /^\s*at /.test(line)); + if (firstAt > 0) { + stack = stack.slice(firstAt); } let outdent = false; diff --git a/test/test.js b/test/test.js index 8721f6c..cf20694 100644 --- a/test/test.js +++ b/test/test.js @@ -71,6 +71,13 @@ t.test('clean: truncates cwd', t => { const expectIndented = utils.join(expectedArray.map(a => ' ' + a)); t.equal(stack.clean(WindowsStack1, 4), expectIndented, 'indentation'); + const multilineWindowsStack = `TypeError: foo\nbar\nbaz\n${WindowsStack1.split('\n').slice(1).join('\n')}`; + t.equal(stack.clean(multilineWindowsStack), expected, 'slices off all lines of leading multiline message'); + + const linuxStackUtils = new StackUtils({cwd: '/user/dev/project', internals: []}); + const multilineLinuxStack = `TypeError: foo\nbar\nbaz\n${LinuxStack1.split('\n').slice(1).join('\n')}`; + t.equal(linuxStackUtils.clean(multilineLinuxStack), expected, 'slices off all lines of leading multiline message on linux'); + t.end(); });