From eb55fe5fa909f1379e7b43b0b5ffdaa1fbadb17f Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 3 Aug 2022 15:55:34 +0100 Subject: [PATCH 1/2] Handle colons in paths --- packages/node/test/stacktrace.test.ts | 58 ++++++++++++++------------- packages/utils/src/stacktrace.ts | 2 +- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/packages/node/test/stacktrace.test.ts b/packages/node/test/stacktrace.test.ts index e84c436364ed..668689ceb41d 100644 --- a/packages/node/test/stacktrace.test.ts +++ b/packages/node/test/stacktrace.test.ts @@ -120,33 +120,6 @@ describe('Stack parsing', () => { ]); }); - test('parses with missing column numbers', () => { - const err = new Error(); - err.stack = - 'AssertionError: true == false\n' + - ' at Test.fn (/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js:6)\n' + - ' at Test.run (/Users/felix/code/node-fast-or-slow/lib/test.js:45)'; - - const frames = parseStackFrames(stackParser, err); - - expect(frames).toEqual([ - { - filename: '/Users/felix/code/node-fast-or-slow/lib/test.js', - module: 'test', - function: 'Test.run', - lineno: 45, - in_app: true, - }, - { - filename: '/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js', - module: 'test-example', - function: 'Test.fn', - lineno: 6, - in_app: true, - }, - ]); - }); - test('parses with native methods', () => { const err = new Error(); err.stack = @@ -379,4 +352,35 @@ describe('Stack parsing', () => { }, ]); }); + + test('parses with colons in paths', () => { + const err = new Error(); + err.stack = + 'AssertionError: true == false\n' + + ' at Test.run (/Users/felix/code/node-fast-or-slow/lib/20:20:20/test.js:45:10)\n' + + ' at TestCase.run (/Users/felix/code/node-fast-or-slow/lib/test_case.js:61:8)\n'; + + const frames = parseStackFrames(stackParser, err); + + console.log(frames); + + expect(frames).toEqual([ + { + filename: '/Users/felix/code/node-fast-or-slow/lib/test_case.js', + module: 'test_case', + function: 'TestCase.run', + lineno: 61, + colno: 8, + in_app: true, + }, + { + filename: '/Users/felix/code/node-fast-or-slow/lib/20:20:20/test.js', + module: 'test', + function: 'Test.run', + lineno: 45, + colno: 10, + in_app: true, + }, + ]); + }); }); diff --git a/packages/utils/src/stacktrace.ts b/packages/utils/src/stacktrace.ts index d044e19fa7b7..5c183b71a568 100644 --- a/packages/utils/src/stacktrace.ts +++ b/packages/utils/src/stacktrace.ts @@ -100,7 +100,7 @@ type GetModuleFn = (filename: string | undefined) => string | undefined; // eslint-disable-next-line complexity function node(getModule?: GetModuleFn): StackLineParserFn { const FILENAME_MATCH = /^\s*[-]{4,}$/; - const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/; + const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/; // eslint-disable-next-line complexity return (line: string) => { From 143090e9cfe16c2db49b942db601918e720efa6b Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 3 Aug 2022 18:43:05 +0100 Subject: [PATCH 2/2] console.log = bad --- packages/node/test/stacktrace.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/node/test/stacktrace.test.ts b/packages/node/test/stacktrace.test.ts index 668689ceb41d..f5a1b453609f 100644 --- a/packages/node/test/stacktrace.test.ts +++ b/packages/node/test/stacktrace.test.ts @@ -362,8 +362,6 @@ describe('Stack parsing', () => { const frames = parseStackFrames(stackParser, err); - console.log(frames); - expect(frames).toEqual([ { filename: '/Users/felix/code/node-fast-or-slow/lib/test_case.js',