Skip to content

Commit 704bafa

Browse files
eoolamattwynneblaisepDane Parchment
authored
Fix-1735 Parentheses in developers' paths break cucumber's own tests 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]>
1 parent 29a7a90 commit 704bafa

File tree

6 files changed

+37
-144
lines changed

6 files changed

+37
-144
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) on how to contribute to Cucumber.
99

1010
## [Unreleased]
11+
### Fixed
12+
- Allows for parentheses in paths for developers working on cucumber's own code ([[#1735](https://github.com/cucumber/cucumber-js/issues/1735)])
1113

1214
## [8.0.0-rc.1] - 2021-10-19
1315
### Added

features/custom_stack_trace.feature

-27
This file was deleted.

package-lock.json

+2-101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
"node": ">=12"
183183
},
184184
"dependencies": {
185+
"@cspotcode/source-map-support": "^0.7.0",
185186
"@cucumber/create-meta": "6.0.2",
186187
"@cucumber/cucumber-expressions": "^14.0.0",
187188
"@cucumber/gherkin": "^22.0.0",
@@ -206,7 +207,6 @@
206207
"resolve": "^1.19.0",
207208
"resolve-pkg": "^2.0.0",
208209
"stack-chain": "^2.0.0",
209-
"stacktrace-js": "^2.0.2",
210210
"string-argv": "^0.3.1",
211211
"tmp": "^0.2.1",
212212
"util-arity": "^1.1.0",

src/support_code_library_builder/get_definition_line_and_uri.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
import path from 'path'
2-
import StackTrace from 'stacktrace-js'
2+
import { wrapCallSite } from '@cspotcode/source-map-support'
3+
import stackChain from 'stack-chain'
34
import { isFileNameInCucumber } from '../stack_trace_filter'
45
import { doesHaveValue, valueOrDefault } from '../value_checker'
56
import { ILineAndUri } from '../types'
7+
import CallSite = NodeJS.CallSite
68

79
export function getDefinitionLineAndUri(
810
cwd: string,
911
isExcluded = isFileNameInCucumber
1012
): ILineAndUri {
1113
let line: number
1214
let uri: string
13-
try {
14-
const stackframes = StackTrace.getSync()
15-
const stackframe = stackframes.find(
16-
(frame) =>
17-
frame.getFileName() !== __filename && !isExcluded(frame.getFileName())
18-
)
19-
if (stackframe != null) {
20-
line = stackframe.getLineNumber()
21-
uri = stackframe.getFileName()
22-
if (doesHaveValue(uri)) {
23-
uri = path.relative(cwd, uri)
24-
}
15+
16+
const stackframes: CallSite[] = stackChain.callSite().map(wrapCallSite)
17+
const stackframe = stackframes.find(
18+
(frame: CallSite) =>
19+
frame.getFileName() !== __filename && !isExcluded(frame.getFileName())
20+
)
21+
if (stackframe != null) {
22+
line = stackframe.getLineNumber()
23+
uri = stackframe.getFileName()
24+
if (doesHaveValue(uri)) {
25+
uri = path.relative(cwd, uri)
2526
}
26-
} catch (e) {
27-
console.warn('Warning: unable to get definition line and uri', e)
2827
}
28+
2929
return {
3030
line: valueOrDefault(line, 0),
3131
uri: valueOrDefault(uri, 'unknown'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import assert from 'assert'
2+
import { getDefinitionLineAndUri } from './get_definition_line_and_uri'
3+
import path from 'path'
4+
5+
describe(getDefinitionLineAndUri.name, () => {
6+
it('correctly gets the filename of the caller', () => {
7+
const includeAnyFile = (): boolean => false
8+
const { uri, line } = getDefinitionLineAndUri('.', includeAnyFile)
9+
assert.strictEqual(
10+
path.normalize(uri),
11+
path.normalize(
12+
'src/support_code_library_builder/get_definition_line_and_uri_spec.ts'
13+
)
14+
)
15+
assert.strictEqual(line, 8)
16+
})
17+
})

0 commit comments

Comments
 (0)