diff --git a/CHANGELOG.md b/CHANGELOG.md index eae2a747c..24b8b14c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) on how to contribute to Cucumber. ## [Unreleased] +### Fixed +- Allows for parentheses in paths for developers working on cucumber's own code ([[#1735](https://github.com/cucumber/cucumber-js/issues/1735)]) ## [8.0.0-rc.1] - 2021-10-19 ### Added diff --git a/features/custom_stack_trace.feature b/features/custom_stack_trace.feature deleted file mode 100644 index d374f1694..000000000 --- a/features/custom_stack_trace.feature +++ /dev/null @@ -1,27 +0,0 @@ -Feature: Custom stack trace - - @spawn - Scenario: Error.prepareStackTrace override - Given a file named "features/a.feature" with: - """ - Feature: Some feature - Scenario: Some scenario - Given Error.prepareStackTrace has been overriden - """ - Given a file named "features/step_definitions/cucumber_steps.js" with: - """ - const {When} = require('@cucumber/cucumber') - - const _prepareStackTrace = Error.prepareStackTrace; - Error.prepareStackTrace = () => { return 'Custom message' } - - When(/^Error.prepareStackTrace has been overriden$/, function() {}) - - Error.prepareStackTrace = _prepareStackTrace - """ - When I run cucumber-js - Then it passes - And the error output contains the text: - """ - Warning: unable to get definition line and uri [Custom message] - """ diff --git a/package-lock.json b/package-lock.json index 688718686..c46871b06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "8.0.0-rc.1", "license": "MIT", "dependencies": { + "@cspotcode/source-map-support": "^0.7.0", "@cucumber/create-meta": "6.0.2", "@cucumber/cucumber-expressions": "^14.0.0", "@cucumber/gherkin": "^22.0.0", @@ -33,7 +34,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", "util-arity": "^1.1.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.7.0", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", - "dev": true, "dependencies": { "@cspotcode/source-map-consumer": "0.8.0" }, @@ -2409,14 +2407,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.19.1", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.19.1.tgz", @@ -6163,46 +6153,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", @@ -7325,14 +7275,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.7.0", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", - "dev": true, "requires": { "@cspotcode/source-map-consumer": "0.8.0" } @@ -8857,14 +8805,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.19.1", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.19.1.tgz", @@ -11692,45 +11632,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 135514eb1..455fc2984 100644 --- a/package.json +++ b/package.json @@ -182,6 +182,7 @@ "node": ">=12" }, "dependencies": { + "@cspotcode/source-map-support": "^0.7.0", "@cucumber/create-meta": "6.0.2", "@cucumber/cucumber-expressions": "^14.0.0", "@cucumber/gherkin": "^22.0.0", @@ -206,7 +207,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", "util-arity": "^1.1.0", 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 4172e6fe2..583319e6a 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,8 +1,10 @@ import path from 'path' -import StackTrace from 'stacktrace-js' +import { wrapCallSite } from '@cspotcode/source-map-support' +import stackChain from 'stack-chain' import { isFileNameInCucumber } from '../stack_trace_filter' import { doesHaveValue, valueOrDefault } from '../value_checker' import { ILineAndUri } from '../types' +import CallSite = NodeJS.CallSite export function getDefinitionLineAndUri( cwd: string, @@ -10,22 +12,20 @@ export function getDefinitionLineAndUri( ): ILineAndUri { let line: number let uri: string - try { - const stackframes = StackTrace.getSync() - const stackframe = stackframes.find( - (frame) => - frame.getFileName() !== __filename && !isExcluded(frame.getFileName()) - ) - if (stackframe != null) { - line = stackframe.getLineNumber() - uri = stackframe.getFileName() - if (doesHaveValue(uri)) { - uri = path.relative(cwd, uri) - } + + const stackframes: CallSite[] = stackChain.callSite().map(wrapCallSite) + const stackframe = stackframes.find( + (frame: CallSite) => + frame.getFileName() !== __filename && !isExcluded(frame.getFileName()) + ) + if (stackframe != null) { + line = stackframe.getLineNumber() + uri = stackframe.getFileName() + if (doesHaveValue(uri)) { + uri = path.relative(cwd, uri) } - } catch (e) { - console.warn('Warning: unable to get definition line and uri', e) } + return { line: valueOrDefault(line, 0), uri: valueOrDefault(uri, 'unknown'), diff --git a/src/support_code_library_builder/get_definition_line_and_uri_spec.ts b/src/support_code_library_builder/get_definition_line_and_uri_spec.ts new file mode 100644 index 000000000..81956f255 --- /dev/null +++ b/src/support_code_library_builder/get_definition_line_and_uri_spec.ts @@ -0,0 +1,17 @@ +import assert from 'assert' +import { getDefinitionLineAndUri } from './get_definition_line_and_uri' +import path from 'path' + +describe(getDefinitionLineAndUri.name, () => { + it('correctly gets the filename of the caller', () => { + const includeAnyFile = (): boolean => false + const { uri, line } = getDefinitionLineAndUri('.', includeAnyFile) + assert.strictEqual( + path.normalize(uri), + path.normalize( + 'src/support_code_library_builder/get_definition_line_and_uri_spec.ts' + ) + ) + assert.strictEqual(line, 8) + }) +})