From 7264d1672e93fdb1046cf7ebe859b607c80e31ca Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 30 Jun 2021 13:42:25 +0200 Subject: [PATCH] refactor(Telemetry): Increase error location coverage --- lib/utils/telemetry/resolve-error-location.js | 4 ++-- .../telemetry/resolve-error-location.test.js | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/utils/telemetry/resolve-error-location.js b/lib/utils/telemetry/resolve-error-location.js index 3b5ebb400df..48255f771a1 100644 --- a/lib/utils/telemetry/resolve-error-location.js +++ b/lib/utils/telemetry/resolve-error-location.js @@ -14,8 +14,8 @@ const resolveErrorLocation = (exceptionTokens) => { const match = line.match(stacktraceLineRegex) || []; const matchedPath = match[1] || match[2]; if (matchedPath) { - // Limited to maximum 5 lines in location - if (stacktracePaths.push(matchedPath) === 5) break; + // Limited to maximum 7 lines in location + if (stacktracePaths.push(matchedPath) === 7) break; } else if (stacktracePaths.length) break; } diff --git a/test/unit/lib/utils/telemetry/resolve-error-location.test.js b/test/unit/lib/utils/telemetry/resolve-error-location.test.js index bca95eb6a45..3467eb44128 100644 --- a/test/unit/lib/utils/telemetry/resolve-error-location.test.js +++ b/test/unit/lib/utils/telemetry/resolve-error-location.test.js @@ -57,7 +57,7 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => { ); }); - it('should return at most 5 lines', () => { + it('should return at most 7 lines', () => { const err = new Error('test'); err.stack = 'Error:\n' + @@ -66,6 +66,10 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => { ' at Test.Runnable.run (/home/xxx/serverless/node_modules/mocha/lib/runnable.js:354:5)\n' + ' at Runner.runTest (/home/xxx/serverless/node_modules/mocha/lib/runner.js:677:10)\n' + ' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:801:12)\n' + + ' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:802:12)\n' + + ' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:803:12)\n' + + ' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:804:12)\n' + + ' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:805:12)\n' + ' at next (/home/xxx/serverless/node_modules/mocha/lib/runner.js:594:14)\n'; const result = resolveErrorLocation(tokenizeException(err)); expect(result).to.equal( @@ -75,6 +79,8 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => { '^:354:5', '/node_modules/mocha/lib/runner.js:677:10', '^:801:12', + '^:802:12', + '^:803:12', ].join('\n') ); }); @@ -101,7 +107,7 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => { ); }); - it('should return at most 5 lines and use `/` path separator', () => { + it('should return at most 7 lines and use `/` path separator', () => { const err = new Error('test'); err.stack = 'Error:\n' + @@ -110,6 +116,10 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => { ' at Test.Runnable.run (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runnable.js:354:5)\r\n' + ' at Runner.runTest (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:677:10)\r\n' + ' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:801:12)\r\n' + + ' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:802:12)\r\n' + + ' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:803:12)\r\n' + + ' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:804:12)\r\n' + + ' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:805:12)\r\n' + ' at next (C:\\home\\xxx\\serverless\\node_modules\\mocha\\lib\\runner.js:594:14)\r\n'; const result = resolveErrorLocation(tokenizeException(err)); expect(result).to.equal( @@ -119,6 +129,8 @@ describe('test/unit/lib/utils/resolve-error-location.test.js', () => { '^:354:5', '/node_modules/mocha/lib/runner.js:677:10', '^:801:12', + '^:802:12', + '^:803:12', ].join('\n') ); });