From d1217f0561fc280f14abc4500241a3429f58a227 Mon Sep 17 00:00:00 2001 From: Emmanuel Ola <54866720+eoola@users.noreply.github.com> Date: Fri, 22 Oct 2021 12:02:57 -0400 Subject: [PATCH] - adds "source-map-support" dependency - progress towards fixing bug for paths with parentheses Cucumber's own features fail when parent directory contains parentheses #1735 - gets accurate line numbers for Error stacks in typescript Co-authored-by: Blaise Pabon Co-authored-by: Matt Wynne --- package-lock.json | 103 +----------------- package.json | 1 + .../get_definition_line_and_uri.ts | 12 +- 3 files changed, 5 insertions(+), 111 deletions(-) diff --git a/package-lock.json b/package-lock.json index 487ae9e68..0d14b7e80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "7.3.0", "license": "MIT", "dependencies": { + "@cspotcode/source-map-support": "^0.6.1", "@cucumber/create-meta": "6.0.1", "@cucumber/cucumber-expressions": "12.1.2", "@cucumber/gherkin": "20.0.1", @@ -34,7 +35,6 @@ "resolve": "^1.19.0", "resolve-pkg": "^2.0.0", "stack-chain": "^2.0.0", - "stacktrace-js": "^2.0.2", "string-argv": "^0.3.1", "tmp": "^0.2.1", "verror": "^1.10.0" @@ -515,7 +515,6 @@ "version": "0.8.0", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", - "dev": true, "engines": { "node": ">= 12" } @@ -524,7 +523,6 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.6.1.tgz", "integrity": "sha512-DX3Z+T5dt1ockmPdobJS/FAsQPW4V4SrWEhD2iYQT2Cb2tQsiMnYxrcUH9By/Z3B+v0S5LMBkQtV/XOBbpLEOg==", - "dev": true, "dependencies": { "@cspotcode/source-map-consumer": "0.8.0" }, @@ -2439,14 +2437,6 @@ "is-arrayish": "^0.2.1" } }, - "node_modules/error-stack-parser": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.0.6.tgz", - "integrity": "sha512-d51brTeqC+BHlwF0BhPtcYgF5nlzf9ZZ0ZIUQNZpc9ZB9qw5IJ2diTrBY9jlCJkTLITYPjmiX6OWCwH+fuyNgQ==", - "dependencies": { - "stackframe": "^1.1.1" - } - }, "node_modules/es-abstract": { "version": "1.18.3", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.3.tgz", @@ -6315,46 +6305,6 @@ "resolved": "https://registry.npmjs.org/stack-chain/-/stack-chain-2.0.0.tgz", "integrity": "sha512-GGrHXePi305aW7XQweYZZwiRwR7Js3MWoK/EHzzB9ROdc75nCnjSJVi21rdAGxFl+yCx2L2qdfl5y7NO4lTyqg==" }, - "node_modules/stack-generator": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.5.tgz", - "integrity": "sha512-/t1ebrbHkrLrDuNMdeAcsvynWgoH/i4o8EGGfX7dEYDoTXOYVAkEpFdtshlvabzc6JlJ8Kf9YdFEoz7JkzGN9Q==", - "dependencies": { - "stackframe": "^1.1.1" - } - }, - "node_modules/stackframe": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.2.0.tgz", - "integrity": "sha512-GrdeshiRmS1YLMYgzF16olf2jJ/IzxXY9lhKOskuVziubpTYcYqyOwYeJKzQkwy7uN0fYSsbsC4RQaXf9LCrYA==" - }, - "node_modules/stacktrace-gps": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/stacktrace-gps/-/stacktrace-gps-3.0.4.tgz", - "integrity": "sha512-qIr8x41yZVSldqdqe6jciXEaSCKw1U8XTXpjDuy0ki/apyTn/r3w9hDAAQOhZdxvsC93H+WwwEu5cq5VemzYeg==", - "dependencies": { - "source-map": "0.5.6", - "stackframe": "^1.1.1" - } - }, - "node_modules/stacktrace-gps/node_modules/source-map": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz", - "integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI=", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/stacktrace-js": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/stacktrace-js/-/stacktrace-js-2.0.2.tgz", - "integrity": "sha512-Je5vBeY4S1r/RnLydLl0TBTi3F2qdfWmYsGvtfZgEI+SCprPppaIhQf5nGcal4gI4cGpCV/duLcAzT1np6sQqg==", - "dependencies": { - "error-stack-parser": "^2.0.6", - "stack-generator": "^2.0.5", - "stacktrace-gps": "^3.0.4" - } - }, "node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", @@ -7527,14 +7477,12 @@ "@cspotcode/source-map-consumer": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", - "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", - "dev": true + "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==" }, "@cspotcode/source-map-support": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.6.1.tgz", "integrity": "sha512-DX3Z+T5dt1ockmPdobJS/FAsQPW4V4SrWEhD2iYQT2Cb2tQsiMnYxrcUH9By/Z3B+v0S5LMBkQtV/XOBbpLEOg==", - "dev": true, "requires": { "@cspotcode/source-map-consumer": "0.8.0" } @@ -9104,14 +9052,6 @@ "is-arrayish": "^0.2.1" } }, - "error-stack-parser": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.0.6.tgz", - "integrity": "sha512-d51brTeqC+BHlwF0BhPtcYgF5nlzf9ZZ0ZIUQNZpc9ZB9qw5IJ2diTrBY9jlCJkTLITYPjmiX6OWCwH+fuyNgQ==", - "requires": { - "stackframe": "^1.1.1" - } - }, "es-abstract": { "version": "1.18.3", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.3.tgz", @@ -12029,45 +11969,6 @@ "resolved": "https://registry.npmjs.org/stack-chain/-/stack-chain-2.0.0.tgz", "integrity": "sha512-GGrHXePi305aW7XQweYZZwiRwR7Js3MWoK/EHzzB9ROdc75nCnjSJVi21rdAGxFl+yCx2L2qdfl5y7NO4lTyqg==" }, - "stack-generator": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.5.tgz", - "integrity": "sha512-/t1ebrbHkrLrDuNMdeAcsvynWgoH/i4o8EGGfX7dEYDoTXOYVAkEpFdtshlvabzc6JlJ8Kf9YdFEoz7JkzGN9Q==", - "requires": { - "stackframe": "^1.1.1" - } - }, - "stackframe": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.2.0.tgz", - "integrity": "sha512-GrdeshiRmS1YLMYgzF16olf2jJ/IzxXY9lhKOskuVziubpTYcYqyOwYeJKzQkwy7uN0fYSsbsC4RQaXf9LCrYA==" - }, - "stacktrace-gps": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/stacktrace-gps/-/stacktrace-gps-3.0.4.tgz", - "integrity": "sha512-qIr8x41yZVSldqdqe6jciXEaSCKw1U8XTXpjDuy0ki/apyTn/r3w9hDAAQOhZdxvsC93H+WwwEu5cq5VemzYeg==", - "requires": { - "source-map": "0.5.6", - "stackframe": "^1.1.1" - }, - "dependencies": { - "source-map": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz", - "integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI=" - } - } - }, - "stacktrace-js": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/stacktrace-js/-/stacktrace-js-2.0.2.tgz", - "integrity": "sha512-Je5vBeY4S1r/RnLydLl0TBTi3F2qdfWmYsGvtfZgEI+SCprPppaIhQf5nGcal4gI4cGpCV/duLcAzT1np6sQqg==", - "requires": { - "error-stack-parser": "^2.0.6", - "stack-generator": "^2.0.5", - "stacktrace-gps": "^3.0.4" - } - }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", diff --git a/package.json b/package.json index 5b636c091..85f4769b0 100644 --- a/package.json +++ b/package.json @@ -168,6 +168,7 @@ "node": ">=12" }, "dependencies": { + "@cspotcode/source-map-support": "^0.6.1", "@cucumber/create-meta": "6.0.1", "@cucumber/cucumber-expressions": "12.1.2", "@cucumber/gherkin": "20.0.1", diff --git a/src/support_code_library_builder/get_definition_line_and_uri.ts b/src/support_code_library_builder/get_definition_line_and_uri.ts index 2be97dddf..3489bdb6d 100644 --- a/src/support_code_library_builder/get_definition_line_and_uri.ts +++ b/src/support_code_library_builder/get_definition_line_and_uri.ts @@ -1,4 +1,5 @@ import path from 'path' +import { wrapCallSite } from '@cspotcode/source-map-support' import stackChain from 'stack-chain' import { isFileNameInCucumber } from '../stack_trace_filter' import { doesHaveValue, valueOrDefault } from '../value_checker' @@ -12,16 +13,7 @@ export function getDefinitionLineAndUri( let line: number let uri: string try { - console.log(new Error().stack.split("\n").slice(1).map( - (line: String) => line.match(/(\/.*):(\d+):\d+/).slice(1,3) - )) - const stackframes = stackChain.callSite() - /*console.log( - stackframes.map((frame: CallSite) => [ - frame.getLineNumber(), - frame.getFileName(), - ]) - )*/ + const stackframes: CallSite[] = stackChain.callSite().map(wrapCallSite) const stackframe = stackframes.find( (frame: CallSite) => frame.getFileName() !== __filename && !isExcluded(frame.getFileName())