Skip to content

Commit

Permalink
Fix-1735 Parentheses in developers' paths break cucumber's own tests …
Browse files Browse the repository at this point in the history
…WIP (#1824)

* Extract functions into their own files

* Allow injection of exclusion filter to make easier to test

* Make sure we always exclude ourselves

* Add unit test for getDefinitionLineAndUri

* -adds regex pattern for stack traces
-removes dependencies for StackFram library

* - 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 <[email protected]>
Co-authored-by: Matt Wynne <[email protected]>

* update cspotcode/source-map-support

* remove .DS_Store

* updates unit test to support paths on windows

Co-authored-by: Matt Wynne <[email protected]>
Co-authored-by: Blaise Pabon <[email protected]>
Co-authored-by: Dane Parchment <[email protected]>

* Removes assertion for a failing test that's no longer needed

Co-authored-by: Matt Wynne <[email protected]>
Co-authored-by: Blaise Pabon <[email protected]>
Co-authored-by: Dane Parchment <[email protected]>

* Removes exception for the custom stack trace feature

Co-authored-by: Matt Wynne <[email protected]>
Co-authored-by: Blaise Pabon <[email protected]>
Co-authored-by: Dane Parchment <[email protected]>

* Updates changelog

Co-authored-by: Matt Wynne <[email protected]>
Co-authored-by: Blaise Pabon <[email protected]>
Co-authored-by: Dane Parchment <[email protected]>

* fixed linting for previous commit

Co-authored-by: Matt Wynne <[email protected]>
Co-authored-by: Blaise Pabon <[email protected]>
Co-authored-by: Dane Parchment <[email protected]>

Co-authored-by: Matt Wynne <[email protected]>
Co-authored-by: Blaise Pabon <[email protected]>
Co-authored-by: Matt Wynne <[email protected]>
Co-authored-by: Dane Parchment <[email protected]>
  • Loading branch information
5 people authored Nov 12, 2021
1 parent 29a7a90 commit 704bafa
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 144 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions features/custom_stack_trace.feature

This file was deleted.

103 changes: 2 additions & 101 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
30 changes: 15 additions & 15 deletions src/support_code_library_builder/get_definition_line_and_uri.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
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,
isExcluded = isFileNameInCucumber
): 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'),
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 704bafa

Please sign in to comment.